[54e41b3] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // Expr.cpp -- |
---|
| 8 | // |
---|
| 9 | // Author : Aaron B. Moss |
---|
| 10 | // Created On : Wed May 15 17:00:00 2019 |
---|
[312029a] | 11 | // Last Modified By : Peter A. Buhr |
---|
[d76f32c] | 12 | // Created On : Thr Jun 13 13:38:00 2019 |
---|
[312029a] | 13 | // Update Count : 6 |
---|
[54e41b3] | 14 | // |
---|
| 15 | |
---|
| 16 | #include "Expr.hpp" |
---|
| 17 | |
---|
| 18 | #include <cassert> // for strict_dynamic_cast |
---|
| 19 | #include <string> // for to_string |
---|
| 20 | #include <vector> |
---|
| 21 | |
---|
[2890212] | 22 | #include "Copy.hpp" // for shallowCopy |
---|
[417117e] | 23 | #include "Eval.hpp" // for call |
---|
[d8938622] | 24 | #include "GenericSubstitution.hpp" |
---|
[cf32116] | 25 | #include "LinkageSpec.hpp" |
---|
[9b4f329] | 26 | #include "Stmt.hpp" |
---|
[54e41b3] | 27 | #include "Type.hpp" |
---|
[d8938622] | 28 | #include "TypeSubstitution.hpp" |
---|
[733074e] | 29 | #include "Common/utility.h" |
---|
[54e41b3] | 30 | #include "Common/SemanticError.h" |
---|
| 31 | #include "GenPoly/Lvalue.h" // for referencesPermissable |
---|
[cf32116] | 32 | #include "InitTweak/InitTweak.h" // for getFunction, getPointerBase |
---|
[54e41b3] | 33 | #include "ResolvExpr/typeops.h" // for extractResultType |
---|
[9b4f329] | 34 | #include "Tuples/Tuples.h" // for makeTupleType |
---|
[54e41b3] | 35 | |
---|
| 36 | namespace ast { |
---|
| 37 | |
---|
[cf32116] | 38 | namespace { |
---|
| 39 | std::set<std::string> const lvalueFunctionNames = {"*?", "?[?]"}; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | // --- Expr |
---|
| 43 | bool Expr::get_lvalue() const { |
---|
| 44 | return false; |
---|
| 45 | } |
---|
| 46 | |
---|
[54e41b3] | 47 | // --- ApplicationExpr |
---|
| 48 | |
---|
[87701b6] | 49 | ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, |
---|
| 50 | std::vector<ptr<Expr>> && as ) |
---|
| 51 | : Expr( loc ), func( f ), args( std::move(as) ) { |
---|
[54e41b3] | 52 | // ensure that `ApplicationExpr` result type is `FuncExpr` |
---|
| 53 | const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() ); |
---|
| 54 | const FunctionType * fn = strict_dynamic_cast< const FunctionType * >( pt->base.get() ); |
---|
| 55 | |
---|
| 56 | result = ResolvExpr::extractResultType( fn ); |
---|
| 57 | assert( result ); |
---|
| 58 | } |
---|
| 59 | |
---|
[cf32116] | 60 | bool ApplicationExpr::get_lvalue() const { |
---|
| 61 | if ( const DeclWithType * func = InitTweak::getFunction( this ) ) { |
---|
| 62 | return func->linkage == Linkage::Intrinsic && lvalueFunctionNames.count( func->name ); |
---|
| 63 | } |
---|
| 64 | return false; |
---|
| 65 | } |
---|
| 66 | |
---|
[54e41b3] | 67 | // --- UntypedExpr |
---|
| 68 | |
---|
[490fb92e] | 69 | UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, const Expr * arg ) { |
---|
[54e41b3] | 70 | assert( arg ); |
---|
| 71 | |
---|
[417117e] | 72 | UntypedExpr * ret = call( loc, "*?", arg ); |
---|
[54e41b3] | 73 | if ( const Type * ty = arg->result ) { |
---|
| 74 | const Type * base = InitTweak::getPointerBase( ty ); |
---|
| 75 | assertf( base, "expected pointer type in dereference (type was %s)", toString( ty ).c_str() ); |
---|
| 76 | |
---|
| 77 | if ( GenPoly::referencesPermissable() ) { |
---|
| 78 | // if references are still allowed in the AST, dereference returns a reference |
---|
| 79 | ret->result = new ReferenceType{ base }; |
---|
| 80 | } else { |
---|
[87701b6] | 81 | // references have been removed, in which case dereference returns an lvalue of the |
---|
[54e41b3] | 82 | // base type |
---|
[d76c588] | 83 | ret->result = base; |
---|
[54e41b3] | 84 | } |
---|
| 85 | } |
---|
| 86 | return ret; |
---|
| 87 | } |
---|
| 88 | |
---|
[cf32116] | 89 | bool UntypedExpr::get_lvalue() const { |
---|
| 90 | std::string fname = InitTweak::getFunctionName( this ); |
---|
| 91 | return lvalueFunctionNames.count( fname ); |
---|
| 92 | } |
---|
| 93 | |
---|
[490fb92e] | 94 | UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ) { |
---|
[54e41b3] | 95 | assert( lhs && rhs ); |
---|
| 96 | |
---|
[417117e] | 97 | UntypedExpr * ret = call( loc, "?=?", lhs, rhs ); |
---|
[54e41b3] | 98 | if ( lhs->result && rhs->result ) { |
---|
| 99 | // if both expressions are typed, assumes that this assignment is a C bitwise assignment, |
---|
| 100 | // so the result is the type of the RHS |
---|
| 101 | ret->result = rhs->result; |
---|
| 102 | } |
---|
| 103 | return ret; |
---|
| 104 | } |
---|
| 105 | |
---|
[d5631b3] | 106 | // --- VariableExpr |
---|
| 107 | |
---|
| 108 | VariableExpr::VariableExpr( const CodeLocation & loc ) |
---|
| 109 | : Expr( loc ), var( nullptr ) {} |
---|
| 110 | |
---|
| 111 | VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) |
---|
| 112 | : Expr( loc ), var( v ) { |
---|
| 113 | assert( var ); |
---|
| 114 | assert( var->get_type() ); |
---|
| 115 | result = shallowCopy( var->get_type() ); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | bool VariableExpr::get_lvalue() const { |
---|
| 119 | // It isn't always an lvalue, but it is never an rvalue. |
---|
| 120 | return true; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | VariableExpr * VariableExpr::functionPointer( |
---|
| 124 | const CodeLocation & loc, const FunctionDecl * decl ) { |
---|
| 125 | // wrap usually-determined result type in a pointer |
---|
| 126 | VariableExpr * funcExpr = new VariableExpr{ loc, decl }; |
---|
| 127 | funcExpr->result = new PointerType{ funcExpr->result }; |
---|
| 128 | return funcExpr; |
---|
| 129 | } |
---|
| 130 | |
---|
[54e41b3] | 131 | // --- AddressExpr |
---|
| 132 | |
---|
| 133 | // Address expressions are typed based on the following inference rules: |
---|
| 134 | // E : lvalue T &..& (n references) |
---|
| 135 | // &E : T *&..& (n references) |
---|
| 136 | // |
---|
| 137 | // E : T &..& (m references) |
---|
| 138 | // &E : T *&..& (m-1 references) |
---|
| 139 | |
---|
| 140 | namespace { |
---|
| 141 | /// The type of the address of a type. |
---|
| 142 | /// Caller is responsible for managing returned memory |
---|
| 143 | Type * addrType( const Type * type ) { |
---|
| 144 | if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * >( type ) ) { |
---|
| 145 | return new ReferenceType{ addrType( refType->base ), refType->qualifiers }; |
---|
| 146 | } else { |
---|
| 147 | return new PointerType{ type }; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) { |
---|
| 153 | if ( arg->result ) { |
---|
[cf32116] | 154 | if ( arg->get_lvalue() ) { |
---|
[54e41b3] | 155 | // lvalue, retains all levels of reference, and gains a pointer inside the references |
---|
| 156 | Type * res = addrType( arg->result ); |
---|
| 157 | result = res; |
---|
| 158 | } else { |
---|
| 159 | // taking address of non-lvalue, must be a reference, loses one layer of reference |
---|
[87701b6] | 160 | if ( const ReferenceType * refType = |
---|
[54e41b3] | 161 | dynamic_cast< const ReferenceType * >( arg->result.get() ) ) { |
---|
| 162 | Type * res = addrType( refType->base ); |
---|
| 163 | result = res; |
---|
| 164 | } else { |
---|
[10a1225] | 165 | SemanticError( loc, arg->result.get(), |
---|
[54e41b3] | 166 | "Attempt to take address of non-lvalue expression: " ); |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | // --- LabelAddressExpr |
---|
| 173 | |
---|
| 174 | // label address always has type `void*` |
---|
[87701b6] | 175 | LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a ) |
---|
[54e41b3] | 176 | : Expr( loc, new PointerType{ new VoidType{} } ), arg( a ) {} |
---|
| 177 | |
---|
| 178 | // --- CastExpr |
---|
| 179 | |
---|
[87701b6] | 180 | CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) |
---|
[54e41b3] | 181 | : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {} |
---|
| 182 | |
---|
[cf32116] | 183 | bool CastExpr::get_lvalue() const { |
---|
| 184 | // This is actually wrong by C, but it works with our current set-up. |
---|
| 185 | return arg->get_lvalue(); |
---|
| 186 | } |
---|
| 187 | |
---|
[54e41b3] | 188 | // --- KeywordCastExpr |
---|
| 189 | |
---|
[312029a] | 190 | const char * KeywordCastExpr::targetString() const { |
---|
| 191 | return AggregateDecl::aggrString( target ); |
---|
[54e41b3] | 192 | } |
---|
| 193 | |
---|
[cf32116] | 194 | // --- UntypedMemberExpr |
---|
| 195 | |
---|
| 196 | bool UntypedMemberExpr::get_lvalue() const { |
---|
| 197 | return aggregate->get_lvalue(); |
---|
| 198 | } |
---|
| 199 | |
---|
[54e41b3] | 200 | // --- MemberExpr |
---|
| 201 | |
---|
| 202 | MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg ) |
---|
| 203 | : Expr( loc ), member( mem ), aggregate( agg ) { |
---|
| 204 | assert( member ); |
---|
| 205 | assert( aggregate ); |
---|
| 206 | assert( aggregate->result ); |
---|
| 207 | |
---|
[3e5dd913] | 208 | result = mem->get_type(); |
---|
[ae265b55] | 209 | |
---|
[335f2d8] | 210 | // substitute aggregate generic parameters into member type |
---|
[60aaa51d] | 211 | genericSubstitution( aggregate->result ).apply( result ); |
---|
[3f3bfe5a] | 212 | // ensure appropriate restrictions from aggregate type |
---|
| 213 | add_qualifiers( result, aggregate->result->qualifiers ); |
---|
[54e41b3] | 214 | } |
---|
| 215 | |
---|
[ae265b55] | 216 | MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg, |
---|
| 217 | MemberExpr::NoOpConstruction overloadSelector ) |
---|
| 218 | : Expr( loc ), member( mem ), aggregate( agg ) { |
---|
| 219 | assert( member ); |
---|
| 220 | assert( aggregate ); |
---|
| 221 | assert( aggregate->result ); |
---|
| 222 | (void) overloadSelector; |
---|
| 223 | } |
---|
| 224 | |
---|
[cf32116] | 225 | bool MemberExpr::get_lvalue() const { |
---|
| 226 | // This is actually wrong by C, but it works with our current set-up. |
---|
| 227 | return true; |
---|
| 228 | } |
---|
| 229 | |
---|
[54e41b3] | 230 | // --- ConstantExpr |
---|
| 231 | |
---|
| 232 | long long int ConstantExpr::intValue() const { |
---|
| 233 | if ( const BasicType * bty = result.as< BasicType >() ) { |
---|
| 234 | if ( bty->isInteger() ) { |
---|
[c36298d] | 235 | assert(ival); |
---|
| 236 | return ival.value(); |
---|
[54e41b3] | 237 | } |
---|
| 238 | } else if ( result.as< ZeroType >() ) { |
---|
| 239 | return 0; |
---|
| 240 | } else if ( result.as< OneType >() ) { |
---|
| 241 | return 1; |
---|
| 242 | } |
---|
| 243 | SemanticError( this, "Constant expression of non-integral type " ); |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) { |
---|
[87701b6] | 247 | return new ConstantExpr{ |
---|
[54e41b3] | 248 | loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b }; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) { |
---|
[87701b6] | 252 | return new ConstantExpr{ |
---|
[54e41b3] | 253 | loc, new BasicType{ BasicType::SignedInt }, std::to_string( i ), (unsigned long long)i }; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) { |
---|
[87701b6] | 257 | return new ConstantExpr{ |
---|
| 258 | loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), |
---|
[54e41b3] | 259 | (unsigned long long)i }; |
---|
| 260 | } |
---|
| 261 | |
---|
[b91bfde] | 262 | ConstantExpr * ConstantExpr::from_string( const CodeLocation & loc, const std::string & str ) { |
---|
| 263 | const Type * charType = new BasicType( BasicType::Char ); |
---|
| 264 | // Adjust the length of the string for the terminator. |
---|
| 265 | const Expr * strSize = from_ulong( loc, str.size() + 1 ); |
---|
| 266 | const Type * strType = new ArrayType( charType, strSize, FixedLen, StaticDim ); |
---|
| 267 | const std::string strValue = "\"" + str + "\""; |
---|
| 268 | return new ConstantExpr( loc, strType, strValue, std::nullopt ); |
---|
| 269 | } |
---|
| 270 | |
---|
[54e41b3] | 271 | ConstantExpr * ConstantExpr::null( const CodeLocation & loc, const Type * ptrType ) { |
---|
| 272 | return new ConstantExpr{ |
---|
| 273 | loc, ptrType ? ptrType : new PointerType{ new VoidType{} }, "0", (unsigned long long)0 }; |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | // --- SizeofExpr |
---|
| 277 | |
---|
| 278 | SizeofExpr::SizeofExpr( const CodeLocation & loc, const Expr * e ) |
---|
| 279 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( e ), type( nullptr ) {} |
---|
| 280 | |
---|
| 281 | SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t ) |
---|
| 282 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {} |
---|
| 283 | |
---|
| 284 | // --- AlignofExpr |
---|
| 285 | |
---|
| 286 | AlignofExpr::AlignofExpr( const CodeLocation & loc, const Expr * e ) |
---|
| 287 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( e ), type( nullptr ) {} |
---|
| 288 | |
---|
| 289 | AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t ) |
---|
| 290 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {} |
---|
| 291 | |
---|
| 292 | // --- OffsetofExpr |
---|
| 293 | |
---|
| 294 | OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem ) |
---|
| 295 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), type( ty ), member( mem ) { |
---|
| 296 | assert( type ); |
---|
| 297 | assert( member ); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | // --- OffsetPackExpr |
---|
| 301 | |
---|
| 302 | OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) |
---|
[87701b6] | 303 | : Expr( loc, new ArrayType{ |
---|
| 304 | new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim } |
---|
[54e41b3] | 305 | ), type( ty ) { |
---|
| 306 | assert( type ); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | // --- LogicalExpr |
---|
| 310 | |
---|
[87701b6] | 311 | LogicalExpr::LogicalExpr( |
---|
[54e41b3] | 312 | const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) |
---|
| 313 | : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} |
---|
| 314 | |
---|
[cf32116] | 315 | // --- CommaExpr |
---|
| 316 | bool CommaExpr::get_lvalue() const { |
---|
| 317 | // This is wrong by C, but the current implementation uses it. |
---|
| 318 | // (ex: Specialize, Lvalue and Box) |
---|
| 319 | return arg2->get_lvalue(); |
---|
| 320 | } |
---|
| 321 | |
---|
[9b4f329] | 322 | // --- ConstructorExpr |
---|
| 323 | |
---|
[10a1225] | 324 | ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) |
---|
[9b4f329] | 325 | : Expr( loc ), callExpr( call ) { |
---|
[10a1225] | 326 | // allow resolver to type a constructor used as an expression if it has the same type as its |
---|
[9b4f329] | 327 | // first argument |
---|
| 328 | assert( callExpr ); |
---|
| 329 | const Expr * arg = InitTweak::getCallArg( callExpr, 0 ); |
---|
| 330 | assert( arg ); |
---|
| 331 | result = arg->result; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | // --- CompoundLiteralExpr |
---|
| 335 | |
---|
| 336 | CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ) |
---|
| 337 | : Expr( loc ), init( i ) { |
---|
| 338 | assert( t && i ); |
---|
[d76c588] | 339 | result = t; |
---|
[9b4f329] | 340 | } |
---|
| 341 | |
---|
[cf32116] | 342 | bool CompoundLiteralExpr::get_lvalue() const { |
---|
| 343 | return true; |
---|
| 344 | } |
---|
| 345 | |
---|
[9b4f329] | 346 | // --- TupleExpr |
---|
| 347 | |
---|
| 348 | TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) |
---|
| 349 | : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {} |
---|
| 350 | |
---|
| 351 | // --- TupleIndexExpr |
---|
| 352 | |
---|
| 353 | TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ) |
---|
| 354 | : Expr( loc ), tuple( t ), index( i ) { |
---|
[10a1225] | 355 | const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result.get() ); |
---|
[9b4f329] | 356 | assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested " |
---|
| 357 | "index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); |
---|
| 358 | // like MemberExpr, TupleIndexExpr is always an lvalue |
---|
[d76c588] | 359 | result = type->types[ index ]; |
---|
[9b4f329] | 360 | } |
---|
| 361 | |
---|
[cf32116] | 362 | bool TupleIndexExpr::get_lvalue() const { |
---|
| 363 | return tuple->get_lvalue(); |
---|
| 364 | } |
---|
| 365 | |
---|
[9b4f329] | 366 | // --- TupleAssignExpr |
---|
| 367 | |
---|
[10a1225] | 368 | TupleAssignExpr::TupleAssignExpr( |
---|
| 369 | const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, |
---|
[9b4f329] | 370 | std::vector<ptr<ObjectDecl>> && tempDecls ) |
---|
| 371 | : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() { |
---|
[10a1225] | 372 | // convert internally into a StmtExpr which contains the declarations and produces the tuple of |
---|
[9b4f329] | 373 | // the assignments |
---|
| 374 | std::list<ptr<Stmt>> stmts; |
---|
| 375 | for ( const ObjectDecl * obj : tempDecls ) { |
---|
| 376 | stmts.emplace_back( new DeclStmt{ loc, obj } ); |
---|
| 377 | } |
---|
| 378 | TupleExpr * tupleExpr = new TupleExpr{ loc, std::move(assigns) }; |
---|
| 379 | assert( tupleExpr->result ); |
---|
| 380 | stmts.emplace_back( new ExprStmt{ loc, tupleExpr } ); |
---|
| 381 | stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } }; |
---|
| 382 | } |
---|
| 383 | |
---|
[0b57626] | 384 | TupleAssignExpr::TupleAssignExpr( |
---|
[20de6fb] | 385 | const CodeLocation & loc, const Type * result, const StmtExpr * s ) |
---|
| 386 | : Expr( loc, result ), stmtExpr() { |
---|
| 387 | stmtExpr = s; |
---|
| 388 | } |
---|
| 389 | |
---|
[9b4f329] | 390 | // --- StmtExpr |
---|
| 391 | |
---|
[10a1225] | 392 | StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) |
---|
[9b4f329] | 393 | : Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); } |
---|
| 394 | |
---|
| 395 | void StmtExpr::computeResult() { |
---|
| 396 | assert( stmts ); |
---|
| 397 | const std::list<ptr<Stmt>> & body = stmts->kids; |
---|
| 398 | if ( ! returnDecls.empty() ) { |
---|
[10a1225] | 399 | // prioritize return decl for result type, since if a return decl exists, then the StmtExpr |
---|
[9b4f329] | 400 | // is currently in an intermediate state where the body will always give a void result type |
---|
| 401 | result = returnDecls.front()->get_type(); |
---|
| 402 | } else if ( ! body.empty() ) { |
---|
| 403 | if ( const ExprStmt * exprStmt = body.back().as< ExprStmt >() ) { |
---|
| 404 | result = exprStmt->expr->result; |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | // ensure a result type exists |
---|
| 408 | if ( ! result ) { result = new VoidType{}; } |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | // --- UniqueExpr |
---|
| 412 | |
---|
| 413 | unsigned long long UniqueExpr::nextId = 0; |
---|
| 414 | |
---|
[10a1225] | 415 | UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) |
---|
[d76f32c] | 416 | : Expr( loc, e->result ), expr( e ), id( i ) { |
---|
[9b4f329] | 417 | assert( expr ); |
---|
[10a1225] | 418 | if ( id == -1ull ) { |
---|
| 419 | assert( nextId != -1ull ); |
---|
[9b4f329] | 420 | id = nextId++; |
---|
| 421 | } |
---|
[54e41b3] | 422 | } |
---|
| 423 | |
---|
[10a1225] | 424 | } |
---|
| 425 | |
---|
[54e41b3] | 426 | // Local Variables: // |
---|
| 427 | // tab-width: 4 // |
---|
| 428 | // mode: c++ // |
---|
| 429 | // compile-command: "make install" // |
---|
[d76f32c] | 430 | // End: // |
---|