Changes in src/SynTree/Expression.cc [5ccb10d:ea6332d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r5ccb10d rea6332d 14 14 // 15 15 16 #include <iostream> 17 #include <cassert> 18 #include <list> 19 #include <algorithm> 20 21 #include <iterator> 22 23 #include "Declaration.h" 24 #include "Expression.h" 25 #include "Initializer.h" 26 #include "Statement.h" 27 #include "Type.h" 28 #include "TypeSubstitution.h" 29 #include "VarExprReplacer.h" 30 31 #include "Common/utility.h" 32 #include "Common/PassVisitor.h" 33 34 #include "InitTweak/InitTweak.h" 35 36 #include "GenPoly/Lvalue.h" 16 #include "SynTree/Expression.h" 17 18 #include <cassert> // for assert, assertf 19 #include <iostream> // for ostream, operator<<, basic_ostream 20 #include <list> // for list, _List_iterator, list<>::co... 21 22 #include "Common/utility.h" // for maybeClone, cloneAll, deleteAll 23 #include "Declaration.h" // for ObjectDecl, DeclarationWithType 24 #include "Expression.h" // for Expression, ImplicitCopyCtorExpr 25 #include "InitTweak/InitTweak.h" // for getCallArg, getPointerBase 26 #include "Initializer.h" // for Designation, Initializer 27 #include "Statement.h" // for CompoundStmt, ExprStmt, Statement 28 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode 29 #include "SynTree/Constant.h" // for Constant 30 #include "Type.h" // for Type, BasicType, Type::Qualifiers 31 #include "TypeSubstitution.h" // for TypeSubstitution 32 37 33 38 34 Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {} … … 93 89 } 94 90 95 VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) {96 VariableExpr * funcExpr = new VariableExpr( func );97 funcExpr->set_result( new PointerType( Type::Qualifiers(), funcExpr->get_result() ) );98 return funcExpr;99 }100 101 91 void VariableExpr::print( std::ostream &os, int indent ) const { 102 92 os << "Variable Expression: "; … … 159 149 160 150 void AlignofExpr::print( std::ostream &os, int indent) const { 161 os << "Alignof Expression on: ";151 os << std::string( indent, ' ' ) << "Alignof Expression on: "; 162 152 163 153 if (isType) … … 268 258 269 259 void AttrExpr::print( std::ostream &os, int indent) const { 270 os << "Attr ";260 os << std::string( indent, ' ' ) << "Attr "; 271 261 attr->print( os, indent + 2 ); 272 262 if ( isType || expr ) { … … 367 357 namespace { 368 358 TypeSubstitution makeSub( Type * t ) { 369 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) { 370 return makeSub( refType->get_base() ); 371 } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) { 359 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) { 372 360 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() ); 373 361 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) { … … 434 422 if ( Type * type = expr->get_result() ) { 435 423 Type * base = InitTweak::getPointerBase( type ); 436 assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() ); 437 ret->set_result( base->clone() ); 438 if ( GenPoly::referencesPermissable() ) { 439 // if references are still allowed in the AST, dereference returns a reference 440 ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) ); 441 } else { 442 // references have been removed, in which case dereference returns an lvalue of the base type. 443 ret->get_result()->set_lvalue( true ); 424 if ( ! base ) { 425 std::cerr << type << std::endl; 444 426 } 427 assertf( base, "expected pointer type in dereference\n" ); 428 ret->set_result( maybeClone( base ) ); 445 429 } 446 430 return ret; … … 506 490 507 491 void LogicalExpr::print( std::ostream &os, int indent )const { 508 os << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";492 os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 509 493 arg1->print(os); 510 494 os << " and "; … … 611 595 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) { 612 596 assert( type && initializer ); 613 type->set_lvalue( true );614 597 set_result( type ); 615 598 }
Note:
See TracChangeset
for help on using the changeset viewer.