source: src/Parser/ExpressionNode.cc @ a16764a6

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 a16764a6 was a16764a6, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Changed warning system to prepare for toggling warnings

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