Ignore:
Timestamp:
Nov 29, 2016, 3:30:59 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8e5724e
Parents:
3a2128f (diff), 9129a84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

Conflicts:

src/Parser/parser.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r3a2128f r1f44196  
    3131
    3232
    33 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {}
    34 
    35 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    36         cloneAll( other.results, results );
     33Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
     34
     35Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    3736}
    3837
     
    4039        delete env;
    4140        delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
    42         deleteAll( results );
    43 }
    44 
    45 void Expression::add_result( Type *t ) {
    46         if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
    47                 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
    48         } else {
    49                 results.push_back(t);
    50         } // if
     41        delete result;
    5142}
    5243
     
    6859
    6960ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
    70         add_result( constant.get_type()->clone() );
     61        set_result( constant.get_type()->clone() );
    7162}
    7263
     
    8576        assert( var );
    8677        assert( var->get_type() );
    87         add_result( var->get_type()->clone() );
    88         for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    89                 (*i)->set_isLvalue( true );
    90         } // for
     78        Type * type = var->get_type()->clone();
     79        type->set_isLvalue( true );
     80        set_result( type );
    9181}
    9282
     
    110100SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
    111101                Expression( _aname ), expr(expr_), type(0), isType(false) {
    112         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     102        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    113103}
    114104
    115105SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
    116106                Expression( _aname ), expr(0), type(type_), isType(true) {
    117         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     107        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    118108}
    119109
     
    141131AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
    142132                Expression( _aname ), expr(expr_), type(0), isType(false) {
    143         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    144134}
    145135
    146136AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
    147137                Expression( _aname ), expr(0), type(type_), isType(true) {
    148         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     138        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    149139}
    150140
     
    172162UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
    173163                Expression( _aname ), type(type_), member(member_) {
    174         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     164        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    175165}
    176166
     
    197187OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
    198188                Expression( _aname ), type(type_), member(member_) {
    199         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     189        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    200190}
    201191
     
    229219
    230220OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
    231         add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
     221        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
    232222}
    233223
     
    284274
    285275CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
    286         add_result(toType);
     276        set_result(toType);
    287277}
    288278
    289279CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
     280        set_result( new VoidType( Type::Qualifiers() ) );
    290281}
    291282
     
    303294        arg->print(os, indent+2);
    304295        os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
    305         if ( results.empty() ) {
    306                 os << std::string( indent+2, ' ' ) << "nothing" << std::endl;
     296        os << std::string( indent+2, ' ' );
     297        if ( result->isVoid() ) {
     298                os << "nothing";
    307299        } else {
    308                 printAll(results, os, indent+2);
     300                result->print( os, indent+2 );
    309301        } // if
    310         Expression::print( os, indent );
    311 }
    312 
    313 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) :
     302        os << std::endl;
     303        Expression::print( os, indent );
     304}
     305
     306UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
    314307                Expression( _aname ), member(_member), aggregate(_aggregate) {}
    315308
    316309UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
    317                 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
     310                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
    318311}
    319312
    320313UntypedMemberExpr::~UntypedMemberExpr() {
    321314        delete aggregate;
     315        delete member;
    322316}
    323317
    324318void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
    325         os << "Untyped Member Expression, with field: " << get_member();
     319        os << "Untyped Member Expression, with field: " << std::endl;
     320        os << std::string( indent+2, ' ' );
     321        get_member()->print(os, indent+4);
     322        os << std::string( indent+2, ' ' );
    326323
    327324        Expression *agg = get_aggregate();
    328         os << ", from aggregate: ";
     325        os << "from aggregate: " << std::endl;
    329326        if (agg != 0) {
    330                 os << std::string( indent + 2, ' ' );
    331                 agg->print(os, indent + 2);
     327                os << std::string( indent + 4, ' ' );
     328                agg->print(os, indent + 4);
    332329        }
    333330        os << std::string( indent+2, ' ' );
     
    338335MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
    339336                Expression( _aname ), member(_member), aggregate(_aggregate) {
    340         add_result( member->get_type()->clone() );
    341         for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    342                 (*i)->set_isLvalue( true );
    343         } // for
     337        set_result( member->get_type()->clone() );
     338        get_result()->set_isLvalue( true );
    344339}
    345340
     
    372367}
    373368
    374 
    375 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {}
     369UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
     370                Expression( _aname ), function(_function), args(_args) {}
    376371
    377372UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
     
    380375}
    381376
    382 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :
    383                 Expression( _aname ), function(_function), args(_args) {}
    384 
    385377UntypedExpr::~UntypedExpr() {
    386378        delete function;
    387379        deleteAll( args );
    388380}
     381
     382UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
     383        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
     384        if ( Type * type = expr->get_result() ) {
     385                Type * base = InitTweak::getPointerBase( type );
     386                if ( ! base ) {
     387                        std::cerr << type << std::endl;
     388                }
     389                assertf( base, "expected pointer type in dereference\n" );
     390                ret->set_result( maybeClone( base ) );
     391        }
     392        return ret;
     393}
     394
     395UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
     396        assert( arg1 && arg2 );
     397        UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
     398        if ( arg1->get_result() && arg2->get_result() ) {
     399                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
     400                // so the result is the type of the RHS
     401                ret->set_result( arg2->get_result()->clone() );
     402        }
     403        return ret;
     404}
     405
    389406
    390407void UntypedExpr::print( std::ostream &os, int indent ) const {
     
    419436LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
    420437                Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
    421         add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     438        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    422439}
    423440
     
    454471
    455472void ConditionalExpr::print( std::ostream &os, int indent ) const {
    456         os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl;
     473        os << "Conditional expression on: " << std::endl;
     474        os << std::string( indent+2, ' ' );
    457475        arg1->print( os, indent+2 );
    458476        os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
     477        os << std::string( indent+2, ' ' );
    459478        arg2->print( os, indent+2 );
    460479        os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
     480        os << std::string( indent+2, ' ' );
    461481        arg3->print( os, indent+2 );
    462482        os << std::endl;
     
    477497ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
    478498        assert( callExpr );
    479         cloneAll( callExpr->get_results(), results );
     499        assert( callExpr->has_result() );
     500        set_result( callExpr->get_result()->clone() );
    480501}
    481502
     
    510531        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
    511532        assert( arg );
    512         cloneAll( arg->get_results(), results );
     533        set_result( maybeClone( arg->get_result() ) );
    513534}
    514535
     
    530551
    531552CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
    532         add_result( type->clone() );
    533 }
    534 
    535 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
     553        assert( type && initializer );
     554        set_result( type->clone() );
     555}
     556
     557CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( other.type->clone() ), initializer( other.initializer->clone() ) {}
    536558
    537559CompoundLiteralExpr::~CompoundLiteralExpr() {
     
    542564void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
    543565        os << "Compound Literal Expression: " << std::endl;
    544         if ( type ) type->print( os, indent + 2 );
    545         if ( initializer ) initializer->print( os, indent + 2 );
     566        os << std::string( indent+2, ' ' );
     567        type->print( os, indent + 2 );
     568        os << std::string( indent+2, ' ' );
     569        initializer->print( os, indent + 2 );
    546570}
    547571
     
    557581
    558582RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
    559 RangeExpr::RangeExpr( const RangeExpr &other ) : low( other.low->clone() ), high( other.high->clone() ) {}
     583RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
    560584void RangeExpr::print( std::ostream &os, int indent ) const {
    561         os << std::string( indent, ' ' ) << "Range Expression: ";
     585        os << "Range Expression: ";
    562586        low->print( os, indent );
    563587        os << " ... ";
    564588        high->print( os, indent );
     589}
     590
     591StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
     592        assert( statements );
     593        std::list< Statement * > & body = statements->get_kids();
     594        if ( ! body.empty() ) {
     595                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
     596                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
     597                }
     598        }
     599}
     600StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {}
     601StmtExpr::~StmtExpr() {
     602        delete statements;
     603}
     604void StmtExpr::print( std::ostream &os, int indent ) const {
     605        os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
     606        statements->print( os, indent+2 );
     607}
     608
     609
     610long long UniqueExpr::count = 0;
     611UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
     612        assert( expr );
     613        assert( count != -1 );
     614        if ( id == -1 ) id = count++;
     615        if ( expr->get_result() ) {
     616                set_result( expr->get_result()->clone() );
     617        }
     618}
     619UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
     620}
     621UniqueExpr::~UniqueExpr() {
     622        delete expr;
     623        delete object;
     624        delete var;
     625}
     626void UniqueExpr::print( std::ostream &os, int indent ) const {
     627        os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
     628        get_expr()->print( os, indent+2 );
     629        if ( get_object() ) {
     630                os << " with decl: ";
     631                get_object()->printShort( os, indent+2 );
     632        }
    565633}
    566634
Note: See TracChangeset for help on using the changeset viewer.