source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/tecsgen/tecslib/core/ctypes.rb@ 359

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

SDカードの挿抜を検知するよう更新

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