Changeset cc79d97


Ignore:
Timestamp:
Jul 8, 2015, 1:44:42 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, 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, resolv-new, string, with_gc
Children:
71bd8c6
Parents:
0a0a65b
Message:

incorrectly redefining a typedef will cause an error in most cases

Location:
src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.in

    r0a0a65b rcc79d97  
    160160        SymTab/cfa_cpp-FixFunction.$(OBJEXT) \
    161161        SymTab/cfa_cpp-ImplementationType.$(OBJEXT) \
     162        SymTab/cfa_cpp-TypeEquality.$(OBJEXT) \
    162163        SynTree/cfa_cpp-Type.$(OBJEXT) \
    163164        SynTree/cfa_cpp-VoidType.$(OBJEXT) \
     
    365366        SymTab/Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \
    366367        SymTab/FixFunction.cc SymTab/ImplementationType.cc \
    367         SynTree/Type.cc SynTree/VoidType.cc SynTree/BasicType.cc \
    368         SynTree/PointerType.cc SynTree/ArrayType.cc \
    369         SynTree/FunctionType.cc SynTree/ReferenceToType.cc \
    370         SynTree/TupleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \
    371         SynTree/Constant.cc SynTree/Expression.cc SynTree/TupleExpr.cc \
     368        SymTab/TypeEquality.cc SynTree/Type.cc SynTree/VoidType.cc \
     369        SynTree/BasicType.cc SynTree/PointerType.cc \
     370        SynTree/ArrayType.cc SynTree/FunctionType.cc \
     371        SynTree/ReferenceToType.cc SynTree/TupleType.cc \
     372        SynTree/TypeofType.cc SynTree/AttrType.cc SynTree/Constant.cc \
     373        SynTree/Expression.cc SynTree/TupleExpr.cc \
    372374        SynTree/CommaExpr.cc SynTree/TypeExpr.cc \
    373375        SynTree/ApplicationExpr.cc SynTree/AddressExpr.cc \
     
    666668SymTab/cfa_cpp-ImplementationType.$(OBJEXT): SymTab/$(am__dirstamp) \
    667669        SymTab/$(DEPDIR)/$(am__dirstamp)
     670SymTab/cfa_cpp-TypeEquality.$(OBJEXT): SymTab/$(am__dirstamp) \
     671        SymTab/$(DEPDIR)/$(am__dirstamp)
    668672SynTree/$(am__dirstamp):
    669673        @$(MKDIR_P) SynTree
     
    823827        -rm -f SymTab/cfa_cpp-Indexer.$(OBJEXT)
    824828        -rm -f SymTab/cfa_cpp-Mangler.$(OBJEXT)
     829        -rm -f SymTab/cfa_cpp-TypeEquality.$(OBJEXT)
    825830        -rm -f SymTab/cfa_cpp-Validate.$(OBJEXT)
    826831        -rm -f SynTree/cfa_cpp-AddressExpr.$(OBJEXT)
     
    931936@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/cfa_cpp-Indexer.Po@am__quote@
    932937@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/cfa_cpp-Mangler.Po@am__quote@
     938@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Po@am__quote@
    933939@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/cfa_cpp-Validate.Po@am__quote@
    934940@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/cfa_cpp-AddressExpr.Po@am__quote@
     
    19101916@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    19111917@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/cfa_cpp-ImplementationType.obj `if test -f 'SymTab/ImplementationType.cc'; then $(CYGPATH_W) 'SymTab/ImplementationType.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/ImplementationType.cc'; fi`
     1918
     1919SymTab/cfa_cpp-TypeEquality.o: SymTab/TypeEquality.cc
     1920@am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/cfa_cpp-TypeEquality.o -MD -MP -MF SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Tpo -c -o SymTab/cfa_cpp-TypeEquality.o `test -f 'SymTab/TypeEquality.cc' || echo '$(srcdir)/'`SymTab/TypeEquality.cc
     1921@am__fastdepCXX_TRUE@   $(am__mv) SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Tpo SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Po
     1922@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='SymTab/TypeEquality.cc' object='SymTab/cfa_cpp-TypeEquality.o' libtool=no @AMDEPBACKSLASH@
     1923@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1924@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/cfa_cpp-TypeEquality.o `test -f 'SymTab/TypeEquality.cc' || echo '$(srcdir)/'`SymTab/TypeEquality.cc
     1925
     1926SymTab/cfa_cpp-TypeEquality.obj: SymTab/TypeEquality.cc
     1927@am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/cfa_cpp-TypeEquality.obj -MD -MP -MF SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Tpo -c -o SymTab/cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi`
     1928@am__fastdepCXX_TRUE@   $(am__mv) SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Tpo SymTab/$(DEPDIR)/cfa_cpp-TypeEquality.Po
     1929@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='SymTab/TypeEquality.cc' object='SymTab/cfa_cpp-TypeEquality.obj' libtool=no @AMDEPBACKSLASH@
     1930@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1931@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi`
    19121932
    19131933SynTree/cfa_cpp-Type.o: SynTree/Type.cc
  • src/SymTab/Validate.cc

    r0a0a65b rcc79d97  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 07 10:41:23 2015
    13 // Update Count     : 136
     12// Last Modified On : Wed Jul 08 12:49:36 2015
     13// Update Count     : 166
    1414//
    1515
     
    4848#include "Indexer.h"
    4949#include "FixFunction.h"
    50 #include "ImplementationType.h"
     50// #include "ImplementationType.h"
    5151#include "utility.h"
    5252#include "UniqueName.h"
    5353#include "AddVisit.h"
    5454#include "MakeLibCfa.h"
    55 
     55#include "TypeEquality.h"
    5656
    5757#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    157157        class EliminateTypedef : public Mutator {
    158158          public:
     159          EliminateTypedef() : scopeLevel( 0 ) {}
    159160                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    160161          private:
     
    166167                virtual Type *mutate( TypeInstType *aggregateUseType );
    167168                virtual Expression *mutate( CastExpr *castExpr );
    168  
    169                 std::map< std::string, TypedefDecl * > typedefNames;
     169
     170                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     171                TypedefMap typedefNames;
     172                int scopeLevel;
    170173        };
    171174
     
    584587                assignDecl2->fixUniqueId();
    585588
     589                // these should be built in the same way that the prelude
     590                // functions are, so build a list containing the prototypes
     591                // and allow MakeLibCfa to autogenerate the bodies.
    586592                std::list< Declaration * > assigns;
    587593                assigns.push_back( assignDecl );
     
    590596                LibCfa::makeLibCfa( assigns );
    591597
    592                 // need to remove the prototypes, since these can appear nested in a routine
     598                // need to remove the prototypes, since this may be nested in a routine
    593599                for (int start = 0, end = assigns.size()/2; start < end; start++) {
    594600                        delete assigns.front();
     
    597603
    598604                declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() );
    599 
    600                 // return assignDecl;
    601605        }
    602606
     
    797801
    798802        Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
    799                 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );
     803                // instances of typedef types will come here. If it is an instance
     804                // of a typdef type, link the instance to its actual type.
     805                TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() );
    800806                if ( def != typedefNames.end() ) {
    801                         Type *ret = def->second->get_base()->clone();
     807                        Type *ret = def->second.first->get_base()->clone();
    802808                        ret->get_qualifiers() += typeInst->get_qualifiers();
    803809                        delete typeInst;
     
    809815        Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
    810816                Declaration *ret = Mutator::mutate( tyDecl );
    811                 typedefNames[ tyDecl->get_name() ] = tyDecl;
     817                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     818                        // typedef to the same name from the same scope
     819                        // must be from the same type
     820
     821                        Type * t1 = tyDecl->get_base();
     822                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
     823                        if ( ! typeEquals( t1, t2, true ) ) {
     824                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
     825                        }
     826                } else {
     827                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     828                } // if
     829
    812830                // When a typedef is a forward declaration:
    813831                //    typedef struct screen SCREEN;
     
    828846
    829847        TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
    830                 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );
     848                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    831849                if ( i != typedefNames.end() ) {
    832850                        typedefNames.erase( i ) ;
     
    836854
    837855        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
    838                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     856                TypedefMap oldNames = typedefNames;
    839857                DeclarationWithType *ret = Mutator::mutate( funcDecl );
    840858                typedefNames = oldNames;
     
    843861
    844862        ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
    845                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     863                TypedefMap oldNames = typedefNames;
    846864                ObjectDecl *ret = Mutator::mutate( objDecl );
    847865                typedefNames = oldNames;
     
    850868
    851869        Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
    852                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     870                TypedefMap oldNames = typedefNames;
    853871                Expression *ret = Mutator::mutate( castExpr );
    854872                typedefNames = oldNames;
     
    857875
    858876        CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
    859                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     877                TypedefMap oldNames = typedefNames;
     878                scopeLevel += 1;
    860879                CompoundStmt *ret = Mutator::mutate( compoundStmt );
     880                scopeLevel -= 1;
    861881                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    862882                while ( i != compoundStmt->get_kids().end() ) {
  • src/SymTab/module.mk

    r0a0a65b rcc79d97  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Mon Jun  1 17:53:50 2015
    14 ## Update Count     : 1
     12## Last Modified By : Rob Schluntz
     13## Last Modified On : Tue Jul 07 16:22:23 2015
     14## Update Count     : 2
    1515###############################################################################
    1616
     
    2020       SymTab/Validate.cc \
    2121       SymTab/FixFunction.cc \
    22        SymTab/ImplementationType.cc
    23 
     22       SymTab/ImplementationType.cc \
     23       SymTab/TypeEquality.cc
Note: See TracChangeset for help on using the changeset viewer.