source: src/Parser/ExpressionNode.cc@ 874ffa4

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 874ffa4 was f56c32e, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

update constant parsing and add 'n' suffix for integer constants

  • Property mode set to 100644
File size: 22.0 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// ExpressionNode.cc --
8//
9// Author : Peter A. Buhr
10// Created On : Sat May 16 13:17:07 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Feb 28 21:36:38 2019
13// Update Count : 933
14//
15
16#include <cassert> // for assert
17#include <stdio.h> // for sscanf, size_t
18#include <climits> // for LLONG_MAX, LONG_MAX, INT_MAX, UINT...
19#include <list> // for list
20#include <sstream> // for basic_istream::operator>>, basic_i...
21#include <string> // for string, operator+, operator==
22
23#include "Common/SemanticError.h" // for SemanticError
24#include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo...
25#include "ParseNode.h" // for ExpressionNode, maybeMoveBuildType
26#include "SynTree/Constant.h" // for Constant
27#include "SynTree/Declaration.h" // for EnumDecl, StructDecl, UnionDecl
28#include "SynTree/Expression.h" // for Expression, ConstantExpr, NameExpr
29#include "SynTree/Statement.h" // for CompoundStmt, Statement
30#include "SynTree/Type.h" // for BasicType, Type, Type::Qualifiers
31#include "parserutility.h" // for notZeroExpr
32
33class Initializer;
34
35using namespace std;
36
37//##############################################################################
38
39// Difficult to separate extra parts of constants during lexing because actions are not allow in the middle of patterns:
40//
41// prefix action constant action suffix
42//
43// Alternatively, breaking a pattern using BEGIN does not work if the following pattern can be empty:
44//
45// constant BEGIN CONT ...
46// <CONT>(...)? BEGIN 0 ... // possible empty suffix
47//
48// because the CONT rule is NOT triggered if the pattern is empty. Hence, constants are reparsed here to determine their
49// type.
50
51extern const Type::Qualifiers noQualifiers; // no qualifiers on constants
52
53// static inline bool checkH( char c ) { return c == 'h' || c == 'H'; }
54// static inline bool checkZ( char c ) { return c == 'z' || c == 'Z'; }
55// static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
56static inline bool checkF( char c ) { return c == 'f' || c == 'F'; }
57static inline bool checkD( char c ) { return c == 'd' || c == 'D'; }
58static inline bool checkF80( char c ) { return c == 'w' || c == 'W'; }
59static inline bool checkF128( char c ) { return c == 'q' || c == 'Q'; }
60static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }
61static inline bool checkI( char c ) { return c == 'i' || c == 'I'; }
62static inline bool checkB( char c ) { return c == 'b' || c == 'B'; }
63static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
64static inline bool checkN( char c ) { return c == 'n' || c == 'N'; }
65
66void lnthSuffix( string & str, int & type, int & ltype ) {
67 string::size_type posn = str.find_last_of( "lL" );
68 if ( posn != string::npos ) {
69 type = 3; // default
70 posn += 1; // advance to size
71 if ( str[posn] == '3' ) { // 32
72 type = ltype = 2; str.erase( posn, 2 );
73 } else if ( str[posn] == '6' ) { // 64
74 type = ltype = 3; str.erase( posn, 2 );
75 } else if ( str[posn] == '8' ) { // 8
76 type = ltype = 1; str.erase( posn, 1 );
77 } else if ( str[posn] == '1' ) {
78 if ( str[posn + 1] == '6' ) { // 16
79 type = ltype = 0; str.erase( posn, 2 );
80 } else { // 128
81 type = ltype = 5; str.erase( posn, 3 );
82 } // if
83 } // if
84 } // if
85} // lnthSuffix
86
87Expression * build_constantInteger( string & str ) {
88 static const BasicType::Kind kind[2][6] = {
89 // short (h) must be before char (hh) because shorter type has the longer suffix
90 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt128, },
91 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt128, },
92 };
93
94 static const char * lnthsInt[2][5] = {
95 { "int16_t", "int8_t", "int32_t", "int64_t", "size_t", },
96 { "uint16_t", "uint8_t", "uint32_t", "uint64_t", "size_t", },
97 }; // lnthsInt
98
99 bool dec = true, Unsigned = false; // decimal, unsigned constant
100 int type = -1; // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => int128
101 int ltype = -1; // literal length
102
103 unsigned long long int v; // converted integral value
104 size_t last = str.length() - 1; // last subscript of constant
105 Expression * ret;
106 string fred( str );
107
108 // special constants
109 if ( str == "0" ) {
110 ret = new ConstantExpr( Constant( (Type *)new ZeroType( noQualifiers ), str, (unsigned long long int)0 ) );
111 goto CLEANUP;
112 } // if
113 if ( str == "1" ) {
114 ret = new ConstantExpr( Constant( (Type *)new OneType( noQualifiers ), str, (unsigned long long int)1 ) );
115 goto CLEANUP;
116 } // if
117
118 // Cannot be just "0"/"1"; sscanf stops at the suffix, if any; value goes over the wall so always generate
119
120 if ( str[0] == '0' ) { // radix character ?
121 dec = false;
122 if ( checkX( str[1] ) ) { // hex constant ?
123 sscanf( (char *)str.c_str(), "%llx", &v );
124 //printf( "%llx %llu\n", v, v );
125 } else if ( checkB( str[1] ) ) { // binary constant ?
126 v = 0; // compute value
127 for ( unsigned int i = 2;; ) {
128 if ( str[i] == '1' ) v |= 1;
129 i += 1;
130 if ( i == last - 1 || (str[i] != '0' && str[i] != '1') ) break;
131 v <<= 1;
132 } // for
133 //printf( "%#llx %llu\n", v, v );
134 } else { // octal constant
135 sscanf( (char *)str.c_str(), "%llo", &v );
136 //printf( "%#llo %llu\n", v, v );
137 } // if
138 } else { // decimal constant ?
139 sscanf( (char *)str.c_str(), "%llu", &v );
140 //printf( "%llu\n", v );
141 } // if
142
143 string::size_type posn;
144
145 if ( isdigit( str[last] ) ) { // no suffix ?
146 lnthSuffix( str, type, ltype ); // could have length suffix
147 if ( type == -1 ) {
148 // no suffix type, use value to determine type
149 if ( v <= INT_MAX ) { // signed int
150 type = 2;
151 } else if ( v <= UINT_MAX && ! dec ) { // unsigned int
152 type = 2;
153 Unsigned = true; // unsigned
154 } else if ( v <= LONG_MAX ) { // signed long int
155 type = 3;
156 } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int
157 type = 3;
158 Unsigned = true; // unsigned long int
159 } else if ( v <= LLONG_MAX ) { // signed long long int
160 type = 4;
161 } else { // unsigned long long int
162 type = 4;
163 Unsigned = true; // unsigned long long int
164 } // if
165 } // if
166 } else {
167 // At least one digit in integer constant, so safe to backup while looking for suffix.
168
169 if ( str.find_last_of( "uU" ) != string::npos ) Unsigned = true;
170
171 posn = str.rfind( "hh" );
172 if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
173
174 posn = str.rfind( "HH" );
175 if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
176
177 posn = str.find_last_of( "hH" );
178 if ( posn != string::npos ) { type = 0; str.erase( posn, 1 ); goto FINI; }
179
180 posn = str.find_last_of( "nN" );
181 if ( posn != string::npos ) { type = 2; str.erase( posn, 1 ); goto FINI; }
182
183 posn = str.find_last_of( "zZ" );
184 if ( posn != string::npos ) { Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); goto FINI; }
185
186 if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) { type = 4; goto FINI; }
187
188 lnthSuffix( str, type, ltype ); // must be after check for "ll"
189 if ( type == -1 ) { type = 3; goto FINI; }
190 FINI: ;
191 } // if
192
193 //if ( !( 0 <= type && type < 6 ) ) { printf( "%s %lu %d %s\n", fred.c_str(), fred.length(), type, str.c_str() ); }
194 assert( 0 <= type && type < 6 );
195
196 // Constant type is correct for overload resolving.
197 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][type] ), str, v ) );
198 if ( Unsigned && type < 2 ) { // hh or h, less than int ?
199 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values.
200 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][type] ), false );
201 } else if ( ltype != -1 ) { // explicit length ?
202 if ( ltype == 5 ) { // int128 ?
203 type = 5;
204 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][type] ), false );
205 } else {
206 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][ltype], false ), false );
207 } // if
208 } // if
209
210 CLEANUP: ;
211 delete &str; // created by lex
212 return ret;
213} // build_constantInteger
214
215
216static inline void checkFnxFloat( string & str, size_t last, bool & explnth, int & type ) {
217 string::size_type posn;
218 // floating-point constant has minimum of 2 characters, 1. or .1, so safe to look ahead
219 if ( str[1] == 'x' ) { // hex ?
220 posn = str.find_last_of( "pP" ); // back for exponent (must have)
221 posn = str.find_first_of( "fF", posn + 1 ); // forward for size (fF allowed in hex constant)
222 } else {
223 posn = str.find_last_of( "fF" ); // back for size (fF not allowed)
224 } // if
225 if ( posn == string::npos ) return;
226 explnth = true;
227 posn += 1; // advance to size
228 if ( str[posn] == '3' ) { // 32
229 if ( str[last] != 'x' ) type = 6;
230 else type = 7;
231 } else if ( str[posn] == '6' ) { // 64
232 if ( str[last] != 'x' ) type = 8;
233 else type = 9;
234 } else if ( str[posn] == '8' ) { // 80
235 type = 3;
236 } else if ( str[posn] == '1' ) { // 16/128
237 if ( str[posn + 1] == '6' ) { // 16
238 type = 5;
239 } else { // 128
240 if ( str[last] != 'x' ) type = 10;
241 else type = 11;
242 } // if
243 } else {
244 assertf( false, "internal error, bad floating point length %s", str.c_str() );
245 } // if
246} // checkFnxFloat
247
248
249Expression * build_constantFloat( string & str ) {
250 static const BasicType::Kind kind[2][12] = {
251 { BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::uuFloat80, BasicType::uuFloat128, BasicType::uFloat16, BasicType::uFloat32, BasicType::uFloat32x, BasicType::uFloat64, BasicType::uFloat64x, BasicType::uFloat128, BasicType::uFloat128x },
252 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, (BasicType::Kind)-1, (BasicType::Kind)-1, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex },
253 };
254
255 // floating-point constant has minimum of 2 characters 1. or .1
256 size_t last = str.length() - 1;
257 double v;
258 int type; // 0 => float, 1 => double, 3 => long double, ...
259 bool complx = false; // real, complex
260 bool explnth = false; // explicit literal length
261
262 sscanf( str.c_str(), "%lg", &v );
263
264 if ( checkI( str[last] ) ) { // imaginary ?
265 complx = true;
266 last -= 1; // backup one character
267 } // if
268
269 if ( checkF( str[last] ) ) { // float ?
270 type = 0;
271 } else if ( checkD( str[last] ) ) { // double ?
272 type = 1;
273 } else if ( checkL( str[last] ) ) { // long double ?
274 type = 2;
275 } else if ( checkF80( str[last] ) ) { // __float80 ?
276 type = 3;
277 } else if ( checkF128( str[last] ) ) { // __float128 ?
278 type = 4;
279 } else {
280 type = 1; // double (default if no suffix)
281 checkFnxFloat( str, last, explnth, type );
282 } // if
283
284 if ( ! complx && checkI( str[last - 1] ) ) { // imaginary ?
285 complx = true;
286 } // if
287
288 assert( 0 <= type && type < 12 );
289 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][type] ), str, v ) );
290 if ( explnth ) { // explicit length ?
291 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][type] ), false );
292 } // if
293
294 delete &str; // created by lex
295 return ret;
296} // build_constantFloat
297
298static void sepString( string & str, string & units, char delimit ) {
299 string::size_type posn = str.find_last_of( delimit ) + 1;
300 if ( posn != str.length() ) {
301 units = "?" + str.substr( posn ); // extract units
302 str.erase( posn ); // remove units
303 } // if
304} // sepString
305
306Expression * build_constantChar( string & str ) {
307 string units; // units
308 sepString( str, units, '\'' ); // separate constant from units
309
310 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
311 if ( units.length() != 0 ) {
312 ret = new UntypedExpr( new NameExpr( units ), { ret } );
313 } // if
314
315 delete &str; // created by lex
316 return ret;
317} // build_constantChar
318
319Expression * build_constantStr( string & str ) {
320 assert( str.length() > 0 );
321 string units; // units
322 sepString( str, units, '"' ); // separate constant from units
323
324 Type * strtype;
325 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1
326 case 'u':
327 if ( str[1] == '8' ) goto Default; // utf-8 characters => array of char
328 // lookup type of associated typedef
329 strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char16_t", false );
330 break;
331 case 'U':
332 strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char32_t", false );
333 break;
334 case 'L':
335 strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "wchar_t", false );
336 break;
337 Default: // char default string type
338 default:
339 strtype = new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char );
340 } // switch
341 ArrayType * at = new ArrayType( noQualifiers, strtype,
342 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
343 false, false );
344 Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
345 if ( units.length() != 0 ) {
346 ret = new UntypedExpr( new NameExpr( units ), { ret } );
347 } // if
348
349 delete &str; // created by lex
350 return ret;
351} // build_constantStr
352
353Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) {
354 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) SemanticError( yylloc, "invalid tuple index " + str );
355 Expression * ret = build_constantInteger( *new string( str.substr(1) ) );
356 delete &str;
357 return ret;
358} // build_field_name_FLOATING_FRACTIONconstant
359
360Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) {
361 if ( str[str.size()-1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str );
362 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );
363 delete &str;
364 return ret;
365} // build_field_name_FLOATING_DECIMALconstant
366
367Expression * build_field_name_FLOATINGconstant( const string & str ) {
368 // str is of the form A.B -> separate at the . and return member expression
369 int a, b;
370 char dot;
371 stringstream ss( str );
372 ss >> a >> dot >> b;
373 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) );
374 delete &str;
375 return ret;
376} // build_field_name_FLOATINGconstant
377
378Expression * make_field_name_fraction_constants( Expression * fieldName, Expression * fracts ) {
379 if ( fracts ) {
380 if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * >( fracts ) ) {
381 memberExpr->set_member( make_field_name_fraction_constants( fieldName, memberExpr->get_aggregate() ) );
382 return memberExpr;
383 } else {
384 return new UntypedMemberExpr( fracts, fieldName );
385 } // if
386 } // if
387 return fieldName;
388} // make_field_name_fraction_constants
389
390Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ) {
391 return make_field_name_fraction_constants( fieldName, maybeMoveBuild< Expression >( fracts ) );
392} // build_field_name_fraction_constants
393
394NameExpr * build_varref( const string * name ) {
395 NameExpr * expr = new NameExpr( *name );
396 delete name;
397 return expr;
398} // build_varref
399
400// TODO: get rid of this and OperKinds and reuse code from OperatorTable
401static const char * OperName[] = { // must harmonize with OperKinds
402 // diadic
403 "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&",
404 "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?",
405 "?=?", "?@=?", "?\\=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?",
406 "?[?]", "...",
407 // monadic
408 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--",
409}; // OperName
410
411Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
412 Type * targetType = maybeMoveBuildType( decl_node );
413 if ( dynamic_cast< VoidType * >( targetType ) ) {
414 delete targetType;
415 return new CastExpr( maybeMoveBuild< Expression >(expr_node), false );
416 } else {
417 return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType, false );
418 } // if
419} // build_cast
420
421Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ) {
422 return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target );
423}
424
425Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
426 return new VirtualCastExpr( maybeMoveBuild< Expression >( expr_node ), maybeMoveBuildType( decl_node ) );
427} // build_virtual_cast
428
429Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
430 return new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
431} // build_fieldSel
432
433Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) {
434 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
435 deref->location = expr_node->location;
436 deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
437 UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
438 return ret;
439} // build_pfieldSel
440
441Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
442 Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
443 delete member;
444 return ret;
445} // build_offsetOf
446
447Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) {
448 return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
449} // build_and_or
450
451Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
452 list< Expression * > args;
453 args.push_back( maybeMoveBuild< Expression >(expr_node) );
454 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
455} // build_unary_val
456
457Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
458 list< Expression * > args;
459 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
460 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
461} // build_unary_ptr
462
463Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
464 list< Expression * > args;
465 args.push_back( maybeMoveBuild< Expression >(expr_node1) );
466 args.push_back( maybeMoveBuild< Expression >(expr_node2) );
467 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
468} // build_binary_val
469
470Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
471 list< Expression * > args;
472 args.push_back( maybeMoveBuild< Expression >(expr_node1) );
473 args.push_back( maybeMoveBuild< Expression >(expr_node2) );
474 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
475} // build_binary_ptr
476
477Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) {
478 return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
479} // build_cond
480
481Expression * build_tuple( ExpressionNode * expr_node ) {
482 list< Expression * > exprs;
483 buildMoveList( expr_node, exprs );
484 return new UntypedTupleExpr( exprs );;
485} // build_tuple
486
487Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
488 list< Expression * > args;
489 buildMoveList( expr_node, args );
490 return new UntypedExpr( maybeMoveBuild< Expression >(function), args );
491} // build_func
492
493Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
494 Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
495 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
496 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) );
497 // these types do not have associated type information
498 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) {
499 if ( newDeclStructDecl->has_body() ) {
500 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild< Initializer >(kids) );
501 } else {
502 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
503 } // if
504 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) {
505 if ( newDeclUnionDecl->has_body() ) {
506 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild< Initializer >(kids) );
507 } else {
508 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
509 } // if
510 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) {
511 if ( newDeclEnumDecl->has_body() ) {
512 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild< Initializer >(kids) );
513 } else {
514 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
515 } // if
516 } else {
517 assert( false );
518 } // if
519} // build_compoundLiteral
520
521// Local Variables: //
522// tab-width: 4 //
523// mode: c++ //
524// compile-command: "make install" //
525// End: //
Note: See TracBrowser for help on using the repository browser.