Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    rea6332d r5ccb10d  
    1414//
    1515
    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"
    3337
    3438Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
     
    8993}
    9094
     95VariableExpr * 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
    91101void VariableExpr::print( std::ostream &os, int indent ) const {
    92102        os << "Variable Expression: ";
     
    149159
    150160void AlignofExpr::print( std::ostream &os, int indent) const {
    151         os << std::string( indent, ' ' ) << "Alignof Expression on: ";
     161        os << "Alignof Expression on: ";
    152162
    153163        if (isType)
     
    258268
    259269void AttrExpr::print( std::ostream &os, int indent) const {
    260         os << std::string( indent, ' ' ) << "Attr ";
     270        os << "Attr ";
    261271        attr->print( os, indent + 2 );
    262272        if ( isType || expr ) {
     
    357367namespace {
    358368        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 ) ) {
    360372                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
    361373                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
     
    422434        if ( Type * type = expr->get_result() ) {
    423435                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 );
    426444                }
    427                 assertf( base, "expected pointer type in dereference\n" );
    428                 ret->set_result( maybeClone( base ) );
    429445        }
    430446        return ret;
     
    490506
    491507void 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: ";
    493509        arg1->print(os);
    494510        os << " and ";
     
    595611CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
    596612        assert( type && initializer );
     613        type->set_lvalue( true );
    597614        set_result( type );
    598615}
Note: See TracChangeset for help on using the changeset viewer.