Changeset 1f44196 for src/SynTree


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, stuck-waitfor-destruct, 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

Location:
src/SynTree
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AddressExpr.cc

    r3a2128f r1f44196  
    1919
    2020AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    21         for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) {
    22                 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );
    23         } // for
     21        if ( arg->has_result() ) {
     22                set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) );
     23        }
    2424}
    2525
     
    3535        if ( arg ) {
    3636                os << std::string( indent+2, ' ' );
    37     arg->print( os, indent+2 );
     37                arg->print( os, indent+2 );
    3838        } // if
    3939}
  • src/SynTree/ApplicationExpr.cc

    r3a2128f r1f44196  
    2121#include "TypeSubstitution.h"
    2222#include "Common/utility.h"
    23 
     23#include "ResolvExpr/typeops.h"
    2424
    2525ParamEntry::ParamEntry( const ParamEntry &other ) :
     
    4343
    4444ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
    45         PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() );
    46         assert( pointer );
    47         FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    48         assert( function );
     45        PointerType *pointer = safe_dynamic_cast< PointerType* >( funcExpr->get_result() );
     46        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    4947
    50         for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
    51                 get_results().push_back( (*i)->get_type()->clone() );
    52         } // for
     48        set_result( ResolvExpr::extractResultType( function ) );
     49
     50        assert( has_result() );
    5351}
    5452
  • src/SynTree/CommaExpr.cc

    r3a2128f r1f44196  
    2323        // to false on all result types. Actually doing this causes some strange things
    2424        // to happen in later passes (particularly, Specialize, Lvalue, and Box). This needs to be looked into.
    25         cloneAll( arg2->get_results(), get_results() );
    26         // for ( Type *& type : get_results() ) {
    27         //      type->set_isLvalue( false );
    28         // }
     25        set_result( maybeClone( arg2->get_result() ) );
     26        // get_type->set_isLvalue( false );
    2927}
    3028
  • src/SynTree/CompoundStmt.cc

    r3a2128f r1f44196  
    2020#include "Expression.h"
    2121#include "Declaration.h"
     22#include "SynTree/VarExprReplacer.h"
    2223
    2324using std::string;
    2425using std::endl;
    25 
    26 class VarExprReplacer : public Visitor {
    27 public:
    28   typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;
    29 private:
    30   const DeclMap & declMap;
    31 public:
    32   VarExprReplacer( const DeclMap & declMap ) : declMap( declMap ) {}
    33 
    34   // replace variable with new node from decl map
    35   virtual void visit( VariableExpr * varExpr ) {
    36     if ( declMap.count( varExpr->get_var() ) ) {
    37       varExpr->set_var( declMap.at( varExpr->get_var() ) );
    38     }
    39   }
    40 };
    41 
    4226
    4327CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) {
     
    4731        cloneAll( other.kids, kids );
    4832
    49   // when cloning a compound statement, we may end up cloning declarations which
    50   // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
    51   // does a shallow copy, so the VariableExpr will end up pointing to the original
    52   // declaration. If the original declaration is deleted, e.g. because the original
    53   // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case,
    54   // find all DeclarationWithType nodes (since a VariableExpr must point to a
    55   // DeclarationWithType) in the original CompoundStmt and map them to the cloned
    56   // node in the new CompoundStmt ('this'), then replace the Declarations referred to
    57   // by each VariableExpr according to the constructed map. Note that only the declarations
    58   // in the current level are collected into the map, because child CompoundStmts will
    59   // recursively execute this routine. There may be more efficient ways of doing
    60   // this.
    61   VarExprReplacer::DeclMap declMap;
    62   std::list< Statement * >::const_iterator origit = other.kids.begin();
    63   for ( Statement * s : kids ) {
    64     assert( origit != other.kids.end() );
    65     if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( s ) ) {
    66       DeclStmt * origDeclStmt = dynamic_cast< DeclStmt * >( *origit );
    67       assert( origDeclStmt );
    68       if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * > ( declStmt->get_decl() ) ) {
    69         DeclarationWithType * origdwt = dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() );
    70         assert( origdwt );
    71         declMap[ origdwt ] = dwt;
    72       }
    73     }
    74   }
    75   if ( ! declMap.empty() ) {
    76     VarExprReplacer replacer( declMap );
    77     accept( replacer );
    78   }
     33        // when cloning a compound statement, we may end up cloning declarations which
     34        // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
     35        // does a shallow copy, so the VariableExpr will end up pointing to the original
     36        // declaration. If the original declaration is deleted, e.g. because the original
     37        // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case,
     38        // find all DeclarationWithType nodes (since a VariableExpr must point to a
     39        // DeclarationWithType) in the original CompoundStmt and map them to the cloned
     40        // node in the new CompoundStmt ('this'), then replace the Declarations referred to
     41        // by each VariableExpr according to the constructed map. Note that only the declarations
     42        // in the current level are collected into the map, because child CompoundStmts will
     43        // recursively execute this routine. There may be more efficient ways of doing
     44        // this.
     45        VarExprReplacer::DeclMap declMap;
     46        std::list< Statement * >::const_iterator origit = other.kids.begin();
     47        for ( Statement * s : kids ) {
     48                assert( origit != other.kids.end() );
     49                Statement * origStmt = *origit++;
     50                if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( s ) ) {
     51                        DeclStmt * origDeclStmt = dynamic_cast< DeclStmt * >( origStmt );
     52                        assert( origDeclStmt );
     53                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * > ( declStmt->get_decl() ) ) {
     54                                DeclarationWithType * origdwt = dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() );
     55                                assert( origdwt );
     56                                assert( dwt->get_name() == origdwt->get_name() );
     57                                declMap[ origdwt ] = dwt;
     58                        }
     59                }
     60        }
     61        if ( ! declMap.empty() ) {
     62                VarExprReplacer replacer( declMap );
     63                accept( replacer );
     64        }
    7965}
    8066
  • 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
  • src/SynTree/Expression.h

    r3a2128f r1f44196  
    3232        virtual ~Expression();
    3333
    34         std::list<Type *>& get_results() { return results; }
    35         void add_result( Type *t );
     34        Type *& get_result() { return result; }
     35        void set_result( Type *newValue ) { result = newValue; }
     36        bool has_result() const { return result != nullptr; }
    3637
    3738        TypeSubstitution *get_env() const { return env; }
     
    4748        virtual void print( std::ostream &os, int indent = 0 ) const;
    4849  protected:
    49         std::list<Type *> results;
     50        Type * result;
    5051        TypeSubstitution *env;
    5152        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
     
    9899class UntypedExpr : public Expression {
    99100  public:
    100         UntypedExpr( Expression *function, Expression *_aname = nullptr );
     101        UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
    101102        UntypedExpr( const UntypedExpr &other );
    102         UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );
    103103        virtual ~UntypedExpr();
    104104
     
    111111        std::list<Expression*>& get_args() { return args; }
    112112
     113        static UntypedExpr * createDeref( Expression * arg );
     114        static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
     115
    113116        virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
    114117        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    200203class UntypedMemberExpr : public Expression {
    201204  public:
    202         UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = nullptr );
     205        UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
    203206        UntypedMemberExpr( const UntypedMemberExpr &other );
    204207        virtual ~UntypedMemberExpr();
    205208
    206         std::string get_member() const { return member; }
    207         void set_member( const std::string &newValue ) { member = newValue; }
     209        Expression * get_member() const { return member; }
     210        void set_member( Expression * newValue ) { member = newValue; }
    208211        Expression *get_aggregate() const { return aggregate; }
    209212        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     
    214217        virtual void print( std::ostream &os, int indent = 0 ) const;
    215218  private:
    216         std::string member;
     219        Expression *member;
    217220        Expression *aggregate;
    218221};
     
    483486};
    484487
    485 /// TupleExpr represents a tuple expression ( [a, b, c] )
    486 class TupleExpr : public Expression {
    487   public:
    488         TupleExpr( Expression *_aname = nullptr );
    489         TupleExpr( const TupleExpr &other );
    490         virtual ~TupleExpr();
    491 
    492         void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
    493         std::list<Expression*>& get_exprs() { return exprs; }
    494 
    495         virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
    496         virtual void accept( Visitor &v ) { v.visit( this ); }
    497         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    498         virtual void print( std::ostream &os, int indent = 0 ) const;
    499   private:
    500         std::list<Expression*> exprs;
    501 };
    502 
    503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    504 class SolvedTupleExpr : public Expression {
    505   public:
    506         SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}
    507         SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );
    508         SolvedTupleExpr( const SolvedTupleExpr &other );
    509         virtual ~SolvedTupleExpr() {}
    510 
    511         std::list<Expression*> &get_exprs() { return exprs; }
    512 
    513         virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
    514         virtual void accept( Visitor &v ) { v.visit( this ); }
    515         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    516         virtual void print( std::ostream &os, int indent = 0 ) const;
    517   private:
    518         std::list<Expression*> exprs;
    519 };
    520 
    521488/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    522489class TypeExpr : public Expression {
     
    618585        CompoundLiteralExpr( Type * type, Initializer * initializer );
    619586        CompoundLiteralExpr( const CompoundLiteralExpr &other );
    620         ~CompoundLiteralExpr();
     587        virtual ~CompoundLiteralExpr();
    621588
    622589        Type * get_type() const { return type; }
     
    670637  private:
    671638        Expression *low, *high;
     639};
     640
     641/// TupleExpr represents a tuple expression ( [a, b, c] )
     642class TupleExpr : public Expression {
     643  public:
     644        TupleExpr( const std::list< Expression * > & exprs = std::list< Expression * >(), Expression *_aname = nullptr );
     645        TupleExpr( const TupleExpr &other );
     646        virtual ~TupleExpr();
     647
     648        void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
     649        std::list<Expression*>& get_exprs() { return exprs; }
     650
     651        virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
     652        virtual void accept( Visitor &v ) { v.visit( this ); }
     653        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     654        virtual void print( std::ostream &os, int indent = 0 ) const;
     655  private:
     656        std::list<Expression*> exprs;
     657};
     658
     659/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
     660class TupleIndexExpr : public Expression {
     661  public:
     662        TupleIndexExpr( Expression * tuple, unsigned int index );
     663        TupleIndexExpr( const TupleIndexExpr &other );
     664        virtual ~TupleIndexExpr();
     665
     666        Expression * get_tuple() const { return tuple; }
     667        int get_index() const { return index; }
     668        TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; }
     669        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
     670
     671        virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); }
     672        virtual void accept( Visitor &v ) { v.visit( this ); }
     673        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     674        virtual void print( std::ostream &os, int indent = 0 ) const;
     675  private:
     676        Expression * tuple;
     677        unsigned int index;
     678};
     679
     680/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
     681class MemberTupleExpr : public Expression {
     682  public:
     683        MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
     684        MemberTupleExpr( const MemberTupleExpr &other );
     685        virtual ~MemberTupleExpr();
     686
     687        Expression * get_member() const { return member; }
     688        Expression * get_aggregate() const { return aggregate; }
     689        MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; }
     690        MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; }
     691
     692        virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); }
     693        virtual void accept( Visitor &v ) { v.visit( this ); }
     694        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     695        virtual void print( std::ostream &os, int indent = 0 ) const;
     696  private:
     697        Expression * member;
     698        Expression * aggregate;
     699};
     700
     701/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;, or a tuple ctor/dtor expression
     702class TupleAssignExpr : public Expression {
     703  public:
     704        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
     705        TupleAssignExpr( const TupleAssignExpr &other );
     706        virtual ~TupleAssignExpr();
     707
     708        std::list< Expression * > & get_assigns() { return assigns; }
     709        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     710
     711        virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); }
     712        virtual void accept( Visitor &v ) { v.visit( this ); }
     713        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     714        virtual void print( std::ostream &os, int indent = 0 ) const;
     715  private:
     716        std::list< Expression * > assigns; // assignment expressions that use tempDecls
     717        std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs
     718};
     719
     720/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
     721class StmtExpr : public Expression {
     722public:
     723        StmtExpr( CompoundStmt *statements );
     724        StmtExpr( const StmtExpr & other );
     725        virtual ~StmtExpr();
     726
     727        CompoundStmt * get_statements() const { return statements; }
     728        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
     729
     730        virtual StmtExpr *clone() const { return new StmtExpr( *this ); }
     731        virtual void accept( Visitor &v ) { v.visit( this ); }
     732        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     733        virtual void print( std::ostream &os, int indent = 0 ) const;
     734private:
     735        CompoundStmt * statements;
     736};
     737
     738class UniqueExpr : public Expression {
     739public:
     740        UniqueExpr( Expression * expr, long long idVal = -1 );
     741        UniqueExpr( const UniqueExpr & other );
     742        ~UniqueExpr();
     743
     744        Expression * get_expr() const { return expr; }
     745        UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
     746
     747        ObjectDecl * get_object() const { return object; }
     748        UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
     749
     750        VariableExpr * get_var() const { return var; }
     751        UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
     752
     753        int get_id() const { return id; }
     754
     755        virtual UniqueExpr *clone() const { return new UniqueExpr( *this ); }
     756        virtual void accept( Visitor &v ) { v.visit( this ); }
     757        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     758        virtual void print( std::ostream &os, int indent = 0 ) const;
     759private:
     760        Expression * expr;
     761        ObjectDecl * object;
     762        VariableExpr * var;
     763        int id;
     764        static long long count;
    672765};
    673766
  • src/SynTree/Initializer.h

    r3a2128f r1f44196  
    2323
    2424#include <cassert>
     25
     26const std::list<Expression*> noDesignators;
    2527
    2628// Initializer: base class for object initializers (provide default values)
  • src/SynTree/Mutator.cc

    r3a2128f r1f44196  
    178178
    179179Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
    180         mutateAll( applicationExpr->get_results(), *this );
     180        applicationExpr->set_result( maybeMutate( applicationExpr->get_result(), *this ) );
    181181        applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
    182182        mutateAll( applicationExpr->get_args(), *this );
     
    185185
    186186Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
    187         mutateAll( untypedExpr->get_results(), *this );
     187        untypedExpr->set_result( maybeMutate( untypedExpr->get_result(), *this ) );
    188188        mutateAll( untypedExpr->get_args(), *this );
    189189        return untypedExpr;
     
    191191
    192192Expression *Mutator::mutate( NameExpr *nameExpr ) {
    193         mutateAll( nameExpr->get_results(), *this );
     193        nameExpr->set_result( maybeMutate( nameExpr->get_result(), *this ) );
    194194        return nameExpr;
    195195}
    196196
    197197Expression *Mutator::mutate( AddressExpr *addressExpr ) {
    198         mutateAll( addressExpr->get_results(), *this );
     198        addressExpr->set_result( maybeMutate( addressExpr->get_result(), *this ) );
    199199        addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
    200200        return addressExpr;
     
    202202
    203203Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
    204         mutateAll( labelAddressExpr->get_results(), *this );
     204        labelAddressExpr->set_result( maybeMutate( labelAddressExpr->get_result(), *this ) );
    205205        labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
    206206        return labelAddressExpr;
     
    208208
    209209Expression *Mutator::mutate( CastExpr *castExpr ) {
    210         mutateAll( castExpr->get_results(), *this );
     210        castExpr->set_result( maybeMutate( castExpr->get_result(), *this ) );
    211211        castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
    212212        return castExpr;
     
    214214
    215215Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
    216         mutateAll( memberExpr->get_results(), *this );
     216        memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) );
     217        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
     218        memberExpr->set_member( maybeMutate( memberExpr->get_member(), *this ) );
     219        return memberExpr;
     220}
     221
     222Expression *Mutator::mutate( MemberExpr *memberExpr ) {
     223        memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) );
    217224        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    218225        return memberExpr;
    219226}
    220227
    221 Expression *Mutator::mutate( MemberExpr *memberExpr ) {
    222         mutateAll( memberExpr->get_results(), *this );
    223         memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    224         return memberExpr;
    225 }
    226 
    227228Expression *Mutator::mutate( VariableExpr *variableExpr ) {
    228         mutateAll( variableExpr->get_results(), *this );
     229        variableExpr->set_result( maybeMutate( variableExpr->get_result(), *this ) );
    229230        return variableExpr;
    230231}
    231232
    232233Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
    233         mutateAll( constantExpr->get_results(), *this );
     234        constantExpr->set_result( maybeMutate( constantExpr->get_result(), *this ) );
    234235//  maybeMutate( constantExpr->get_constant(), *this )
    235236        return constantExpr;
     
    237238
    238239Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
    239         mutateAll( sizeofExpr->get_results(), *this );
     240        sizeofExpr->set_result( maybeMutate( sizeofExpr->get_result(), *this ) );
    240241        if ( sizeofExpr->get_isType() ) {
    241242                sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
     
    247248
    248249Expression *Mutator::mutate( AlignofExpr *alignofExpr ) {
    249         mutateAll( alignofExpr->get_results(), *this );
     250        alignofExpr->set_result( maybeMutate( alignofExpr->get_result(), *this ) );
    250251        if ( alignofExpr->get_isType() ) {
    251252                alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) );
     
    257258
    258259Expression *Mutator::mutate( UntypedOffsetofExpr *offsetofExpr ) {
    259         mutateAll( offsetofExpr->get_results(), *this );
     260        offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) );
    260261        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
    261262        return offsetofExpr;
     
    263264
    264265Expression *Mutator::mutate( OffsetofExpr *offsetofExpr ) {
    265         mutateAll( offsetofExpr->get_results(), *this );
     266        offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) );
    266267        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
    267268        offsetofExpr->set_member( maybeMutate( offsetofExpr->get_member(), *this ) );
     
    270271
    271272Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
    272         mutateAll( offsetPackExpr->get_results(), *this );
     273        offsetPackExpr->set_result( maybeMutate( offsetPackExpr->get_result(), *this ) );
    273274        offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
    274275        return offsetPackExpr;
     
    276277
    277278Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    278         mutateAll( attrExpr->get_results(), *this );
     279        attrExpr->set_result( maybeMutate( attrExpr->get_result(), *this ) );
    279280        if ( attrExpr->get_isType() ) {
    280281                attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
     
    286287
    287288Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
    288         mutateAll( logicalExpr->get_results(), *this );
     289        logicalExpr->set_result( maybeMutate( logicalExpr->get_result(), *this ) );
    289290        logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
    290291        logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
     
    293294
    294295Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
    295         mutateAll( conditionalExpr->get_results(), *this );
     296        conditionalExpr->set_result( maybeMutate( conditionalExpr->get_result(), *this ) );
    296297        conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
    297298        conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
     
    301302
    302303Expression *Mutator::mutate( CommaExpr *commaExpr ) {
    303         mutateAll( commaExpr->get_results(), *this );
     304        commaExpr->set_result( maybeMutate( commaExpr->get_result(), *this ) );
    304305        commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
    305306        commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
     
    307308}
    308309
    309 Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
    310         mutateAll( tupleExpr->get_results(), *this );
    311         mutateAll( tupleExpr->get_exprs(), *this );
    312         return tupleExpr;
    313 }
    314 
    315 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
    316         mutateAll( tupleExpr->get_results(), *this );
    317         mutateAll( tupleExpr->get_exprs(), *this );
    318         return tupleExpr;
    319 }
    320 
    321310Expression *Mutator::mutate( TypeExpr *typeExpr ) {
    322         mutateAll( typeExpr->get_results(), *this );
     311        typeExpr->set_result( maybeMutate( typeExpr->get_result(), *this ) );
    323312        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
    324313        return typeExpr;
     
    340329
    341330Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) {
    342         mutateAll( ctorExpr->get_results(), *this );
     331        ctorExpr->set_result( maybeMutate( ctorExpr->get_result(), *this ) );
    343332        ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) );
    344333        return ctorExpr;
     
    346335
    347336Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {
    348         mutateAll( compLitExpr->get_results(), *this );
     337        compLitExpr->set_result( maybeMutate( compLitExpr->get_result(), *this ) );
    349338        compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );
    350339        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
     
    353342
    354343Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
    355         mutateAll( valofExpr->get_results(), *this );
     344        valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) );
    356345        return valofExpr;
    357346}
     
    361350        rangeExpr->set_high( maybeMutate( rangeExpr->get_high(), *this ) );
    362351        return rangeExpr;
     352}
     353
     354Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
     355        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
     356        mutateAll( tupleExpr->get_exprs(), *this );
     357        return tupleExpr;
     358}
     359
     360Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) {
     361        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
     362        tupleExpr->set_tuple( maybeMutate( tupleExpr->get_tuple(), *this ) );
     363        return tupleExpr;
     364}
     365
     366Expression *Mutator::mutate( MemberTupleExpr *tupleExpr ) {
     367        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
     368        tupleExpr->set_member( maybeMutate( tupleExpr->get_member(), *this ) );
     369        tupleExpr->set_aggregate( maybeMutate( tupleExpr->get_aggregate(), *this ) );
     370        return tupleExpr;
     371}
     372
     373Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) {
     374        assignExpr->set_result( maybeMutate( assignExpr->get_result(), *this ) );
     375        mutateAll( assignExpr->get_tempDecls(), *this );
     376        mutateAll( assignExpr->get_assigns(), *this );
     377        return assignExpr;
     378}
     379
     380Expression *Mutator::mutate( StmtExpr *stmtExpr ) {
     381        stmtExpr->set_result( maybeMutate( stmtExpr->get_result(), *this ) );
     382        stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) );
     383        return stmtExpr;
     384}
     385
     386Expression *Mutator::mutate( UniqueExpr *uniqueExpr ) {
     387        uniqueExpr->set_result( maybeMutate( uniqueExpr->get_result(), *this ) );
     388        uniqueExpr->set_expr( maybeMutate( uniqueExpr->get_expr(), *this ) );
     389        return uniqueExpr;
    363390}
    364391
  • src/SynTree/Mutator.h

    r3a2128f r1f44196  
    7171        virtual Expression* mutate( ConditionalExpr *conditionalExpr );
    7272        virtual Expression* mutate( CommaExpr *commaExpr );
    73         virtual Expression* mutate( TupleExpr *tupleExpr );
    74         virtual Expression* mutate( SolvedTupleExpr *tupleExpr );
    7573        virtual Expression* mutate( TypeExpr *typeExpr );
    7674        virtual Expression* mutate( AsmExpr *asmExpr );
     
    8078        virtual Expression* mutate( UntypedValofExpr *valofExpr );
    8179        virtual Expression* mutate( RangeExpr *rangeExpr );
     80        virtual Expression* mutate( TupleExpr *tupleExpr );
     81        virtual Expression* mutate( TupleIndexExpr *tupleExpr );
     82        virtual Expression* mutate( MemberTupleExpr *tupleExpr );
     83        virtual Expression* mutate( TupleAssignExpr *assignExpr );
     84        virtual Expression* mutate( StmtExpr * stmtExpr );
     85        virtual Expression* mutate( UniqueExpr * uniqueExpr );
    8286
    8387        virtual Type* mutate( VoidType *basicType );
  • src/SynTree/ReferenceToType.cc

    r3a2128f r1f44196  
    5656        }
    5757} // namespace
     58
     59StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct ) : Parent( tq, baseStruct->get_name() ), baseStruct( baseStruct ) {}
    5860
    5961std::string StructInstType::typeString() const { return "struct"; }
  • src/SynTree/SynTree.h

    r3a2128f r1f44196  
    7676class ConditionalExpr;
    7777class CommaExpr;
    78 class TupleExpr;
    79 class SolvedTupleExpr;
    8078class TypeExpr;
    8179class AsmExpr;
     
    8583class UntypedValofExpr;
    8684class RangeExpr;
     85class TupleExpr;
     86class TupleIndexExpr;
     87class MemberTupleExpr;
     88class TupleAssignExpr;
     89class StmtExpr;
     90class UniqueExpr;
    8791
    8892class Type;
  • src/SynTree/TupleExpr.cc

    r3a2128f r1f44196  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleExpr.cc -- 
     7// TupleExpr.cc --
    88//
    99// Author           : Richard C. Bilson
     
    1616#include "Expression.h"
    1717#include "Common/utility.h"
     18#include "Type.h"
     19#include "Declaration.h"
     20#include "Tuples/Tuples.h"
     21#include "VarExprReplacer.h"
    1822
    19 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) {
     23TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
     24        if ( ! exprs.empty() ) {
     25                if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) {
     26                        set_result( Tuples::makeTupleType( exprs ) );
     27                }
     28        }
    2029}
    2130
     
    2938
    3039void TupleExpr::print( std::ostream &os, int indent ) const {
    31         os << std::string( indent, ' ' ) << "Tuple:" << std::endl;
     40        os << "Tuple:" << std::endl;
    3241        printAll( exprs, os, indent+2 );
    3342        Expression::print( os, indent );
    3443}
    3544
    36 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) {
    37         std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs));
     45TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
     46        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
     47        assert( type->size() > index );
     48        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
     49        get_result()->set_isLvalue( type->get_isLvalue() );
    3850}
    3951
    40 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) {
    41         cloneAll( other.exprs, exprs );
     52TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
    4253}
    4354
    44 void SolvedTupleExpr::print( std::ostream &os, int indent ) const {
    45         os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl;
    46         printAll( exprs, os, indent+2 );
     55TupleIndexExpr::~TupleIndexExpr() {
     56        delete tuple;
     57}
     58
     59void TupleIndexExpr::print( std::ostream &os, int indent ) const {
     60        os << "Tuple Index Expression, with tuple:" << std::endl;
     61        os << std::string( indent+2, ' ' );
     62        tuple->print( os, indent+2 );
     63        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
    4764        Expression::print( os, indent );
    4865}
     66
     67MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
     68        set_result( maybeClone( member->get_result() ) ); // xxx - ???
     69}
     70
     71MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {
     72}
     73
     74MemberTupleExpr::~MemberTupleExpr() {
     75        delete member;
     76        delete aggregate;
     77}
     78
     79void MemberTupleExpr::print( std::ostream &os, int indent ) const {
     80        os << "Member Tuple Expression, with aggregate:" << std::endl;
     81        os << std::string( indent+2, ' ' );
     82        aggregate->print( os, indent+2 );
     83        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
     84        os << std::string( indent+2, ' ' );
     85        member->print( os, indent+2 );
     86        Expression::print( os, indent );
     87}
     88
     89
     90TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
     91        set_result( Tuples::makeTupleType( assigns ) );
     92}
     93
     94TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
     95        cloneAll( other.assigns, assigns );
     96        cloneAll( other.tempDecls, tempDecls );
     97
     98        // clone needs to go into assigns and replace tempDecls
     99        VarExprReplacer::DeclMap declMap;
     100        std::list< ObjectDecl * >::const_iterator origit = other.tempDecls.begin();
     101        for ( ObjectDecl * temp : tempDecls ) {
     102                assert( origit != other.tempDecls.end() );
     103                ObjectDecl * origTemp = *origit++;
     104                assert( origTemp );
     105                assert( temp->get_name() == origTemp->get_name() );
     106                declMap[ origTemp ] = temp;
     107        }
     108        if ( ! declMap.empty() ) {
     109                VarExprReplacer replacer( declMap );
     110                for ( Expression * assn : assigns ) {
     111                        assn->accept( replacer );
     112                }
     113        }
     114}
     115
     116TupleAssignExpr::~TupleAssignExpr() {
     117        deleteAll( assigns );
     118        // deleteAll( tempDecls );
     119}
     120
     121void TupleAssignExpr::print( std::ostream &os, int indent ) const {
     122        os << "Tuple Assignment Expression, with temporaries:" << std::endl;
     123        printAll( tempDecls, os, indent+4 );
     124        os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl;
     125        printAll( assigns, os, indent+4 );
     126        Expression::print( os, indent );
     127}
     128
     129
    49130
    50131// Local Variables: //
  • src/SynTree/TupleType.cc

    r3a2128f r1f44196  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleType.cc -- 
     7// TupleType.cc --
    88//
    99// Author           : Richard C. Bilson
     
    1717#include "Common/utility.h"
    1818
    19 TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq ) {
     19TupleType::TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types ) : Type( tq ), types( types ) {
    2020}
    2121
  • src/SynTree/Type.h

    r3a2128f r1f44196  
    2020#include "Visitor.h"
    2121#include "Mutator.h"
     22#include "Common/utility.h"
    2223
    2324class Type {
     
    2728                Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
    2829
     30                Qualifiers &operator&=( const Qualifiers &other );
    2931                Qualifiers &operator+=( const Qualifiers &other );
    3032                Qualifiers &operator-=( const Qualifiers &other );
     
    6365        void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
    6466        void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }
    65         std::list<TypeDecl*>& get_forall() { return forall; }
     67
     68        typedef std::list<TypeDecl *> ForallList;
     69        ForallList& get_forall() { return forall; }
     70
     71        /// How many elemental types are represented by this type
     72        virtual unsigned size() const { return 1; };
     73        virtual bool isVoid() const { return size() == 0; }
    6674
    6775        virtual Type *clone() const = 0;
     
    7179  private:
    7280        Qualifiers tq;
    73         std::list<TypeDecl*> forall;
     81        ForallList forall;
    7482};
    7583
     
    7785  public:
    7886        VoidType( const Type::Qualifiers &tq );
     87
     88        virtual unsigned size() const { return 0; };
    7989
    8090        virtual VoidType *clone() const { return new VoidType( *this ); }
     
    234244  public:
    235245        StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
     246        StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct );
    236247        StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
    237248
     
    348359class TupleType : public Type {
    349360  public:
    350         TupleType( const Type::Qualifiers &tq );
     361        TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >() );
    351362        TupleType( const TupleType& );
    352363        virtual ~TupleType();
    353364
     365        typedef std::list<Type*> value_type;
     366        typedef value_type::iterator iterator;
     367
    354368        std::list<Type*>& get_types() { return types; }
     369        virtual unsigned size() const { return types.size(); };
     370
     371        iterator begin() { return types.begin(); }
     372        iterator end() { return types.end(); }
    355373
    356374        virtual TupleType *clone() const { return new TupleType( *this ); }
     
    442460};
    443461
     462inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) {
     463        isConst &= other.isConst;
     464        isVolatile &= other.isVolatile;
     465        isRestrict &= other.isRestrict;
     466        isLvalue &= other.isLvalue;
     467        isAtomic &= other.isAtomic;
     468        return *this;
     469}
     470
    444471inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
    445472        isConst |= other.isConst;
  • src/SynTree/TypeSubstitution.cc

    r3a2128f r1f44196  
    7272Type *TypeSubstitution::lookup( std::string formalType ) const {
    7373        TypeEnvType::const_iterator i = typeEnv.find( formalType );
    74        
     74
    7575        // break on not in substitution set
    7676        if ( i == typeEnv.end() ) return 0;
    77        
     77
    7878        // attempt to transitively follow TypeInstType links.
    7979        while ( TypeInstType *actualType = dynamic_cast< TypeInstType* >( i->second ) ) {
    8080                const std::string& typeName = actualType->get_name();
    81                
     81
    8282                // break cycles in the transitive follow
    8383                if ( formalType == typeName ) break;
    84                
     84
    8585                // Look for the type this maps to, returning previous mapping if none-such
    8686                i = typeEnv.find( typeName );
    8787                if ( i == typeEnv.end() ) return actualType;
    8888        }
    89        
     89
    9090        // return type from substitution set
    9191        return i->second;
    92        
     92
    9393#if 0
    9494        if ( i == typeEnv.end() ) {
     
    149149        // bind type variables from forall-qualifiers
    150150        if ( freeOnly ) {
    151                 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
     151                for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
    152152                        boundVars.insert( (*tyvar )->get_name() );
    153153                } // for
     
    163163        // bind type variables from forall-qualifiers
    164164        if ( freeOnly ) {
    165                 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
     165                for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
    166166                        boundVars.insert( (*tyvar )->get_name() );
    167167                } // for
  • src/SynTree/Visitor.cc

    r3a2128f r1f44196  
    150150
    151151void Visitor::visit( ApplicationExpr *applicationExpr ) {
    152         acceptAll( applicationExpr->get_results(), *this );
     152        maybeAccept( applicationExpr->get_result(), *this );
    153153        maybeAccept( applicationExpr->get_function(), *this );
    154154        acceptAll( applicationExpr->get_args(), *this );
     
    156156
    157157void Visitor::visit( UntypedExpr *untypedExpr ) {
    158         acceptAll( untypedExpr->get_results(), *this );
     158        maybeAccept( untypedExpr->get_result(), *this );
    159159        acceptAll( untypedExpr->get_args(), *this );
    160160}
    161161
    162162void Visitor::visit( NameExpr *nameExpr ) {
    163         acceptAll( nameExpr->get_results(), *this );
     163        maybeAccept( nameExpr->get_result(), *this );
    164164}
    165165
    166166void Visitor::visit( AddressExpr *addressExpr ) {
    167         acceptAll( addressExpr->get_results(), *this );
     167        maybeAccept( addressExpr->get_result(), *this );
    168168        maybeAccept( addressExpr->get_arg(), *this );
    169169}
    170170
    171171void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
    172         acceptAll( labAddressExpr->get_results(), *this );
     172        maybeAccept( labAddressExpr->get_result(), *this );
    173173        maybeAccept( labAddressExpr->get_arg(), *this );
    174174}
    175175
    176176void Visitor::visit( CastExpr *castExpr ) {
    177         acceptAll( castExpr->get_results(), *this );
     177        maybeAccept( castExpr->get_result(), *this );
    178178        maybeAccept( castExpr->get_arg(), *this );
    179179}
    180180
    181181void Visitor::visit( UntypedMemberExpr *memberExpr ) {
    182         acceptAll( memberExpr->get_results(), *this );
     182        maybeAccept( memberExpr->get_result(), *this );
    183183        maybeAccept( memberExpr->get_aggregate(), *this );
     184        maybeAccept( memberExpr->get_member(), *this );
    184185}
    185186
    186187void Visitor::visit( MemberExpr *memberExpr ) {
    187         acceptAll( memberExpr->get_results(), *this );
     188        maybeAccept( memberExpr->get_result(), *this );
    188189        maybeAccept( memberExpr->get_aggregate(), *this );
    189190}
    190191
    191192void Visitor::visit( VariableExpr *variableExpr ) {
    192         acceptAll( variableExpr->get_results(), *this );
     193        maybeAccept( variableExpr->get_result(), *this );
    193194}
    194195
    195196void Visitor::visit( ConstantExpr *constantExpr ) {
    196         acceptAll( constantExpr->get_results(), *this );
     197        maybeAccept( constantExpr->get_result(), *this );
    197198        maybeAccept( constantExpr->get_constant(), *this );
    198199}
    199200
    200201void Visitor::visit( SizeofExpr *sizeofExpr ) {
    201         acceptAll( sizeofExpr->get_results(), *this );
     202        maybeAccept( sizeofExpr->get_result(), *this );
    202203        if ( sizeofExpr->get_isType() ) {
    203204                maybeAccept( sizeofExpr->get_type(), *this );
     
    208209
    209210void Visitor::visit( AlignofExpr *alignofExpr ) {
    210         acceptAll( alignofExpr->get_results(), *this );
     211        maybeAccept( alignofExpr->get_result(), *this );
    211212        if ( alignofExpr->get_isType() ) {
    212213                maybeAccept( alignofExpr->get_type(), *this );
     
    217218
    218219void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
    219         acceptAll( offsetofExpr->get_results(), *this );
     220        maybeAccept( offsetofExpr->get_result(), *this );
    220221        maybeAccept( offsetofExpr->get_type(), *this );
    221222}
    222223
    223224void Visitor::visit( OffsetofExpr *offsetofExpr ) {
    224         acceptAll( offsetofExpr->get_results(), *this );
     225        maybeAccept( offsetofExpr->get_result(), *this );
    225226        maybeAccept( offsetofExpr->get_type(), *this );
    226227        maybeAccept( offsetofExpr->get_member(), *this );
     
    228229
    229230void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
    230         acceptAll( offsetPackExpr->get_results(), *this );
     231        maybeAccept( offsetPackExpr->get_result(), *this );
    231232        maybeAccept( offsetPackExpr->get_type(), *this );
    232233}
    233234
    234235void Visitor::visit( AttrExpr *attrExpr ) {
    235         acceptAll( attrExpr->get_results(), *this );
     236        maybeAccept( attrExpr->get_result(), *this );
    236237        if ( attrExpr->get_isType() ) {
    237238                maybeAccept( attrExpr->get_type(), *this );
     
    242243
    243244void Visitor::visit( LogicalExpr *logicalExpr ) {
    244         acceptAll( logicalExpr->get_results(), *this );
     245        maybeAccept( logicalExpr->get_result(), *this );
    245246        maybeAccept( logicalExpr->get_arg1(), *this );
    246247        maybeAccept( logicalExpr->get_arg2(), *this );
     
    248249
    249250void Visitor::visit( ConditionalExpr *conditionalExpr ) {
    250         acceptAll( conditionalExpr->get_results(), *this );
     251        maybeAccept( conditionalExpr->get_result(), *this );
    251252        maybeAccept( conditionalExpr->get_arg1(), *this );
    252253        maybeAccept( conditionalExpr->get_arg2(), *this );
     
    255256
    256257void Visitor::visit( CommaExpr *commaExpr ) {
    257         acceptAll( commaExpr->get_results(), *this );
     258        maybeAccept( commaExpr->get_result(), *this );
    258259        maybeAccept( commaExpr->get_arg1(), *this );
    259260        maybeAccept( commaExpr->get_arg2(), *this );
    260261}
    261262
    262 void Visitor::visit( TupleExpr *tupleExpr ) {
    263         acceptAll( tupleExpr->get_results(), *this );
    264         acceptAll( tupleExpr->get_exprs(), *this );
    265 }
    266 
    267 void Visitor::visit( SolvedTupleExpr *tupleExpr ) {
    268         acceptAll( tupleExpr->get_results(), *this );
    269         acceptAll( tupleExpr->get_exprs(), *this );
    270 }
    271 
    272263void Visitor::visit( TypeExpr *typeExpr ) {
    273         acceptAll( typeExpr->get_results(), *this );
     264        maybeAccept( typeExpr->get_result(), *this );
    274265        maybeAccept( typeExpr->get_type(), *this );
    275266}
     
    288279
    289280void Visitor::visit( ConstructorExpr * ctorExpr ) {
    290         acceptAll( ctorExpr->get_results(), *this );
     281        maybeAccept( ctorExpr->get_result(), *this );
    291282        maybeAccept( ctorExpr->get_callExpr(), *this );
    292283}
    293284
    294285void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
    295         acceptAll( compLitExpr->get_results(), *this );
     286        maybeAccept( compLitExpr->get_result(), *this );
    296287        maybeAccept( compLitExpr->get_type(), *this );
    297288        maybeAccept( compLitExpr->get_initializer(), *this );
     
    299290
    300291void Visitor::visit( UntypedValofExpr *valofExpr ) {
    301         acceptAll( valofExpr->get_results(), *this );
     292        maybeAccept( valofExpr->get_result(), *this );
    302293        maybeAccept( valofExpr->get_body(), *this );
    303294}
     
    306297        maybeAccept( rangeExpr->get_low(), *this );
    307298        maybeAccept( rangeExpr->get_high(), *this );
     299}
     300
     301void Visitor::visit( TupleExpr *tupleExpr ) {
     302        maybeAccept( tupleExpr->get_result(), *this );
     303        acceptAll( tupleExpr->get_exprs(), *this );
     304}
     305
     306void Visitor::visit( TupleIndexExpr *tupleExpr ) {
     307        maybeAccept( tupleExpr->get_result(), *this );
     308        maybeAccept( tupleExpr->get_tuple(), *this );
     309}
     310
     311void Visitor::visit( MemberTupleExpr *tupleExpr ) {
     312        maybeAccept( tupleExpr->get_result(), *this );
     313        maybeAccept( tupleExpr->get_member(), *this );
     314        maybeAccept( tupleExpr->get_aggregate(), *this );
     315}
     316
     317void Visitor::visit( TupleAssignExpr *assignExpr ) {
     318        maybeAccept( assignExpr->get_result(), *this );
     319        acceptAll( assignExpr->get_tempDecls(), *this );
     320        acceptAll( assignExpr->get_assigns(), *this );
     321}
     322
     323void Visitor::visit( StmtExpr *stmtExpr ) {
     324        maybeAccept( stmtExpr->get_result(), *this );
     325        maybeAccept( stmtExpr->get_statements(), *this );
     326}
     327
     328void Visitor::visit( UniqueExpr *uniqueExpr ) {
     329        maybeAccept( uniqueExpr->get_result(), *this );
     330        maybeAccept( uniqueExpr->get_expr(), *this );
    308331}
    309332
  • src/SynTree/Visitor.h

    r3a2128f r1f44196  
    7171        virtual void visit( ConditionalExpr *conditionalExpr );
    7272        virtual void visit( CommaExpr *commaExpr );
    73         virtual void visit( TupleExpr *tupleExpr );
    74         virtual void visit( SolvedTupleExpr *tupleExpr );
    7573        virtual void visit( TypeExpr *typeExpr );
    7674        virtual void visit( AsmExpr *asmExpr );
     
    8078        virtual void visit( UntypedValofExpr *valofExpr );
    8179        virtual void visit( RangeExpr *rangeExpr );
     80        virtual void visit( TupleExpr *tupleExpr );
     81        virtual void visit( TupleIndexExpr *tupleExpr );
     82        virtual void visit( MemberTupleExpr *tupleExpr );
     83        virtual void visit( TupleAssignExpr *assignExpr );
     84        virtual void visit( StmtExpr * stmtExpr );
     85        virtual void visit( UniqueExpr * uniqueExpr );
    8286
    8387        virtual void visit( VoidType *basicType );
  • src/SynTree/module.mk

    r3a2128f r1f44196  
    4949       SynTree/AddStmtVisitor.cc \
    5050       SynTree/TypeSubstitution.cc \
    51        SynTree/Attribute.cc
     51       SynTree/Attribute.cc \
     52       SynTree/VarExprReplacer.cc
    5253
Note: See TracChangeset for help on using the changeset viewer.