source: EcnlProtoTool/trunk/asp3_dcre/tecsgen/tecslib/core/ctypes.rb@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 7.5 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# TECS Generator
4# Generator for TOPPERS Embedded Component System
5#
6# Copyright (C) 2008-2014 by TOPPERS Project
7#--
8# 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
9# ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
10# 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
11# (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
12# 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
13# スコード中に含まれていること.
14# (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
15# 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
16# 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
17# の無保証規定を掲載すること.
18# (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
19# 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
20# と.
21# (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22# 作権表示,この利用条件および下記の無保証規定を掲載すること.
23# (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
24# 報告すること.
25# (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
26# 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
27# また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
28# 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
29# 免責すること.
30#
31# 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
32# よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
33# に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
34# アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
35# の責任を負わない.
36#
37# $Id$
38#++
39
40# CType は C_parser で定義される型を扱う CIntType, CFloatType などに include するもの
41# CIntType は IntType を継承するなど、C の型では TECS の型を継承する
42module CType
43
44 #=== 構文要素 type_specifier が複数指定されている場合に merge する
45 # merge は const(CIntType) unsigned(CIntTtype), long(CIntType), などと他の型をマージする
46 # const, unsigned, long などは、単体で int (CIntType) 型になりうる
47 #
48 # mikan C の文法を厳密にはチェックしていない long struct 等もできてしまう
49 def merge another
50
51 # p "self: #{self.class} kind_of( IntType ): #{self.kind_of?( IntType )} another: #{another.class}"
52
53 # signed, unsigned が Symbol として来る事は無くなった
54 # if another.instance_of? Symbol then
55 # # ここで Symbol は :SIGNED, :UNSIGNED のいずれか
56 #
57 # # CIntType か?
58 # if self.instance_of? CIntType then
59 # self.set_sign another
60 # return self
61 # else
62 # cdl_error( "C1001 $1: mismatch, suitable for int types" , another )
63 # return self
64 # end
65 # elsif self.instance_of?( CIntType ) && another.instance_of?( CIntType )then
66 if self.instance_of?( CIntType ) && another.instance_of?( CIntType )then
67 if another.get_bit_size != -3 then
68 if @bit_size == -4 && another.get_bit_size == -4 then
69 @bit_size = -5 # long long
70 else
71 # self は int 型、another の bit_size が (int 以外であれば)そちらにする
72 # mikan 上記以外で 両方 -3 でなければ、本来エラー
73 @bit_size = another.get_bit_size
74 end
75 end
76
77 if another.get_sign then
78 # another で sign が指定されていれば、そちらのものを採用する mikan 矛盾のチェック
79 @sign = another.get_sign
80 end
81
82# if another.get_qualifier then
83# # another で qualifier が指定されていれば、そちらのものを採用する mikan 矛盾のチェック
84# @qualifier = another.get_qualifier
85# end
86 if another.is_const? then
87 @b_const = true
88 end
89 if another.is_volatile? then
90 @b_volatile = true
91 end
92
93 return self
94 elsif self.instance_of?( CIntType ) then
95 return another.merge self
96 elsif self.instance_of?( CDefinedType ) then
97 # mikan unsigned などとの merge の不正検出
98 if another.is_const? then
99 @b_const = true
100 end
101 if another.is_volatile? then
102 @b_volatile = true
103 end
104
105# if self.get_type.get_type_str == another.get_type_str &&
106# self.get_type.get_type_str_post == another.get_type_str_post
107# # p "typedef #{another.get_type_str} #{self.get_type_str}#{another.get_type_str_post} ;"
108# else
109# cdl_error( "C1002 $1 not compatible with previous one $2" , self.get_type_str, another.get_type_str )
110# end
111 return self
112 elsif self.instance_of?( CStructType ) then
113 if another.is_const? then
114 @b_const = true
115 end
116 if another.is_volatile? then
117 @b_volatile = true
118 end
119 return self
120 else
121 # mikan long double
122 # TECS には long double を表現する手段がない (double80_t を定義すればよいか?)
123# cdl_warning( "C1003 $1 & $2 incompatible (\'long double\' is not supported.). Treated as $3." , self.class, another.class, self.class )
124 cdl_warning( "W9999 $1 & $2 incompatible (\'long double\' is not supported.). Treated as $3." , self.get_type_str, another.get_type_str, self.get_type_str )
125 return self
126 end
127 end
128
129 #=== qualifier を設定する
130 # 元の Type クラスでは矛盾チェックしない(TECSの本来の文法では重複指定できないため)
131 def set_qualifier( qual )
132
133 if @qualifier then
134 cdl_error( "C1004 $1: qualifier redefined. previous one: $2" , qual, @qualifier )
135 end
136 super( qual )
137 end
138
139end
140
141class CDefinedType < DefinedType
142
143 include CType
144
145 def initialize( type_name )
146 super( type_name )
147 end
148end
149
150class CVoidType < VoidType
151
152 include CType
153
154end
155
156class CBoolType < BoolType
157
158 include CType
159
160end
161
162class CIntType < IntType
163
164 include CType
165
166 def initialize( bit_size )
167 #p super.class mikan super.class が Symbol だ、なぜ?
168 super( bit_size )
169 end
170
171 def set_sign( sign, b_uint = false )
172 super( sign, b_uint )
173 # p "CInt: set_sign: #{get_type_str} #{sign}"
174 end
175end
176
177class CFloatType < FloatType
178
179 include CType
180
181 def initialize( bit_size )
182 super
183 end
184
185end
186
187class CEnumType < EnumType # mikan
188
189 include CType
190
191 def initialize( bit_size )
192 super( bit_size )
193 end
194
195end
196
197class CStructType < StructType
198
199 include CType
200
201
202 def initialize( tag = nil )
203 super( tag )
204 end
205end
206
207class CFuncType < FuncType
208
209 include CType
210
211 def initialize( paramlist = nil )
212 super( paramlist )
213 end
214
215end
216
217class CArrayType < ArrayType
218
219 include CType
220
221 def initialize( subscript = nil )
222 super( subscript )
223 end
224end
225
226class CPtrType < PtrType
227
228 include CType
229
230 def initialize( referto = nil )
231 super( referto )
232 end
233
234end
Note: See TracBrowser for help on using the repository browser.