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

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

mruby版ECNLプロトタイピング・ツールを追加

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