[270] | 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 ã®åãç¶æ¿ãã
|
---|
| 57 | module 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 |
|
---|
| 155 | end
|
---|
| 156 |
|
---|
| 157 | class CDefinedType < DefinedType
|
---|
| 158 |
|
---|
| 159 | include CType
|
---|
| 160 |
|
---|
| 161 | def initialize( type_name )
|
---|
| 162 | super( type_name )
|
---|
| 163 | end
|
---|
| 164 | end
|
---|
| 165 |
|
---|
| 166 | class CVoidType < VoidType
|
---|
| 167 |
|
---|
| 168 | include CType
|
---|
| 169 |
|
---|
| 170 | end
|
---|
| 171 |
|
---|
| 172 | class CBoolType < BoolType
|
---|
| 173 |
|
---|
| 174 | include CType
|
---|
| 175 |
|
---|
| 176 | end
|
---|
| 177 |
|
---|
| 178 | class 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
|
---|
| 191 | end
|
---|
| 192 |
|
---|
| 193 | class CFloatType < FloatType
|
---|
| 194 |
|
---|
| 195 | include CType
|
---|
| 196 |
|
---|
| 197 | def initialize( bit_size )
|
---|
| 198 | super
|
---|
| 199 | end
|
---|
| 200 |
|
---|
| 201 | end
|
---|
| 202 |
|
---|
| 203 | class CEnumType < EnumType # mikan
|
---|
| 204 |
|
---|
| 205 | include CType
|
---|
| 206 |
|
---|
| 207 | def initialize( bit_size )
|
---|
| 208 | super( bit_size )
|
---|
| 209 | end
|
---|
| 210 |
|
---|
| 211 | end
|
---|
| 212 |
|
---|
| 213 | class CStructType < StructType
|
---|
| 214 |
|
---|
| 215 | include CType
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | def initialize( tag = nil )
|
---|
| 219 | super( tag )
|
---|
| 220 | end
|
---|
| 221 | end
|
---|
| 222 |
|
---|
| 223 | class CFuncType < FuncType
|
---|
| 224 |
|
---|
| 225 | include CType
|
---|
| 226 |
|
---|
| 227 | def initialize( paramlist = nil )
|
---|
| 228 | super( paramlist )
|
---|
| 229 | end
|
---|
| 230 |
|
---|
| 231 | end
|
---|
| 232 |
|
---|
| 233 | class CArrayType < ArrayType
|
---|
| 234 |
|
---|
| 235 | include CType
|
---|
| 236 |
|
---|
| 237 | def initialize( subscript = nil )
|
---|
| 238 | super( subscript )
|
---|
| 239 | end
|
---|
| 240 | end
|
---|
| 241 |
|
---|
| 242 | class CPtrType < PtrType
|
---|
| 243 |
|
---|
| 244 | include CType
|
---|
| 245 |
|
---|
| 246 | def initialize( referto = nil )
|
---|
| 247 | super( referto )
|
---|
| 248 | end
|
---|
| 249 |
|
---|
| 250 | end
|
---|