source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tecsgen/tecslib/core/ctypes.rb@ 374

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

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 7.8 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# TECS Generator
4# Generator for TOPPERS Embedded Component System
5#
6# Copyright (C) 2008-2017 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 elsif self.instance_of?( CFloatType ) then
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 self.to_long
126 return self
127 else
128 raise "merge: unknown type"
129 end
130 end
131
132 #=== qualifier を設定する
133 # 元の Type クラスでは矛盾チェックしない(TECSの本来の文法では重複指定できないため)
134 def set_qualifier( qual )
135
136 if @qualifier then
137 cdl_error( "C1004 $1: qualifier redefined. previous one: $2" , qual, @qualifier )
138 end
139 super( qual )
140 end
141
142end
143
144class CDefinedType < DefinedType
145
146 include CType
147
148 def initialize( type_name )
149 super( type_name )
150 end
151end
152
153class CVoidType < VoidType
154
155 include CType
156
157end
158
159class CBoolType < BoolType
160
161 include CType
162
163end
164
165class CIntType < IntType
166
167 include CType
168
169 def initialize( bit_size )
170 #p super.class mikan super.class が Symbol だ、なぜ?
171 super( bit_size )
172 end
173
174 def set_sign( sign, b_uint = false )
175 super( sign, b_uint )
176 # p "CInt: set_sign: #{get_type_str} #{sign}"
177 end
178end
179
180class CFloatType < FloatType
181
182 include CType
183
184 def initialize( bit_size )
185 super
186 end
187
188 def to_long
189 if @bit_size != -64 then
190 cdl_warning( "W9999 long specified for $1" , get_type_str )
191 else
192 @bit_size = -128 # @bit_size = -128 : long double
193 end
194 end
195end
196
197class CEnumType < EnumType # mikan
198
199 include CType
200
201 def initialize( bit_size )
202 super( bit_size )
203 end
204
205end
206
207class CStructType < StructType
208
209 include CType
210
211
212 def initialize( tag = nil )
213 super( tag )
214 end
215end
216
217class CFuncType < FuncType
218
219 include CType
220
221 def initialize( paramlist = nil )
222 super( paramlist )
223 end
224
225end
226
227class CArrayType < ArrayType
228
229 include CType
230
231 def initialize( subscript = nil )
232 super( subscript )
233 end
234end
235
236class CPtrType < PtrType
237
238 include CType
239
240 def initialize( referto = nil )
241 super( referto )
242 end
243
244end
Note: See TracBrowser for help on using the repository browser.