Changes in src/AST/Expr.cpp [3e5dd913:312029a]
- File:
-
- 1 edited
-
src/AST/Expr.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r3e5dd913 r312029a 20 20 #include <vector> 21 21 22 #include "Copy.hpp" // for shallowCopy23 #include "Eval.hpp" // for call24 22 #include "GenericSubstitution.hpp" 25 #include "LinkageSpec.hpp"26 23 #include "Stmt.hpp" 27 24 #include "Type.hpp" … … 30 27 #include "Common/SemanticError.h" 31 28 #include "GenPoly/Lvalue.h" // for referencesPermissable 32 #include "InitTweak/InitTweak.h" // for get Function, getPointerBase29 #include "InitTweak/InitTweak.h" // for getPointerBase 33 30 #include "ResolvExpr/typeops.h" // for extractResultType 34 31 #include "Tuples/Tuples.h" // for makeTupleType 35 32 36 33 namespace ast { 37 38 namespace {39 std::set<std::string> const lvalueFunctionNames = {"*?", "?[?]"};40 }41 42 // --- Expr43 bool Expr::get_lvalue() const {44 return false;45 }46 34 47 35 // --- ApplicationExpr … … 58 46 } 59 47 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 67 48 // --- UntypedExpr 68 49 69 UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, constExpr * arg ) {50 UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, Expr * arg ) { 70 51 assert( arg ); 71 52 72 UntypedExpr * ret = call( loc, "*?", arg ); 53 UntypedExpr * ret = new UntypedExpr{ 54 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 55 }; 73 56 if ( const Type * ty = arg->result ) { 74 57 const Type * base = InitTweak::getPointerBase( ty ); … … 82 65 // base type 83 66 ret->result = base; 67 add_qualifiers( ret->result, CV::Lvalue ); 84 68 } 85 69 } … … 87 71 } 88 72 89 bool UntypedExpr::get_lvalue() const { 90 std::string fname = InitTweak::getFunctionName( this ); 91 return lvalueFunctionNames.count( fname ); 92 } 93 94 UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ) { 73 UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ) { 95 74 assert( lhs && rhs ); 96 75 97 UntypedExpr * ret = call( loc, "?=?", lhs, rhs ); 76 UntypedExpr * ret = new UntypedExpr{ 77 loc, new NameExpr{loc, "?=?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ lhs }, ptr<Expr>{ rhs } } 78 }; 98 79 if ( lhs->result && rhs->result ) { 99 80 // if both expressions are typed, assumes that this assignment is a C bitwise assignment, … … 102 83 } 103 84 return ret; 104 }105 106 // --- VariableExpr107 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 pointer126 VariableExpr * funcExpr = new VariableExpr{ loc, decl };127 funcExpr->result = new PointerType{ funcExpr->result };128 return funcExpr;129 85 } 130 86 … … 152 108 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) { 153 109 if ( arg->result ) { 154 if ( arg-> get_lvalue() ) {110 if ( arg->result->is_lvalue() ) { 155 111 // lvalue, retains all levels of reference, and gains a pointer inside the references 156 112 Type * res = addrType( arg->result ); 113 res->set_lvalue( false ); // result of & is never an lvalue 157 114 result = res; 158 115 } else { … … 161 118 dynamic_cast< const ReferenceType * >( arg->result.get() ) ) { 162 119 Type * res = addrType( refType->base ); 120 res->set_lvalue( false ); // result of & is never an lvalue 163 121 result = res; 164 122 } else { … … 181 139 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {} 182 140 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 188 141 // --- KeywordCastExpr 189 142 190 143 const char * KeywordCastExpr::targetString() const { 191 144 return AggregateDecl::aggrString( target ); 192 }193 194 // --- UntypedMemberExpr195 196 bool UntypedMemberExpr::get_lvalue() const {197 return aggregate->get_lvalue();198 145 } 199 146 … … 206 153 assert( aggregate->result ); 207 154 155 // take ownership of member type 208 156 result = mem->get_type(); 209 210 157 // substitute aggregate generic parameters into member type 211 158 genericSubstitution( aggregate->result ).apply( result ); 212 // ensure appropriate restrictions from aggregate type 213 add_qualifiers( result, aggregate->result->qualifiers ); 214 } 215 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 225 bool MemberExpr::get_lvalue() const { 226 // This is actually wrong by C, but it works with our current set-up. 227 return true; 159 // ensure lvalue and appropriate restrictions from aggregate type 160 add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue ); 161 } 162 163 // --- VariableExpr 164 165 VariableExpr::VariableExpr( const CodeLocation & loc ) 166 : Expr( loc ), var( nullptr ) {} 167 168 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) 169 : Expr( loc ), var( v ) { 170 assert( var ); 171 assert( var->get_type() ); 172 result = var->get_type(); 173 add_qualifiers( result, CV::Lvalue ); 174 } 175 176 VariableExpr * VariableExpr::functionPointer( 177 const CodeLocation & loc, const FunctionDecl * decl ) { 178 // wrap usually-determined result type in a pointer 179 VariableExpr * funcExpr = new VariableExpr{ loc, decl }; 180 funcExpr->result = new PointerType{ funcExpr->result }; 181 return funcExpr; 228 182 } 229 183 … … 303 257 const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) 304 258 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} 305 306 // --- CommaExpr307 bool CommaExpr::get_lvalue() const {308 // This is wrong by C, but the current implementation uses it.309 // (ex: Specialize, Lvalue and Box)310 return arg2->get_lvalue();311 }312 259 313 260 // --- ConstructorExpr … … 329 276 assert( t && i ); 330 277 result = t; 331 } 332 333 bool CompoundLiteralExpr::get_lvalue() const { 334 return true; 278 add_qualifiers( result, CV::Lvalue ); 335 279 } 336 280 … … 349 293 // like MemberExpr, TupleIndexExpr is always an lvalue 350 294 result = type->types[ index ]; 351 } 352 353 bool TupleIndexExpr::get_lvalue() const { 354 return tuple->get_lvalue(); 295 add_qualifiers( result, CV::Lvalue ); 355 296 } 356 297
Note:
See TracChangeset
for help on using the changeset viewer.