Ignore:
Timestamp:
Apr 14, 2016, 4:13:10 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
356189a
Parents:
db4ecc5 (diff), 37f0da8 (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' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/GenPoly/Box.cc
src/Parser/DeclarationNode.cc
src/Parser/ParseNode.h
src/Parser/parser.cc
src/Parser/parser.yy
src/SymTab/AddVisit.h
src/SymTab/Validate.cc
src/SynTree/Expression.cc
src/SynTree/Expression.h
src/SynTree/Mutator.cc
src/SynTree/Mutator.h
src/SynTree/SynTree.h
src/SynTree/Visitor.cc
src/SynTree/Visitor.h
src/libcfa/iostream.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rdb4ecc5 r70a06f6  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Apr 04 17:13:29 2016
     12// Last Modified On : Thu Apr 14 15:37:23 2016
    1313// Update Count     : 297
    1414//
     
    4040#include <list>
    4141#include <iterator>
     42#include "Common/utility.h"
     43#include "Common/UniqueName.h"
    4244#include "Validate.h"
    4345#include "SynTree/Visitor.h"
    4446#include "SynTree/Mutator.h"
    4547#include "SynTree/Type.h"
     48#include "SynTree/Expression.h"
    4649#include "SynTree/Statement.h"
    4750#include "SynTree/TypeSubstitution.h"
     
    4952#include "FixFunction.h"
    5053// #include "ImplementationType.h"
    51 #include "Common/utility.h"
    52 #include "Common/UniqueName.h"
     54#include "GenPoly/DeclMutator.h"
    5355#include "AddVisit.h"
    5456#include "MakeLibCfa.h"
     
    7173
    7274                virtual void visit( CompoundStmt *compoundStmt );
    73                 virtual void visit( IfStmt *ifStmt );
    74                 virtual void visit( WhileStmt *whileStmt );
    75                 virtual void visit( ForStmt *forStmt );
    7675                virtual void visit( SwitchStmt *switchStmt );
    7776                virtual void visit( ChooseStmt *chooseStmt );
    78                 virtual void visit( CaseStmt *caseStmt );
    79                 virtual void visit( CatchStmt *catchStmt );
     77                // virtual void visit( CaseStmt *caseStmt );
    8078          private:
    8179                HoistStruct();
     
    132130                /// and return something if the return type is non-void.
    133131                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    134 
    135132          private:
    136133                virtual void visit( FunctionDecl * functionDecl );
     
    163160                AggDecl *handleAggregate( AggDecl * aggDecl );
    164161
     162                template<typename AggDecl>
     163                void addImplicitTypedef( AggDecl * aggDecl );
     164
    165165                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
    166166                TypedefMap typedefNames;
     
    175175                static void verify( std::list< Declaration * > &translationUnit );
    176176
    177                 // VerifyCtorDtor() {}
    178 
    179177                virtual void visit( FunctionDecl *funcDecl );
    180         private:
     178};
     179
     180        class CompoundLiteral : public GenPoly::DeclMutator {
     181                DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;
     182
     183                virtual DeclarationWithType * mutate( ObjectDecl *objectDecl );
     184                virtual Expression *mutate( CompoundLiteralExpr *compLitExpr );
    181185        };
    182186
     
    185189                Pass2 pass2( doDebug, 0 );
    186190                Pass3 pass3( 0 );
     191                CompoundLiteral compoundliteral;
     192
    187193                EliminateTypedef::eliminateTypedef( translationUnit );
    188194                HoistStruct::hoistStruct( translationUnit );
     
    190196                acceptAll( translationUnit, pass2 );
    191197                ReturnChecker::checkFunctionReturns( translationUnit );
     198                mutateAll( translationUnit, compoundliteral );
    192199                autogenerateRoutines( translationUnit );
    193200                acceptAll( translationUnit, pass3 );
     
    258265        }
    259266
    260         void HoistStruct::visit( IfStmt *ifStmt ) {
    261                 addVisit( ifStmt, *this );
    262         }
    263 
    264         void HoistStruct::visit( WhileStmt *whileStmt ) {
    265                 addVisit( whileStmt, *this );
    266         }
    267 
    268         void HoistStruct::visit( ForStmt *forStmt ) {
    269                 addVisit( forStmt, *this );
    270         }
    271 
    272267        void HoistStruct::visit( SwitchStmt *switchStmt ) {
    273268                addVisit( switchStmt, *this );
     
    278273        }
    279274
    280         void HoistStruct::visit( CaseStmt *caseStmt ) {
    281                 addVisit( caseStmt, *this );
    282         }
    283 
    284         void HoistStruct::visit( CatchStmt *cathStmt ) {
    285                 addVisit( cathStmt, *this );
    286         }
     275        // void HoistStruct::visit( CaseStmt *caseStmt ) {
     276        //      addVisit( caseStmt, *this );
     277        // }
    287278
    288279        void Pass1::visit( EnumDecl *enumDecl ) {
     
    620611        }
    621612
    622         // there may be typedefs nested within aggregates
    623         // in order for everything to work properly, these
    624         // should be removed as well
     613        // there may be typedefs nested within aggregates in order for everything to work properly, these should be removed
     614        // as well
    625615        template<typename AggDecl>
    626616        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
     
    637627        }
    638628
     629        template<typename AggDecl>
     630        void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
     631                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
     632                        Type *type;
     633                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
     634                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
     635                        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) {
     636                                type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() );
     637                        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl )  ) {
     638                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
     639                        } // if
     640                        TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type );
     641                        typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     642                } // if
     643        }
    639644        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
     645                addImplicitTypedef( structDecl );
    640646                Mutator::mutate( structDecl );
    641647                return handleAggregate( structDecl );
     
    643649
    644650        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
     651                addImplicitTypedef( unionDecl );
    645652                Mutator::mutate( unionDecl );
    646653                return handleAggregate( unionDecl );
     
    648655
    649656        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
     657                addImplicitTypedef( enumDecl );
    650658                Mutator::mutate( enumDecl );
    651659                return handleAggregate( enumDecl );
    652660        }
    653661
    654                 Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) {
     662        Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) {
    655663                Mutator::mutate( contextDecl );
    656664                return handleAggregate( contextDecl );
     
    689697                // added, so not in this pass!
    690698        }
     699
     700        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
     701                storageclass = objectDecl->get_storageClass();
     702                DeclarationWithType * temp = Mutator::mutate( objectDecl );
     703                storageclass = DeclarationNode::NoStorageClass;
     704                return temp;
     705        }
     706
     707        Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
     708                // transform [storage_class] ... (struct S){ 3, ... };
     709                // into [storage_class] struct S temp =  { 3, ... };
     710                static UniqueName indexName( "_compLit" );
     711
     712                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() );
     713                compLitExpr->set_type( 0 );
     714                compLitExpr->set_initializer( 0 );
     715                delete compLitExpr;
     716                DeclarationWithType * newtempvar = mutate( tempvar );
     717                addDeclaration( newtempvar );                                   // add modified temporary to current block
     718                return new VariableExpr( newtempvar );
     719        }
    691720} // namespace SymTab
    692721
Note: See TracChangeset for help on using the changeset viewer.