[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
|
---|
[e612146c] | 12 | // Last Modified On : Sun Sep 3 22:21:21 2017
|
---|
| 13 | // Update Count : 639
|
---|
[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==
|
---|
[51b73452] | 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;
|
---|
[51b73452] | 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 |
|
---|
[ba2a68b] | 68 | Expression * build_constantInteger( 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 ) {
|
---|
[ba2a68b] | 150 | ret = new UntypedExpr( new NameExpr( units ), { ret } );
|
---|
[e8ccca3] | 151 | } // if
|
---|
| 152 |
|
---|
[ab57786] | 153 | delete &str; // created by lex
|
---|
| 154 | return ret;
|
---|
[7bf7fb9] | 155 | } // build_constantInteger
|
---|
[51b73452] | 156 |
|
---|
[f43df73] | 157 | Expression * build_constantFloat( 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 );
|
---|
[51b73452] | 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
|
---|
[51b73452] | 189 |
|
---|
[e8ccca3] | 190 | Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
|
---|
| 191 | if ( units.length() != 0 ) {
|
---|
[ba2a68b] | 192 | ret = new UntypedExpr( new NameExpr( units ), { ret } );
|
---|
[e8ccca3] | 193 | } // if
|
---|
[76c62b2] | 194 |
|
---|
[ab57786] | 195 | delete &str; // created by lex
|
---|
| 196 | return ret;
|
---|
[7bf7fb9] | 197 | } // build_constantFloat
|
---|
[51b73452] | 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 |
|
---|
[f43df73] | 207 | Expression * build_constantChar( string & str ) {
|
---|
[76c62b2] | 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 ) {
|
---|
[ba2a68b] | 213 | ret = new UntypedExpr( new NameExpr( units ), { ret } );
|
---|
[e8ccca3] | 214 | } // if
|
---|
[76c62b2] | 215 |
|
---|
[ab57786] | 216 | delete &str; // created by lex
|
---|
| 217 | return ret;
|
---|
[7bf7fb9] | 218 | } // build_constantChar
|
---|
[51b73452] | 219 |
|
---|
[e612146c] | 220 | Expression * build_constantStr( string & str ) {
|
---|
[76c62b2] | 221 | string units; // units
|
---|
| 222 | sepString( str, units, '"' ); // separate constant from units
|
---|
| 223 |
|
---|
[e612146c] | 224 | BasicType::Kind strtype = BasicType::Char; // default string type
|
---|
| 225 | switch ( str[0] ) { // str has >= 2 characters, i.e, null string ""
|
---|
| 226 | case 'u':
|
---|
| 227 | if ( str[1] == '8' ) break; // utf-8 characters
|
---|
| 228 | strtype = BasicType::ShortUnsignedInt;
|
---|
| 229 | break;
|
---|
| 230 | case 'U':
|
---|
| 231 | strtype = BasicType::UnsignedInt;
|
---|
| 232 | break;
|
---|
| 233 | case 'L':
|
---|
| 234 | strtype = BasicType::SignedInt;
|
---|
| 235 | break;
|
---|
| 236 | } // switch
|
---|
| 237 | ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ),
|
---|
[e8ccca3] | 238 | new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
|
---|
| 239 | false, false );
|
---|
[e612146c] | 240 | Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
|
---|
| 241 | if ( units.length() != 0 ) {
|
---|
| 242 | ret = new UntypedExpr( new NameExpr( units ), { ret } );
|
---|
| 243 | } // if
|
---|
[5809461] | 244 |
|
---|
[ab57786] | 245 | delete &str; // created by lex
|
---|
| 246 | return ret;
|
---|
[7bf7fb9] | 247 | } // build_constantStr
|
---|
[51b73452] | 248 |
|
---|
[f43df73] | 249 | Expression * build_field_name_FLOATINGconstant( const string & str ) {
|
---|
[8780e30] | 250 | // str is of the form A.B -> separate at the . and return member expression
|
---|
| 251 | int a, b;
|
---|
| 252 | char dot;
|
---|
[f43df73] | 253 | stringstream ss( str );
|
---|
[8780e30] | 254 | ss >> a >> dot >> b;
|
---|
[d56e5bc] | 255 | UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) );
|
---|
[8780e30] | 256 | delete &str;
|
---|
| 257 | return ret;
|
---|
| 258 | } // build_field_name_FLOATINGconstant
|
---|
| 259 |
|
---|
| 260 | Expression * make_field_name_fraction_constants( Expression * fieldName, Expression * fracts ) {
|
---|
| 261 | if ( fracts ) {
|
---|
| 262 | if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * >( fracts ) ) {
|
---|
| 263 | memberExpr->set_member( make_field_name_fraction_constants( fieldName, memberExpr->get_aggregate() ) );
|
---|
| 264 | return memberExpr;
|
---|
| 265 | } else {
|
---|
| 266 | return new UntypedMemberExpr( fracts, fieldName );
|
---|
[f43df73] | 267 | } // if
|
---|
| 268 | } // if
|
---|
[8780e30] | 269 | return fieldName;
|
---|
| 270 | } // make_field_name_fraction_constants
|
---|
| 271 |
|
---|
| 272 | Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ) {
|
---|
| 273 | return make_field_name_fraction_constants( fieldName, maybeMoveBuild< Expression >( fracts ) );
|
---|
| 274 | } // build_field_name_fraction_constants
|
---|
| 275 |
|
---|
[f43df73] | 276 | Expression * build_field_name_REALFRACTIONconstant( const string & str ) {
|
---|
[0213af6] | 277 | if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
|
---|
[f43df73] | 278 | Expression * ret = build_constantInteger( *new string( str.substr(1) ) );
|
---|
[8780e30] | 279 | delete &str;
|
---|
| 280 | return ret;
|
---|
| 281 | } // build_field_name_REALFRACTIONconstant
|
---|
| 282 |
|
---|
[f43df73] | 283 | Expression * build_field_name_REALDECIMALconstant( const string & str ) {
|
---|
[0213af6] | 284 | if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str );
|
---|
[f43df73] | 285 | Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );
|
---|
[8780e30] | 286 | delete &str;
|
---|
| 287 | return ret;
|
---|
| 288 | } // build_field_name_REALDECIMALconstant
|
---|
| 289 |
|
---|
[a2e0687] | 290 | NameExpr * build_varref( const string * name ) {
|
---|
| 291 | NameExpr * expr = new NameExpr( *name, nullptr );
|
---|
[7ecbb7e] | 292 | delete name;
|
---|
| 293 | return expr;
|
---|
[a2e0687] | 294 | } // build_varref
|
---|
[51b1202] | 295 |
|
---|
[5809461] | 296 | // TODO: get rid of this and OperKinds and reuse code from OperatorTable
|
---|
[a2e0687] | 297 | static const char * OperName[] = { // must harmonize with OperKinds
|
---|
[5721a6d] | 298 | // diadic
|
---|
[e5f2a67] | 299 | "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&",
|
---|
[5721a6d] | 300 | "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?",
|
---|
[e5f2a67] | 301 | "?=?", "?@=?", "?\\=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?",
|
---|
[d9e2280] | 302 | "?[?]", "...",
|
---|
[5721a6d] | 303 | // monadic
|
---|
[5809461] | 304 | "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--",
|
---|
[a2e0687] | 305 | }; // OperName
|
---|
[5721a6d] | 306 |
|
---|
[a2e0687] | 307 | Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
|
---|
| 308 | Type * targetType = maybeMoveBuildType( decl_node );
|
---|
[d1625f8] | 309 | if ( dynamic_cast< VoidType * >( targetType ) ) {
|
---|
[064e3ff] | 310 | delete targetType;
|
---|
[7ecbb7e] | 311 | return new CastExpr( maybeMoveBuild< Expression >(expr_node) );
|
---|
[064e3ff] | 312 | } else {
|
---|
[7ecbb7e] | 313 | return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
|
---|
[064e3ff] | 314 | } // if
|
---|
[a2e0687] | 315 | } // build_cast
|
---|
[a5f0529] | 316 |
|
---|
[a2e0687] | 317 | Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
|
---|
| 318 | Type * targetType = maybeMoveBuildType( decl_node );
|
---|
| 319 | Expression * castArg = maybeMoveBuild< Expression >( expr_node );
|
---|
[a5f0529] | 320 | return new VirtualCastExpr( castArg, targetType );
|
---|
[a2e0687] | 321 | } // build_virtual_cast
|
---|
[064e3ff] | 322 |
|
---|
[a2e0687] | 323 | Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
|
---|
| 324 | UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
|
---|
[064e3ff] | 325 | return ret;
|
---|
[a2e0687] | 326 | } // build_fieldSel
|
---|
[064e3ff] | 327 |
|
---|
[a2e0687] | 328 | Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) {
|
---|
| 329 | UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
|
---|
[64ac636] | 330 | deref->location = expr_node->location;
|
---|
[7ecbb7e] | 331 | deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
|
---|
[a2e0687] | 332 | UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
|
---|
[064e3ff] | 333 | return ret;
|
---|
[a2e0687] | 334 | } // build_pfieldSel
|
---|
[064e3ff] | 335 |
|
---|
[a2e0687] | 336 | Expression * build_addressOf( ExpressionNode * expr_node ) {
|
---|
[7ecbb7e] | 337 | return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
|
---|
[a2e0687] | 338 | } // build_addressOf
|
---|
| 339 |
|
---|
| 340 | Expression * build_sizeOfexpr( ExpressionNode * expr_node ) {
|
---|
[7ecbb7e] | 341 | return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
|
---|
[a2e0687] | 342 | } // build_sizeOfexpr
|
---|
| 343 |
|
---|
| 344 | Expression * build_sizeOftype( DeclarationNode * decl_node ) {
|
---|
[4f147cc] | 345 | return new SizeofExpr( maybeMoveBuildType( decl_node ) );
|
---|
[a2e0687] | 346 | } // build_sizeOftype
|
---|
| 347 |
|
---|
| 348 | Expression * build_alignOfexpr( ExpressionNode * expr_node ) {
|
---|
[7ecbb7e] | 349 | return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
|
---|
[a2e0687] | 350 | } // build_alignOfexpr
|
---|
| 351 |
|
---|
| 352 | Expression * build_alignOftype( DeclarationNode * decl_node ) {
|
---|
[4f147cc] | 353 | return new AlignofExpr( maybeMoveBuildType( decl_node) );
|
---|
[a2e0687] | 354 | } // build_alignOftype
|
---|
| 355 |
|
---|
| 356 | Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
|
---|
[a7c90d4] | 357 | Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
|
---|
[ac71a86] | 358 | delete member;
|
---|
| 359 | return ret;
|
---|
[a2e0687] | 360 | } // build_offsetOf
|
---|
[064e3ff] | 361 |
|
---|
[a2e0687] | 362 | Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) {
|
---|
[7ecbb7e] | 363 | return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
|
---|
[a2e0687] | 364 | } // build_and_or
|
---|
[51e076e] | 365 |
|
---|
[a2e0687] | 366 | Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
|
---|
[f43df73] | 367 | list< Expression * > args;
|
---|
[7ecbb7e] | 368 | args.push_back( maybeMoveBuild< Expression >(expr_node) );
|
---|
[d9e2280] | 369 | return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
|
---|
[a2e0687] | 370 | } // build_unary_val
|
---|
| 371 |
|
---|
| 372 | Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
|
---|
[f43df73] | 373 | list< Expression * > args;
|
---|
[cccc534] | 374 | args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
|
---|
[d9e2280] | 375 | return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
|
---|
[a2e0687] | 376 | } // build_unary_ptr
|
---|
| 377 |
|
---|
| 378 | Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
|
---|
[f43df73] | 379 | list< Expression * > args;
|
---|
[7ecbb7e] | 380 | args.push_back( maybeMoveBuild< Expression >(expr_node1) );
|
---|
| 381 | args.push_back( maybeMoveBuild< Expression >(expr_node2) );
|
---|
[d9e2280] | 382 | return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
|
---|
[a2e0687] | 383 | } // build_binary_val
|
---|
| 384 |
|
---|
| 385 | Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
|
---|
[f43df73] | 386 | list< Expression * > args;
|
---|
[cda7889] | 387 | args.push_back( maybeMoveBuild< Expression >(expr_node1) );
|
---|
[7ecbb7e] | 388 | args.push_back( maybeMoveBuild< Expression >(expr_node2) );
|
---|
[d9e2280] | 389 | return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
|
---|
[a2e0687] | 390 | } // build_binary_ptr
|
---|
[51e076e] | 391 |
|
---|
[a2e0687] | 392 | Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) {
|
---|
[7ecbb7e] | 393 | return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
|
---|
[a2e0687] | 394 | } // build_cond
|
---|
[51e076e] | 395 |
|
---|
[a2e0687] | 396 | Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
|
---|
[7ecbb7e] | 397 | return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
|
---|
[a2e0687] | 398 | } // build_comma
|
---|
[51e076e] | 399 |
|
---|
[a2e0687] | 400 | Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) {
|
---|
[7ecbb7e] | 401 | return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
|
---|
[a2e0687] | 402 | } // build_attrexpr
|
---|
| 403 |
|
---|
| 404 | Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) {
|
---|
[4f147cc] | 405 | return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
|
---|
[a2e0687] | 406 | } // build_attrtype
|
---|
[9706554] | 407 |
|
---|
[a2e0687] | 408 | Expression * build_tuple( ExpressionNode * expr_node ) {
|
---|
[f43df73] | 409 | list< Expression * > exprs;
|
---|
[907eccb] | 410 | buildMoveList( expr_node, exprs );
|
---|
| 411 | return new UntypedTupleExpr( exprs );;
|
---|
[a2e0687] | 412 | } // build_tuple
|
---|
[9706554] | 413 |
|
---|
[a2e0687] | 414 | Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
|
---|
[f43df73] | 415 | list< Expression * > args;
|
---|
[7ecbb7e] | 416 | buildMoveList( expr_node, args );
|
---|
| 417 | return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
|
---|
[a2e0687] | 418 | } // build_func
|
---|
[9706554] | 419 |
|
---|
[a2e0687] | 420 | Expression * build_range( ExpressionNode * low, ExpressionNode * high ) {
|
---|
[7ecbb7e] | 421 | return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
|
---|
[a2e0687] | 422 | } // build_range
|
---|
[51b73452] | 423 |
|
---|
[e612146c] | 424 | Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) {
|
---|
[7ecbb7e] | 425 | return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
|
---|
[a2e0687] | 426 | } // build_asmexpr
|
---|
[7f5566b] | 427 |
|
---|
[a2e0687] | 428 | Expression * build_valexpr( StatementNode * s ) {
|
---|
[af5c204a] | 429 | return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
|
---|
[a2e0687] | 430 | } // build_valexpr
|
---|
| 431 |
|
---|
| 432 | Expression * build_typevalue( DeclarationNode * decl ) {
|
---|
[4f147cc] | 433 | return new TypeExpr( maybeMoveBuildType( decl ) );
|
---|
[a2e0687] | 434 | } // build_typevalue
|
---|
[630a82a] | 435 |
|
---|
[a2e0687] | 436 | Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
|
---|
[7880579] | 437 | Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
|
---|
[630a82a] | 438 | if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
|
---|
[7ecbb7e] | 439 | return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) );
|
---|
[630a82a] | 440 | // these types do not have associated type information
|
---|
| 441 | } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) {
|
---|
[fbcde64] | 442 | if ( newDeclStructDecl->has_body() ) {
|
---|
| 443 | return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild< Initializer >(kids) );
|
---|
| 444 | } else {
|
---|
| 445 | return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
|
---|
| 446 | } // if
|
---|
[630a82a] | 447 | } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) {
|
---|
[fbcde64] | 448 | if ( newDeclUnionDecl->has_body() ) {
|
---|
| 449 | return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild< Initializer >(kids) );
|
---|
| 450 | } else {
|
---|
| 451 | return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
|
---|
| 452 | } // if
|
---|
[630a82a] | 453 | } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) {
|
---|
[fbcde64] | 454 | if ( newDeclEnumDecl->has_body() ) {
|
---|
| 455 | return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild< Initializer >(kids) );
|
---|
| 456 | } else {
|
---|
| 457 | return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
|
---|
| 458 | } // if
|
---|
[630a82a] | 459 | } else {
|
---|
| 460 | assert( false );
|
---|
| 461 | } // if
|
---|
[a2e0687] | 462 | } // build_compoundLiteral
|
---|
[630a82a] | 463 |
|
---|
[b87a5ed] | 464 | // Local Variables: //
|
---|
| 465 | // tab-width: 4 //
|
---|
| 466 | // mode: c++ //
|
---|
| 467 | // compile-command: "make install" //
|
---|
| 468 | // End: //
|
---|