- Timestamp:
- Oct 4, 2019, 3:07:07 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 3f3bfe5a
- Parents:
- 90ce35aa
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/Expr.cpp ¶
r90ce35aa rcf32116 10 10 // Created On : Wed May 15 17:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Created On : Thr Jun 13 13:38:00 201913 // Update Count : 212 // Created On : Thr Jun 26 12:12:00 2019 13 // Update Count : 3 14 14 // 15 15 … … 23 23 #include "Eval.hpp" // for call 24 24 #include "GenericSubstitution.hpp" 25 #include "LinkageSpec.hpp" 25 26 #include "Stmt.hpp" 26 27 #include "Type.hpp" … … 29 30 #include "Common/SemanticError.h" 30 31 #include "GenPoly/Lvalue.h" // for referencesPermissable 31 #include "InitTweak/InitTweak.h" // for get PointerBase32 #include "InitTweak/InitTweak.h" // for getFunction, getPointerBase 32 33 #include "ResolvExpr/typeops.h" // for extractResultType 33 34 #include "Tuples/Tuples.h" // for makeTupleType 34 35 35 36 namespace ast { 37 38 namespace { 39 std::set<std::string> const lvalueFunctionNames = {"*?", "?[?]"}; 40 } 41 42 // --- Expr 43 bool Expr::get_lvalue() const { 44 return false; 45 } 36 46 37 47 // --- ApplicationExpr … … 46 56 result = ResolvExpr::extractResultType( fn ); 47 57 assert( result ); 58 } 59 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; 48 65 } 49 66 … … 71 88 } 72 89 90 bool UntypedExpr::get_lvalue() const { 91 std::string fname = InitTweak::getFunctionName( this ); 92 return lvalueFunctionNames.count( fname ); 93 } 94 73 95 UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ) { 74 96 assert( lhs && rhs ); … … 106 128 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) { 107 129 if ( arg->result ) { 108 if ( arg-> result->is_lvalue() ) {130 if ( arg->get_lvalue() ) { 109 131 // lvalue, retains all levels of reference, and gains a pointer inside the references 110 132 Type * res = addrType( arg->result ); … … 137 159 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {} 138 160 161 bool CastExpr::get_lvalue() const { 162 // This is actually wrong by C, but it works with our current set-up. 163 return arg->get_lvalue(); 164 } 165 139 166 // --- KeywordCastExpr 140 167 … … 150 177 } 151 178 179 // --- UntypedMemberExpr 180 181 bool UntypedMemberExpr::get_lvalue() const { 182 return aggregate->get_lvalue(); 183 } 184 152 185 // --- MemberExpr 153 186 … … 210 243 } 211 244 245 bool MemberExpr::get_lvalue() const { 246 // This is actually wrong by C, but it works with our current set-up. 247 return true; 248 } 249 212 250 // --- VariableExpr 213 251 … … 222 260 r->qualifiers |= CV::Lvalue; 223 261 result = r; 262 } 263 264 bool VariableExpr::get_lvalue() const { 265 // It isn't always an lvalue, but it is never an rvalue. 266 return true; 224 267 } 225 268 … … 308 351 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} 309 352 353 // --- CommaExpr 354 bool CommaExpr::get_lvalue() const { 355 // This is wrong by C, but the current implementation uses it. 356 // (ex: Specialize, Lvalue and Box) 357 return arg2->get_lvalue(); 358 } 359 310 360 // --- ConstructorExpr 311 361 … … 329 379 } 330 380 381 bool CompoundLiteralExpr::get_lvalue() const { 382 return true; 383 } 384 331 385 // --- TupleExpr 332 386 … … 344 398 result = type->types[ index ]; 345 399 add_qualifiers( result, CV::Lvalue ); 400 } 401 402 bool TupleIndexExpr::get_lvalue() const { 403 return tuple->get_lvalue(); 346 404 } 347 405 -
TabularUnified src/AST/Expr.hpp ¶
r90ce35aa rcf32116 9 9 // Author : Aaron B. Moss 10 10 // Created On : Fri May 10 10:30:00 2019 11 // Last Modified By : A aron B. Moss12 // Created On : Fri May 10 10:30:00 201913 // Update Count : 111 // Last Modified By : Andrew Beach 12 // Created On : Thr Sep 26 12:51:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 187 187 188 188 Expr * set_extension( bool ex ) { extension = ex; return this; } 189 virtual bool get_lvalue() const; 189 190 190 191 virtual const Expr * accept( Visitor & v ) const override = 0; … … 203 204 ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} ); 204 205 206 bool get_lvalue() const final; 207 205 208 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 206 209 private: … … 217 220 UntypedExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} ) 218 221 : Expr( loc ), func( f ), args( std::move(as) ) {} 222 223 bool get_lvalue() const final; 219 224 220 225 /// Creates a new dereference expression … … 293 298 CastExpr( const Expr * a ) : CastExpr( a->location, a, GeneratedCast ) {} 294 299 300 bool get_lvalue() const final; 301 295 302 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 296 303 private: … … 340 347 : Expr( loc ), member( mem ), aggregate( agg ) { assert( aggregate ); } 341 348 349 bool get_lvalue() const final; 350 342 351 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 343 352 private: … … 353 362 354 363 MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg ); 364 365 bool get_lvalue() const final; 355 366 356 367 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } … … 374 385 VariableExpr( const CodeLocation & loc ); 375 386 VariableExpr( const CodeLocation & loc, const DeclWithType * v ); 387 388 bool get_lvalue() const final; 376 389 377 390 /// generates a function pointer for a given function … … 545 558 } 546 559 560 bool get_lvalue() const final; 561 547 562 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 548 563 private: … … 616 631 CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ); 617 632 633 bool get_lvalue() const final; 634 618 635 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 619 636 private: … … 671 688 672 689 TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ); 690 691 bool get_lvalue() const final; 673 692 674 693 const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
Note: See TracChangeset
for help on using the changeset viewer.