source: src/Parser/ExpressionNode.cc @ ba54f7d

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ba54f7d was 513e165, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

generalize types for encoded strings, and fold simple ExpressionNode? build routines into parser

  • Property mode set to 100644
File size: 19.6 KB
RevLine 
[b87a5ed]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//
[0caaa6a]7// ExpressionNode.cc --
8//
[f43df73]9// Author           : Peter A. Buhr
[b87a5ed]10// Created On       : Sat May 16 13:17:07 2015
[76c62b2]11// Last Modified By : Peter A. Buhr
[513e165]12// Last Modified On : Wed Sep 13 14:54:19 2017
13// Update Count     : 683
[0caaa6a]14//
[b87a5ed]15
[ea6332d]16#include <cassert>                 // for assert
[d180746]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==
[51b7345]22
[d180746]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;
[51b7345]34
35using namespace std;
36
[cd623a4]37//##############################################################################
38
[7bf7fb9]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
[beec62c]51extern const Type::Qualifiers noQualifiers;                             // no qualifiers on constants
[7bf7fb9]52
[930f69e]53static inline bool checkH( char c ) { return c == 'h' || c == 'H'; }
[7bf7fb9]54static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }
[930f69e]55static inline bool checkZ( char c ) { return c == 'z' || c == 'Z'; }
56static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
[7bf7fb9]57static inline bool checkF( char c ) { return c == 'f' || c == 'F'; }
58static inline bool checkD( char c ) { return c == 'd' || c == 'D'; }
59static inline bool checkI( char c ) { return c == 'i' || c == 'I'; }
60static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
61
[76c62b2]62static void sepNumeric( string & str, string & units ) {
63        string::size_type posn = str.find_first_of( "`" );
64        if ( posn != string::npos ) {
[e8ccca3]65                units = "?" + str.substr( posn );                               // extract units
[76c62b2]66                str.erase( posn );                                                              // remove units
67        } // if
68} // sepNumeric
69
[ba2a68b]70Expression * build_constantInteger( string & str ) {
[930f69e]71        static const BasicType::Kind kind[2][5] = {
72                // short (h) must be before char (hh)
73                { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
74                { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
[7bf7fb9]75        };
[76c62b2]76
77        string units;                                                                           // units
78        sepNumeric( str, units );                                                       // separate constant from units
79
[7bf7fb9]80        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
[beec62c]81        int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t
[6165ce7]82        unsigned long long int v;                                                       // converted integral value
[7bf7fb9]83        size_t last = str.length() - 1;                                         // last character of constant
[6165ce7]84        Expression * ret;
[7bf7fb9]85
[6165ce7]86        // special constants
87        if ( str == "0" ) {
88                ret = new ConstantExpr( Constant( (Type *)new ZeroType( noQualifiers ), str, (unsigned long long int)0 ) );
89                goto CLEANUP;
90        } // if
91        if ( str == "1" ) {
92                ret = new ConstantExpr( Constant( (Type *)new OneType( noQualifiers ), str, (unsigned long long int)1 ) );
93                goto CLEANUP;
94        } // if
[ea6332d]95
[7bf7fb9]96        if ( str[0] == '0' ) {                                                          // octal/hex constant ?
97                dec = false;
98                if ( last != 0 && checkX( str[1] ) ) {                  // hex constant ?
99                        sscanf( (char *)str.c_str(), "%llx", &v );
100                        //printf( "%llx %llu\n", v, v );
101                } else {                                                                                // octal constant
102                        sscanf( (char *)str.c_str(), "%llo", &v );
103                        //printf( "%llo %llu\n", v, v );
104                } // if
105        } else {                                                                                        // decimal constant ?
106                sscanf( (char *)str.c_str(), "%llu", &v );
107                //printf( "%llu %llu\n", v, v );
108        } // if
109
110        if ( v <= INT_MAX ) {                                                           // signed int
[930f69e]111                size = 2;
[7bf7fb9]112        } else if ( v <= UINT_MAX && ! dec ) {                          // unsigned int
[930f69e]113                size = 2;
[7bf7fb9]114                Unsigned = true;                                                                // unsigned
115        } else if ( v <= LONG_MAX ) {                                           // signed long int
[930f69e]116                size = 3;
[7bf7fb9]117        } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int
[930f69e]118                size = 3;
[7bf7fb9]119                Unsigned = true;                                                                // unsigned long int
120        } else if ( v <= LLONG_MAX ) {                                          // signed long long int
[930f69e]121                size = 4;
[7bf7fb9]122        } else {                                                                                        // unsigned long long int
[930f69e]123                size = 4;
[7bf7fb9]124                Unsigned = true;                                                                // unsigned long long int
125        } // if
126
[930f69e]127        // At least one digit in integer constant, so safe to backup while looking for suffix.
128
[7bf7fb9]129        if ( checkU( str[last] ) ) {                                            // suffix 'u' ?
130                Unsigned = true;
[930f69e]131                if ( checkL( str[last - 1] ) ) {                                // suffix 'l' ?
132                        size = 3;
133                        if ( checkL( str[last - 2] ) ) {                        // suffix "ll" ?
134                                size = 4;
[7bf7fb9]135                        } // if
[930f69e]136                } else if ( checkH( str[last - 1] ) ) {                 // suffix 'h' ?
137                        size = 0;
138                        if ( checkH( str[last - 2] ) ) {                        // suffix "hh" ?
139                                size = 1;
140                        } // if
141                        str.erase( last - size - 1, size + 1 );         // remove 'h'/"hh"
[7bf7fb9]142                } // if
143        } else if ( checkL( str[ last ] ) ) {                           // suffix 'l' ?
[930f69e]144                size = 3;
145                if ( checkL( str[last - 1] ) ) {                                // suffix 'll' ?
146                        size = 4;
147                        if ( checkU( str[last - 2] ) ) {                        // suffix 'u' ?
[7bf7fb9]148                                Unsigned = true;
149                        } // if
[930f69e]150                } else if ( checkU( str[last - 1] ) ) {                 // suffix 'u' ?
151                        Unsigned = true;
152                } // if
153        } else if ( checkH( str[ last ] ) ) {                           // suffix 'h' ?
154                size = 0;
155                if ( checkH( str[last - 1] ) ) {                                // suffix "hh" ?
156                        size = 1;
157                        if ( checkU( str[last - 2] ) ) {                        // suffix 'u' ?
[7bf7fb9]158                                Unsigned = true;
159                        } // if
[930f69e]160                } else if ( checkU( str[last - 1] ) ) {                 // suffix 'u' ?
161                        Unsigned = true;
[7bf7fb9]162                } // if
[930f69e]163                str.erase( last - size, size + 1 );                             // remove 'h'/"hh"
164        } else if ( checkZ( str[last] ) ) {                                     // suffix 'z' ?
[beec62c]165                size = 5;
[930f69e]166                str.erase( last, 1 );                                                   // remove 'z'
[7bf7fb9]167        } // if
168
[e8ccca3]169        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
[7b1d5ec]170        if ( Unsigned && size < 2 ) {                                           // less than int ?
[beec62c]171                // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates warnings for large values.
[7b1d5ec]172                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
[beec62c]173        } else if ( size == 5 ) {                                                       // explicit cast to size_t
174                ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) );
[7b1d5ec]175        } // if
[6165ce7]176  CLEANUP:
[e8ccca3]177        if ( units.length() != 0 ) {
[ba2a68b]178                ret = new UntypedExpr( new NameExpr( units ), { ret } );
[e8ccca3]179        } // if
180
[ab57786]181        delete &str;                                                                            // created by lex
182        return ret;
[7bf7fb9]183} // build_constantInteger
[51b7345]184
[f43df73]185Expression * build_constantFloat( string & str ) {
[7bf7fb9]186        static const BasicType::Kind kind[2][3] = {
187                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
188                { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex },
189        };
[59c24b6]190
[76c62b2]191        string units;                                                                           // units
192        sepNumeric( str, units );                                                       // separate constant from units
193
[7bf7fb9]194        bool complx = false;                                                            // real, complex
195        int size = 1;                                                                           // 0 => float, 1 => double (default), 2 => long double
196        // floating-point constant has minimum of 2 characters: 1. or .1
197        size_t last = str.length() - 1;
[d56e5bc]198        double v;
199
200        sscanf( str.c_str(), "%lg", &v );
[51b7345]201
[7bf7fb9]202        if ( checkI( str[last] ) ) {                                            // imaginary ?
203                complx = true;
204                last -= 1;                                                                              // backup one character
205        } // if
[0caaa6a]206
[7bf7fb9]207        if ( checkF( str[last] ) ) {                                            // float ?
208                size = 0;
209        } else if ( checkD( str[last] ) ) {                                     // double ?
210                size = 1;
211        } else if ( checkL( str[last] ) ) {                                     // long double ?
212                size = 2;
213        } // if
214        if ( ! complx && checkI( str[last - 1] ) ) {            // imaginary ?
215                complx = true;
216        } // if
[51b7345]217
[e8ccca3]218        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
219        if ( units.length() != 0 ) {
[ba2a68b]220                ret = new UntypedExpr( new NameExpr( units ), { ret } );
[e8ccca3]221        } // if
[76c62b2]222
[ab57786]223        delete &str;                                                                            // created by lex
224        return ret;
[7bf7fb9]225} // build_constantFloat
[51b7345]226
[76c62b2]227static void sepString( string & str, string & units, char delimit ) {
228        string::size_type posn = str.find_last_of( delimit ) + 1;
229        if ( posn != str.length() ) {
[e8ccca3]230                units = "?" + str.substr( posn );                               // extract units
[76c62b2]231                str.erase( posn );                                                              // remove units
232        } // if
233} // sepString
234
[f43df73]235Expression * build_constantChar( string & str ) {
[76c62b2]236        string units;                                                                           // units
237        sepString( str, units, '\'' );                                          // separate constant from units
238
[e8ccca3]239        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
240        if ( units.length() != 0 ) {
[ba2a68b]241                ret = new UntypedExpr( new NameExpr( units ), { ret } );
[e8ccca3]242        } // if
[76c62b2]243
[ab57786]244        delete &str;                                                                            // created by lex
245        return ret;
[7bf7fb9]246} // build_constantChar
[51b7345]247
[e612146c]248Expression * build_constantStr( string & str ) {
[76c62b2]249        string units;                                                                           // units
250        sepString( str, units, '"' );                                           // separate constant from units
251
[513e165]252        Type * strtype;
253        switch ( str[0] ) {                                                                     // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1
[e612146c]254          case 'u':
[513e165]255                if ( str[1] == '8' ) goto Default;                              // utf-8 characters => array of char
256                // lookup type of associated typedef
257                strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char16_t", false );
[e612146c]258                break;
259          case 'U':
[513e165]260                strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char32_t", false );
[e612146c]261                break;
262          case 'L':
[513e165]263                strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "wchar_t", false );
[e612146c]264                break;
[513e165]265          Default:                                                                                      // char default string type
266          default:
267                strtype = new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char );
[e612146c]268        } // switch
[513e165]269        ArrayType * at = new ArrayType( noQualifiers, strtype,
[e8ccca3]270                                                                        new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
271                                                                        false, false );
[e612146c]272        Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
273        if ( units.length() != 0 ) {
274                ret = new UntypedExpr( new NameExpr( units ), { ret } );
275        } // if
[5809461]276
[ab57786]277        delete &str;                                                                            // created by lex
278        return ret;
[7bf7fb9]279} // build_constantStr
[51b7345]280
[930f69e]281Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) {
282        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
283        Expression * ret = build_constantInteger( *new string( str.substr(1) ) );
284        delete &str;
285        return ret;
286} // build_field_name_FLOATING_FRACTIONconstant
287
288Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) {
289        if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str );
290        Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );
291        delete &str;
292        return ret;
293} // build_field_name_FLOATING_DECIMALconstant
294
[f43df73]295Expression * build_field_name_FLOATINGconstant( const string & str ) {
[8780e30]296        // str is of the form A.B -> separate at the . and return member expression
297        int a, b;
298        char dot;
[f43df73]299        stringstream ss( str );
[8780e30]300        ss >> a >> dot >> b;
[d56e5bc]301        UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) );
[8780e30]302        delete &str;
303        return ret;
304} // build_field_name_FLOATINGconstant
305
306Expression * make_field_name_fraction_constants( Expression * fieldName, Expression * fracts ) {
307        if ( fracts ) {
308                if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * >( fracts ) ) {
309                        memberExpr->set_member( make_field_name_fraction_constants( fieldName, memberExpr->get_aggregate() ) );
310                        return memberExpr;
311                } else {
312                        return new UntypedMemberExpr( fracts, fieldName );
[f43df73]313                } // if
314        } // if
[8780e30]315        return fieldName;
316} // make_field_name_fraction_constants
317
318Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ) {
319        return make_field_name_fraction_constants( fieldName, maybeMoveBuild< Expression >( fracts ) );
320} // build_field_name_fraction_constants
321
[a2e0687]322NameExpr * build_varref( const string * name ) {
323        NameExpr * expr = new NameExpr( *name, nullptr );
[7ecbb7e]324        delete name;
325        return expr;
[a2e0687]326} // build_varref
[51b1202]327
[5809461]328// TODO: get rid of this and OperKinds and reuse code from OperatorTable
[a2e0687]329static const char * OperName[] = {                                              // must harmonize with OperKinds
[5721a6d]330        // diadic
[e5f2a67]331        "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&",
[5721a6d]332        "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?",
[e5f2a67]333        "?=?", "?@=?", "?\\=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?",
[d9e2280]334        "?[?]", "...",
[5721a6d]335        // monadic
[5809461]336        "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--",
[a2e0687]337}; // OperName
[5721a6d]338
[a2e0687]339Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
340        Type * targetType = maybeMoveBuildType( decl_node );
[d1625f8]341        if ( dynamic_cast< VoidType * >( targetType ) ) {
[064e3ff]342                delete targetType;
[7ecbb7e]343                return new CastExpr( maybeMoveBuild< Expression >(expr_node) );
[064e3ff]344        } else {
[7ecbb7e]345                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
[064e3ff]346        } // if
[a2e0687]347} // build_cast
[a5f0529]348
[a2e0687]349Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
[513e165]350        return new VirtualCastExpr( maybeMoveBuild< Expression >( expr_node ), maybeMoveBuildType( decl_node ) );
[a2e0687]351} // build_virtual_cast
[064e3ff]352
[a2e0687]353Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
[513e165]354        return new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
[a2e0687]355} // build_fieldSel
[064e3ff]356
[a2e0687]357Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) {
358        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
[64ac636]359        deref->location = expr_node->location;
[7ecbb7e]360        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
[a2e0687]361        UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
[064e3ff]362        return ret;
[a2e0687]363} // build_pfieldSel
[064e3ff]364
[a2e0687]365Expression * build_addressOf( ExpressionNode * expr_node ) {
[513e165]366        return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
[a2e0687]367} // build_addressOf
368
369Expression * build_sizeOfexpr( ExpressionNode * expr_node ) {
[7ecbb7e]370        return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
[a2e0687]371} // build_sizeOfexpr
372
373Expression * build_sizeOftype( DeclarationNode * decl_node ) {
[4f147cc]374        return new SizeofExpr( maybeMoveBuildType( decl_node ) );
[a2e0687]375} // build_sizeOftype
376
377Expression * build_alignOfexpr( ExpressionNode * expr_node ) {
[7ecbb7e]378        return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
[a2e0687]379} // build_alignOfexpr
380
381Expression * build_alignOftype( DeclarationNode * decl_node ) {
[4f147cc]382        return new AlignofExpr( maybeMoveBuildType( decl_node) );
[a2e0687]383} // build_alignOftype
384
385Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
[a7c90d4]386        Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
[ac71a86]387        delete member;
388        return ret;
[a2e0687]389} // build_offsetOf
[064e3ff]390
[a2e0687]391Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) {
[7ecbb7e]392        return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
[a2e0687]393} // build_and_or
[51e076e]394
[a2e0687]395Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
[f43df73]396        list< Expression * > args;
[7ecbb7e]397        args.push_back( maybeMoveBuild< Expression >(expr_node) );
[d9e2280]398        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
[a2e0687]399} // build_unary_val
400
401Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
[f43df73]402        list< Expression * > args;
[cccc534]403        args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
[d9e2280]404        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
[a2e0687]405} // build_unary_ptr
406
407Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
[f43df73]408        list< Expression * > args;
[7ecbb7e]409        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
410        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
[d9e2280]411        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
[a2e0687]412} // build_binary_val
413
414Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
[f43df73]415        list< Expression * > args;
[cda7889]416        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
[7ecbb7e]417        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
[d9e2280]418        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
[a2e0687]419} // build_binary_ptr
[51e076e]420
[a2e0687]421Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) {
[7ecbb7e]422        return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
[a2e0687]423} // build_cond
[51e076e]424
[a2e0687]425Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) {
[7ecbb7e]426        return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
[a2e0687]427} // build_attrexpr
428
429Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) {
[4f147cc]430        return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
[a2e0687]431} // build_attrtype
[9706554]432
[a2e0687]433Expression * build_tuple( ExpressionNode * expr_node ) {
[f43df73]434        list< Expression * > exprs;
[907eccb]435        buildMoveList( expr_node, exprs );
436        return new UntypedTupleExpr( exprs );;
[a2e0687]437} // build_tuple
[9706554]438
[a2e0687]439Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
[f43df73]440        list< Expression * > args;
[7ecbb7e]441        buildMoveList( expr_node, args );
442        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
[a2e0687]443} // build_func
[9706554]444
[a2e0687]445Expression * build_range( ExpressionNode * low, ExpressionNode * high ) {
[7ecbb7e]446        return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
[a2e0687]447} // build_range
[51b7345]448
[a2e0687]449Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
[7880579]450        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
[630a82a]451        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
[7ecbb7e]452                return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) );
[630a82a]453        // these types do not have associated type information
454        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
[fbcde64]455                if ( newDeclStructDecl->has_body() ) {
456                        return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild< Initializer >(kids) );
457                } else {
458                        return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
459                } // if
[630a82a]460        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
[fbcde64]461                if ( newDeclUnionDecl->has_body() ) {
462                        return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild< Initializer >(kids) );
463                } else {
464                        return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
465                } // if
[630a82a]466        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
[fbcde64]467                if ( newDeclEnumDecl->has_body() ) {
468                        return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild< Initializer >(kids) );
469                } else {
470                        return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
471                } // if
[630a82a]472        } else {
473                assert( false );
474        } // if
[a2e0687]475} // build_compoundLiteral
[630a82a]476
[b87a5ed]477// Local Variables: //
478// tab-width: 4 //
479// mode: c++ //
480// compile-command: "make install" //
481// End: //
Note: See TracBrowser for help on using the repository browser.