[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
|
---|
[d76f32c] | 11 | // Last Modified By : Andrew Beach
|
---|
| 12 | // Created On : Thr Jun 13 13:38:00 2019
|
---|
| 13 | // Update Count : 2
|
---|
[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"
|
---|
[9b4f329] | 25 | #include "Stmt.hpp"
|
---|
[54e41b3] | 26 | #include "Type.hpp"
|
---|
[d8938622] | 27 | #include "TypeSubstitution.hpp"
|
---|
[733074e] | 28 | #include "Common/utility.h"
|
---|
[54e41b3] | 29 | #include "Common/SemanticError.h"
|
---|
| 30 | #include "GenPoly/Lvalue.h" // for referencesPermissable
|
---|
| 31 | #include "InitTweak/InitTweak.h" // for getPointerBase
|
---|
| 32 | #include "ResolvExpr/typeops.h" // for extractResultType
|
---|
[9b4f329] | 33 | #include "Tuples/Tuples.h" // for makeTupleType
|
---|
[54e41b3] | 34 |
|
---|
| 35 | namespace ast {
|
---|
| 36 |
|
---|
| 37 | // --- ApplicationExpr
|
---|
| 38 |
|
---|
[87701b6] | 39 | ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f,
|
---|
| 40 | std::vector<ptr<Expr>> && as )
|
---|
| 41 | : Expr( loc ), func( f ), args( std::move(as) ) {
|
---|
[54e41b3] | 42 | // ensure that `ApplicationExpr` result type is `FuncExpr`
|
---|
| 43 | const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() );
|
---|
| 44 | const FunctionType * fn = strict_dynamic_cast< const FunctionType * >( pt->base.get() );
|
---|
| 45 |
|
---|
| 46 | result = ResolvExpr::extractResultType( fn );
|
---|
| 47 | assert( result );
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | // --- UntypedExpr
|
---|
| 51 |
|
---|
| 52 | UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, Expr * arg ) {
|
---|
| 53 | assert( arg );
|
---|
| 54 |
|
---|
[417117e] | 55 | UntypedExpr * ret = call( loc, "*?", arg );
|
---|
[54e41b3] | 56 | if ( const Type * ty = arg->result ) {
|
---|
| 57 | const Type * base = InitTweak::getPointerBase( ty );
|
---|
| 58 | assertf( base, "expected pointer type in dereference (type was %s)", toString( ty ).c_str() );
|
---|
| 59 |
|
---|
| 60 | if ( GenPoly::referencesPermissable() ) {
|
---|
| 61 | // if references are still allowed in the AST, dereference returns a reference
|
---|
| 62 | ret->result = new ReferenceType{ base };
|
---|
| 63 | } else {
|
---|
[87701b6] | 64 | // references have been removed, in which case dereference returns an lvalue of the
|
---|
[54e41b3] | 65 | // base type
|
---|
[d76c588] | 66 | ret->result = base;
|
---|
[ee574a2] | 67 | add_qualifiers( ret->result, CV::Lvalue );
|
---|
[54e41b3] | 68 | }
|
---|
| 69 | }
|
---|
| 70 | return ret;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ) {
|
---|
| 74 | assert( lhs && rhs );
|
---|
| 75 |
|
---|
[417117e] | 76 | UntypedExpr * ret = call( loc, "?=?", lhs, rhs );
|
---|
[54e41b3] | 77 | if ( lhs->result && rhs->result ) {
|
---|
| 78 | // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
|
---|
| 79 | // so the result is the type of the RHS
|
---|
| 80 | ret->result = rhs->result;
|
---|
| 81 | }
|
---|
| 82 | return ret;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | // --- AddressExpr
|
---|
| 86 |
|
---|
| 87 | // Address expressions are typed based on the following inference rules:
|
---|
| 88 | // E : lvalue T &..& (n references)
|
---|
| 89 | // &E : T *&..& (n references)
|
---|
| 90 | //
|
---|
| 91 | // E : T &..& (m references)
|
---|
| 92 | // &E : T *&..& (m-1 references)
|
---|
| 93 |
|
---|
| 94 | namespace {
|
---|
| 95 | /// The type of the address of a type.
|
---|
| 96 | /// Caller is responsible for managing returned memory
|
---|
| 97 | Type * addrType( const Type * type ) {
|
---|
| 98 | if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * >( type ) ) {
|
---|
| 99 | return new ReferenceType{ addrType( refType->base ), refType->qualifiers };
|
---|
| 100 | } else {
|
---|
| 101 | return new PointerType{ type };
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) {
|
---|
| 107 | if ( arg->result ) {
|
---|
| 108 | if ( arg->result->is_lvalue() ) {
|
---|
| 109 | // lvalue, retains all levels of reference, and gains a pointer inside the references
|
---|
| 110 | Type * res = addrType( arg->result );
|
---|
| 111 | res->set_lvalue( false ); // result of & is never an lvalue
|
---|
| 112 | result = res;
|
---|
| 113 | } else {
|
---|
| 114 | // taking address of non-lvalue, must be a reference, loses one layer of reference
|
---|
[87701b6] | 115 | if ( const ReferenceType * refType =
|
---|
[54e41b3] | 116 | dynamic_cast< const ReferenceType * >( arg->result.get() ) ) {
|
---|
| 117 | Type * res = addrType( refType->base );
|
---|
| 118 | res->set_lvalue( false ); // result of & is never an lvalue
|
---|
| 119 | result = res;
|
---|
| 120 | } else {
|
---|
[10a1225] | 121 | SemanticError( loc, arg->result.get(),
|
---|
[54e41b3] | 122 | "Attempt to take address of non-lvalue expression: " );
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | // --- LabelAddressExpr
|
---|
| 129 |
|
---|
| 130 | // label address always has type `void*`
|
---|
[87701b6] | 131 | LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a )
|
---|
[54e41b3] | 132 | : Expr( loc, new PointerType{ new VoidType{} } ), arg( a ) {}
|
---|
| 133 |
|
---|
| 134 | // --- CastExpr
|
---|
| 135 |
|
---|
[87701b6] | 136 | CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g )
|
---|
[54e41b3] | 137 | : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {}
|
---|
| 138 |
|
---|
| 139 | // --- KeywordCastExpr
|
---|
| 140 |
|
---|
| 141 | const std::string & KeywordCastExpr::targetString() const {
|
---|
| 142 | static const std::string targetStrs[] = {
|
---|
| 143 | "coroutine", "thread", "monitor"
|
---|
| 144 | };
|
---|
| 145 | static_assert(
|
---|
| 146 | (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
|
---|
| 147 | "Each KeywordCastExpr::Target should have a corresponding string representation"
|
---|
| 148 | );
|
---|
| 149 | return targetStrs[(unsigned long)target];
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | // --- MemberExpr
|
---|
| 153 |
|
---|
| 154 | MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg )
|
---|
| 155 | : Expr( loc ), member( mem ), aggregate( agg ) {
|
---|
| 156 | assert( member );
|
---|
| 157 | assert( aggregate );
|
---|
| 158 | assert( aggregate->result );
|
---|
| 159 |
|
---|
[ae265b55] | 160 | // Deep copy on result type avoids mutation on transitively multiply referenced object.
|
---|
| 161 | //
|
---|
| 162 | // Example, adapted from parts of builtins and bootloader:
|
---|
| 163 | //
|
---|
| 164 | // forall(dtype T)
|
---|
| 165 | // struct __Destructor {
|
---|
| 166 | // T * object;
|
---|
| 167 | // void (*dtor)(T *);
|
---|
| 168 | // };
|
---|
| 169 | //
|
---|
| 170 | // forall(dtype S)
|
---|
| 171 | // void foo(__Destructor(S) &d) {
|
---|
| 172 | // if (d.dtor) { // here
|
---|
| 173 | // }
|
---|
| 174 | // }
|
---|
| 175 | //
|
---|
| 176 | // Let e be the "d.dtor" guard espression, which is MemberExpr after resolve. Let d be the
|
---|
| 177 | // declaration of member __Destructor.dtor (an ObjectDecl), as accessed via the top-level
|
---|
| 178 | // declaration of __Destructor. Consider the types e.result and d.type. In the old AST, one
|
---|
| 179 | // is a clone of the other. Ordinary new-AST use would set them up as a multiply-referenced
|
---|
| 180 | // object.
|
---|
| 181 | //
|
---|
| 182 | // e.result: PointerType
|
---|
| 183 | // .base: FunctionType
|
---|
| 184 | // .params.front(): ObjectDecl, the anonymous parameter of type T*
|
---|
| 185 | // .type: PointerType
|
---|
| 186 | // .base: TypeInstType
|
---|
| 187 | // let x = that
|
---|
| 188 | // let y = similar, except start from d.type
|
---|
| 189 | //
|
---|
| 190 | // Consider two code lines down, genericSubstitution(...).apply(result).
|
---|
| 191 | //
|
---|
| 192 | // Applying this chosen-candidate's type substitution means modifying x, substituting
|
---|
| 193 | // S for T. This mutation should affect x and not y.
|
---|
| 194 |
|
---|
| 195 | result = deepCopy(mem->get_type());
|
---|
| 196 |
|
---|
[335f2d8] | 197 | // substitute aggregate generic parameters into member type
|
---|
[60aaa51d] | 198 | genericSubstitution( aggregate->result ).apply( result );
|
---|
[335f2d8] | 199 | // ensure lvalue and appropriate restrictions from aggregate type
|
---|
[ee574a2] | 200 | add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue );
|
---|
[54e41b3] | 201 | }
|
---|
| 202 |
|
---|
[ae265b55] | 203 | MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg,
|
---|
| 204 | MemberExpr::NoOpConstruction overloadSelector )
|
---|
| 205 | : Expr( loc ), member( mem ), aggregate( agg ) {
|
---|
| 206 | assert( member );
|
---|
| 207 | assert( aggregate );
|
---|
| 208 | assert( aggregate->result );
|
---|
| 209 | (void) overloadSelector;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[54e41b3] | 212 | // --- VariableExpr
|
---|
| 213 |
|
---|
[546e712] | 214 | VariableExpr::VariableExpr( const CodeLocation & loc )
|
---|
| 215 | : Expr( loc ), var( nullptr ) {}
|
---|
| 216 |
|
---|
[54e41b3] | 217 | VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v )
|
---|
| 218 | : Expr( loc ), var( v ) {
|
---|
| 219 | assert( var );
|
---|
| 220 | assert( var->get_type() );
|
---|
[2890212] | 221 | auto r = shallowCopy( var->get_type() );
|
---|
| 222 | r->qualifiers |= CV::Lvalue;
|
---|
| 223 | result = r;
|
---|
[54e41b3] | 224 | }
|
---|
| 225 |
|
---|
[87701b6] | 226 | VariableExpr * VariableExpr::functionPointer(
|
---|
[54e41b3] | 227 | const CodeLocation & loc, const FunctionDecl * decl ) {
|
---|
| 228 | // wrap usually-determined result type in a pointer
|
---|
| 229 | VariableExpr * funcExpr = new VariableExpr{ loc, decl };
|
---|
| 230 | funcExpr->result = new PointerType{ funcExpr->result };
|
---|
| 231 | return funcExpr;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | // --- ConstantExpr
|
---|
| 235 |
|
---|
| 236 | long long int ConstantExpr::intValue() const {
|
---|
| 237 | if ( const BasicType * bty = result.as< BasicType >() ) {
|
---|
| 238 | if ( bty->isInteger() ) {
|
---|
[c36298d] | 239 | assert(ival);
|
---|
| 240 | return ival.value();
|
---|
[54e41b3] | 241 | }
|
---|
| 242 | } else if ( result.as< ZeroType >() ) {
|
---|
| 243 | return 0;
|
---|
| 244 | } else if ( result.as< OneType >() ) {
|
---|
| 245 | return 1;
|
---|
| 246 | }
|
---|
| 247 | SemanticError( this, "Constant expression of non-integral type " );
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) {
|
---|
[87701b6] | 251 | return new ConstantExpr{
|
---|
[54e41b3] | 252 | loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b };
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) {
|
---|
[87701b6] | 256 | return new ConstantExpr{
|
---|
[54e41b3] | 257 | loc, new BasicType{ BasicType::SignedInt }, std::to_string( i ), (unsigned long long)i };
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) {
|
---|
[87701b6] | 261 | return new ConstantExpr{
|
---|
| 262 | loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ),
|
---|
[54e41b3] | 263 | (unsigned long long)i };
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | ConstantExpr * ConstantExpr::null( const CodeLocation & loc, const Type * ptrType ) {
|
---|
| 267 | return new ConstantExpr{
|
---|
| 268 | loc, ptrType ? ptrType : new PointerType{ new VoidType{} }, "0", (unsigned long long)0 };
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | // --- SizeofExpr
|
---|
| 272 |
|
---|
| 273 | SizeofExpr::SizeofExpr( const CodeLocation & loc, const Expr * e )
|
---|
| 274 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
|
---|
| 275 |
|
---|
| 276 | SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t )
|
---|
| 277 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
|
---|
| 278 |
|
---|
| 279 | // --- AlignofExpr
|
---|
| 280 |
|
---|
| 281 | AlignofExpr::AlignofExpr( const CodeLocation & loc, const Expr * e )
|
---|
| 282 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
|
---|
| 283 |
|
---|
| 284 | AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t )
|
---|
| 285 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
|
---|
| 286 |
|
---|
| 287 | // --- OffsetofExpr
|
---|
| 288 |
|
---|
| 289 | OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem )
|
---|
| 290 | : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), type( ty ), member( mem ) {
|
---|
| 291 | assert( type );
|
---|
| 292 | assert( member );
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | // --- OffsetPackExpr
|
---|
| 296 |
|
---|
| 297 | OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty )
|
---|
[87701b6] | 298 | : Expr( loc, new ArrayType{
|
---|
| 299 | new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim }
|
---|
[54e41b3] | 300 | ), type( ty ) {
|
---|
| 301 | assert( type );
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | // --- LogicalExpr
|
---|
| 305 |
|
---|
[87701b6] | 306 | LogicalExpr::LogicalExpr(
|
---|
[54e41b3] | 307 | const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia )
|
---|
| 308 | : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
|
---|
| 309 |
|
---|
[9b4f329] | 310 | // --- ConstructorExpr
|
---|
| 311 |
|
---|
[10a1225] | 312 | ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call )
|
---|
[9b4f329] | 313 | : Expr( loc ), callExpr( call ) {
|
---|
[10a1225] | 314 | // allow resolver to type a constructor used as an expression if it has the same type as its
|
---|
[9b4f329] | 315 | // first argument
|
---|
| 316 | assert( callExpr );
|
---|
| 317 | const Expr * arg = InitTweak::getCallArg( callExpr, 0 );
|
---|
| 318 | assert( arg );
|
---|
| 319 | result = arg->result;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | // --- CompoundLiteralExpr
|
---|
| 323 |
|
---|
| 324 | CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i )
|
---|
| 325 | : Expr( loc ), init( i ) {
|
---|
| 326 | assert( t && i );
|
---|
[d76c588] | 327 | result = t;
|
---|
[ee574a2] | 328 | add_qualifiers( result, CV::Lvalue );
|
---|
[9b4f329] | 329 | }
|
---|
| 330 |
|
---|
| 331 | // --- TupleExpr
|
---|
| 332 |
|
---|
| 333 | TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs )
|
---|
| 334 | : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {}
|
---|
| 335 |
|
---|
| 336 | // --- TupleIndexExpr
|
---|
| 337 |
|
---|
| 338 | TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i )
|
---|
| 339 | : Expr( loc ), tuple( t ), index( i ) {
|
---|
[10a1225] | 340 | const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result.get() );
|
---|
[9b4f329] | 341 | assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested "
|
---|
| 342 | "index %d in expr %s", type->size(), index, toString( tuple ).c_str() );
|
---|
| 343 | // like MemberExpr, TupleIndexExpr is always an lvalue
|
---|
[d76c588] | 344 | result = type->types[ index ];
|
---|
[ee574a2] | 345 | add_qualifiers( result, CV::Lvalue );
|
---|
[9b4f329] | 346 | }
|
---|
| 347 |
|
---|
| 348 | // --- TupleAssignExpr
|
---|
| 349 |
|
---|
[10a1225] | 350 | TupleAssignExpr::TupleAssignExpr(
|
---|
| 351 | const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
|
---|
[9b4f329] | 352 | std::vector<ptr<ObjectDecl>> && tempDecls )
|
---|
| 353 | : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() {
|
---|
[10a1225] | 354 | // convert internally into a StmtExpr which contains the declarations and produces the tuple of
|
---|
[9b4f329] | 355 | // the assignments
|
---|
| 356 | std::list<ptr<Stmt>> stmts;
|
---|
| 357 | for ( const ObjectDecl * obj : tempDecls ) {
|
---|
| 358 | stmts.emplace_back( new DeclStmt{ loc, obj } );
|
---|
| 359 | }
|
---|
| 360 | TupleExpr * tupleExpr = new TupleExpr{ loc, std::move(assigns) };
|
---|
| 361 | assert( tupleExpr->result );
|
---|
| 362 | stmts.emplace_back( new ExprStmt{ loc, tupleExpr } );
|
---|
| 363 | stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } };
|
---|
| 364 | }
|
---|
| 365 |
|
---|
[0b57626] | 366 | TupleAssignExpr::TupleAssignExpr(
|
---|
[20de6fb] | 367 | const CodeLocation & loc, const Type * result, const StmtExpr * s )
|
---|
| 368 | : Expr( loc, result ), stmtExpr() {
|
---|
| 369 | stmtExpr = s;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
[9b4f329] | 372 | // --- StmtExpr
|
---|
| 373 |
|
---|
[10a1225] | 374 | StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss )
|
---|
[9b4f329] | 375 | : Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); }
|
---|
| 376 |
|
---|
| 377 | void StmtExpr::computeResult() {
|
---|
| 378 | assert( stmts );
|
---|
| 379 | const std::list<ptr<Stmt>> & body = stmts->kids;
|
---|
| 380 | if ( ! returnDecls.empty() ) {
|
---|
[10a1225] | 381 | // prioritize return decl for result type, since if a return decl exists, then the StmtExpr
|
---|
[9b4f329] | 382 | // is currently in an intermediate state where the body will always give a void result type
|
---|
| 383 | result = returnDecls.front()->get_type();
|
---|
| 384 | } else if ( ! body.empty() ) {
|
---|
| 385 | if ( const ExprStmt * exprStmt = body.back().as< ExprStmt >() ) {
|
---|
| 386 | result = exprStmt->expr->result;
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 | // ensure a result type exists
|
---|
| 390 | if ( ! result ) { result = new VoidType{}; }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | // --- UniqueExpr
|
---|
| 394 |
|
---|
| 395 | unsigned long long UniqueExpr::nextId = 0;
|
---|
| 396 |
|
---|
[10a1225] | 397 | UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i )
|
---|
[d76f32c] | 398 | : Expr( loc, e->result ), expr( e ), id( i ) {
|
---|
[9b4f329] | 399 | assert( expr );
|
---|
[10a1225] | 400 | if ( id == -1ull ) {
|
---|
| 401 | assert( nextId != -1ull );
|
---|
[9b4f329] | 402 | id = nextId++;
|
---|
| 403 | }
|
---|
[54e41b3] | 404 | }
|
---|
| 405 |
|
---|
[10a1225] | 406 | }
|
---|
| 407 |
|
---|
[54e41b3] | 408 | // Local Variables: //
|
---|
| 409 | // tab-width: 4 //
|
---|
| 410 | // mode: c++ //
|
---|
| 411 | // compile-command: "make install" //
|
---|
[d76f32c] | 412 | // End: //
|
---|