Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r312029a r5d00425  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 11 07:55:15 2019
    13 // Update Count     : 70
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 15 13:43:00 2019
     13// Update Count     : 64
    1414//
    1515
     
    1919#include <iostream>                  // for ostream, operator<<, basic_ostream
    2020#include <list>                      // for list, _List_iterator, list<>::co...
    21 #include <set>                       // for set
    2221
    2322#include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
     23#include "Declaration.h"             // for ObjectDecl, DeclarationWithType
    2424#include "Expression.h"              // for Expression, ImplicitCopyCtorExpr
    2525#include "InitTweak/InitTweak.h"     // for getCallArg, getPointerBase
     
    6464
    6565bool Expression::get_lvalue() const {
     66        assert( !result->get_lvalue() );
    6667        return false;
    6768}
     
    114115        assert( var->get_type() );
    115116        Type * type = var->get_type()->clone();
     117        type->set_lvalue( true );
    116118
    117119        // xxx - doesn't quite work yet - get different alternatives with the same cost
     
    123125        //      long long int value;
    124126        //      if ( decl->valueOf( var, value ) ) {
    125         //              type->set_lvalue( false ); // Would have to move to get_lvalue.
     127        //              type->set_lvalue( false );
    126128        //      }
    127129        // }
     
    138140
    139141bool VariableExpr::get_lvalue() const {
    140         // It isn't always an lvalue, but it is never an rvalue.
    141         return true;
     142        return result->get_lvalue();
    142143}
    143144
     
    276277
    277278bool CastExpr::get_lvalue() const {
    278         // This is actually wrong by C, but it works with our current set-up.
    279         return arg->get_lvalue();
     279        return result->get_lvalue();
    280280}
    281281
     
    293293}
    294294
    295 KeywordCastExpr::KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ) : Expression(), arg(arg), target( target ) {
     295KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) {
    296296}
    297297
     
    303303}
    304304
    305 const char * KeywordCastExpr::targetString() const {
    306         return AggregateDecl::aggrString( target );
     305const std::string & KeywordCastExpr::targetString() const {
     306        static const std::string targetStrs[] = {
     307                "coroutine", "thread", "monitor"
     308        };
     309        static_assert(
     310                (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
     311                "Each KeywordCastExpr::Target should have a corresponding string representation"
     312        );
     313        return targetStrs[(unsigned long)target];
    307314}
    308315
     
    353360}
    354361
    355 bool UntypedMemberExpr::get_lvalue() const {
    356         return aggregate->get_lvalue();
    357 }
    358 
    359362void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const {
    360363        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
     
    375378        sub.apply( res );
    376379        result = res;
     380        result->set_lvalue( true );
    377381        result->get_qualifiers() |= aggregate->result->get_qualifiers();
    378382}
     
    388392
    389393bool MemberExpr::get_lvalue() const {
    390         // This is actually wrong by C, but it works with our current set-up.
     394        assert( result->get_lvalue() );
    391395        return true;
    392396}
     
    423427                        // if references are still allowed in the AST, dereference returns a reference
    424428                        ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) );
     429                } else {
     430                        // references have been removed, in which case dereference returns an lvalue of the base type.
     431                        ret->result->set_lvalue( true );
    425432                }
    426433        }
     
    440447
    441448bool UntypedExpr::get_lvalue() const {
    442         // from src/GenPoly/Lvalue.cc: isIntrinsicReference
    443         static std::set<std::string> lvalueFunctions = { "*?", "?[?]" };
    444         std::string fname = InitTweak::getFunctionName( const_cast< UntypedExpr * >( this ) );
    445         return lvalueFunctions.count(fname);
     449        return result->get_lvalue();
    446450}
    447451
     
    506510
    507511bool ConditionalExpr::get_lvalue() const {
    508         return false;
     512        return result->get_lvalue();
    509513}
    510514
     
    519523}
    520524
    521 AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( other.inout ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
     525AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
    522526
    523527
    524528void AsmExpr::print( std::ostream & os, Indenter indent ) const {
    525529        os << "Asm Expression: " << std::endl;
    526         if ( !inout.empty() ) os <<  "[" << inout << "] ";
     530        if ( inout ) inout->print( os, indent+1 );
    527531        if ( constraint ) constraint->print( os, indent+1 );
    528532        if ( operand ) operand->print( os, indent+1 );
     
    566570
    567571bool ConstructorExpr::get_lvalue() const {
    568         return false;
     572        return result->get_lvalue();
    569573}
    570574
     
    578582CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
    579583        assert( type && initializer );
     584        type->set_lvalue( true );
    580585        set_result( type );
    581586}
     
    588593
    589594bool CompoundLiteralExpr::get_lvalue() const {
     595        assert( result->get_lvalue() );
    590596        return true;
    591597}
     
    642648}
    643649bool StmtExpr::get_lvalue() const {
    644         return false;
     650        return result->get_lvalue();
    645651}
    646652void StmtExpr::print( std::ostream & os, Indenter indent ) const {
Note: See TracChangeset for help on using the changeset viewer.