Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r5ccb10d rea6332d  
    1414//
    1515
    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
    3733
    3834Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
     
    9389}
    9490
    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 
    10191void VariableExpr::print( std::ostream &os, int indent ) const {
    10292        os << "Variable Expression: ";
     
    159149
    160150void AlignofExpr::print( std::ostream &os, int indent) const {
    161         os << "Alignof Expression on: ";
     151        os << std::string( indent, ' ' ) << "Alignof Expression on: ";
    162152
    163153        if (isType)
     
    268258
    269259void AttrExpr::print( std::ostream &os, int indent) const {
    270         os << "Attr ";
     260        os << std::string( indent, ' ' ) << "Attr ";
    271261        attr->print( os, indent + 2 );
    272262        if ( isType || expr ) {
     
    367357namespace {
    368358        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 ) ) {
    372360                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
    373361                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
     
    434422        if ( Type * type = expr->get_result() ) {
    435423                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;
    444426                }
     427                assertf( base, "expected pointer type in dereference\n" );
     428                ret->set_result( maybeClone( base ) );
    445429        }
    446430        return ret;
     
    506490
    507491void 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: ";
    509493        arg1->print(os);
    510494        os << " and ";
     
    611595CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
    612596        assert( type && initializer );
    613         type->set_lvalue( true );
    614597        set_result( type );
    615598}
Note: See TracChangeset for help on using the changeset viewer.