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