Changes in src/SynTree/Expression.cc [ea6332d:5ccb10d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
rea6332d r5ccb10d 14 14 // 15 15 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 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" 33 37 34 38 Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {} … … 89 93 } 90 94 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 91 101 void VariableExpr::print( std::ostream &os, int indent ) const { 92 102 os << "Variable Expression: "; … … 149 159 150 160 void AlignofExpr::print( std::ostream &os, int indent) const { 151 os << std::string( indent, ' ' ) <<"Alignof Expression on: ";161 os << "Alignof Expression on: "; 152 162 153 163 if (isType) … … 258 268 259 269 void AttrExpr::print( std::ostream &os, int indent) const { 260 os << std::string( indent, ' ' ) <<"Attr ";270 os << "Attr "; 261 271 attr->print( os, indent + 2 ); 262 272 if ( isType || expr ) { … … 357 367 namespace { 358 368 TypeSubstitution makeSub( Type * t ) { 359 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) { 369 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) { 370 return makeSub( refType->get_base() ); 371 } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) { 360 372 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() ); 361 373 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) { … … 422 434 if ( Type * type = expr->get_result() ) { 423 435 Type * base = InitTweak::getPointerBase( type ); 424 if ( ! base ) { 425 std::cerr << type << std::endl; 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 ); 426 444 } 427 assertf( base, "expected pointer type in dereference\n" );428 ret->set_result( maybeClone( base ) );429 445 } 430 446 return ret; … … 490 506 491 507 void LogicalExpr::print( std::ostream &os, int indent )const { 492 os << std::string( indent, ' ' ) <<"Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";508 os << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 493 509 arg1->print(os); 494 510 os << " and "; … … 595 611 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) { 596 612 assert( type && initializer ); 613 type->set_lvalue( true ); 597 614 set_result( type ); 598 615 }
Note:
See TracChangeset
for help on using the changeset viewer.