source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/core/ctypes.rb@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
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# 上記著作権者
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$
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 elsif self.instance_of?( CFloatType ) then
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 self.to_long
141 return self
142 else
143 raise "merge: unknown type"
144 end
145 end
146
147 #=== qualifier を設定する
148 # å…
149ƒã® Type クラスでは矛盾チェックしない(TECSの本来の文法では重複指定できないため)
150 def set_qualifier( qual )
151
152 if @qualifier then
153 cdl_error( "C1004 $1: qualifier redefined. previous one: $2" , qual, @qualifier )
154 end
155 super( qual )
156 end
157
158end
159
160class CDefinedType < DefinedType
161
162 include CType
163
164 def initialize( type_name )
165 super( type_name )
166 end
167end
168
169class CVoidType < VoidType
170
171 include CType
172
173end
174
175class CBoolType < BoolType
176
177 include CType
178
179end
180
181class CIntType < IntType
182
183 include CType
184
185 def initialize( bit_size )
186 #p super.class mikan super.class が Symbol だ、なぜ?
187 super( bit_size )
188 end
189
190 def set_sign( sign, b_uint = false )
191 super( sign, b_uint )
192 # p "CInt: set_sign: #{get_type_str} #{sign}"
193 end
194end
195
196class CFloatType < FloatType
197
198 include CType
199
200 def initialize( bit_size )
201 super
202 end
203
204 def to_long
205 if @bit_size != -64 then
206 cdl_warning( "W9999 long specified for $1" , get_type_str )
207 else
208 @bit_size = -128 # @bit_size = -128 : long double
209 end
210 end
211end
212
213class CEnumType < EnumType # mikan
214
215 include CType
216
217 def initialize( bit_size )
218 super( bit_size )
219 end
220
221end
222
223class CStructType < StructType
224
225 include CType
226
227
228 def initialize( tag = nil )
229 super( tag )
230 end
231end
232
233class CFuncType < FuncType
234
235 include CType
236
237 def initialize( paramlist = nil )
238 super( paramlist )
239 end
240
241end
242
243class CArrayType < ArrayType
244
245 include CType
246
247 def initialize( subscript = nil )
248 super( subscript )
249 end
250end
251
252class CPtrType < PtrType
253
254 include CType
255
256 def initialize( referto = nil )
257 super( referto )
258 end
259
260end
Note: See TracBrowser for help on using the repository browser.