Changeset cff1143 for src/SymTab


Ignore:
Timestamp:
Jul 9, 2015, 3:07:32 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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, string, with_gc
Children:
0215a76f, dfee306
Parents:
82dd287 (diff), e5609dd (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 plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/SymTab
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r82dd287 rcff1143  
    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; }
     
    162162        class EliminateTypedef : public Mutator {
    163163          public:
     164          EliminateTypedef() : scopeLevel( 0 ) {}
    164165                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    165166          private:
     
    171172                virtual Type *mutate( TypeInstType *aggregateUseType );
    172173                virtual Expression *mutate( CastExpr *castExpr );
    173  
    174                 std::map< std::string, TypedefDecl * > typedefNames;
     174
     175                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     176                TypedefMap typedefNames;
     177                int scopeLevel;
    175178        };
    176179
     
    589592                assignDecl2->fixUniqueId();
    590593
     594                // these should be built in the same way that the prelude
     595                // functions are, so build a list containing the prototypes
     596                // and allow MakeLibCfa to autogenerate the bodies.
    591597                std::list< Declaration * > assigns;
    592598                assigns.push_back( assignDecl );
     
    595601                LibCfa::makeLibCfa( assigns );
    596602
    597                 // need to remove the prototypes, since these can appear nested in a routine
     603                // need to remove the prototypes, since this may be nested in a routine
    598604                for (int start = 0, end = assigns.size()/2; start < end; start++) {
    599605                        delete assigns.front();
     
    602608
    603609                declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() );
    604 
    605                 // return assignDecl;
    606610        }
    607611
     
    802806
    803807        Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
    804                 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );
     808                // instances of typedef types will come here. If it is an instance
     809                // of a typdef type, link the instance to its actual type.
     810                TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() );
    805811                if ( def != typedefNames.end() ) {
    806                         Type *ret = def->second->get_base()->clone();
     812                        Type *ret = def->second.first->get_base()->clone();
    807813                        ret->get_qualifiers() += typeInst->get_qualifiers();
    808814                        delete typeInst;
     
    814820        Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
    815821                Declaration *ret = Mutator::mutate( tyDecl );
    816                 typedefNames[ tyDecl->get_name() ] = tyDecl;
     822                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     823                        // typedef to the same name from the same scope
     824                        // must be from the same type
     825
     826                        Type * t1 = tyDecl->get_base();
     827                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
     828                        if ( ! typeEquals( t1, t2, true ) ) {
     829                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
     830                        }
     831                } else {
     832                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     833                } // if
     834
    817835                // When a typedef is a forward declaration:
    818836                //    typedef struct screen SCREEN;
     
    833851
    834852        TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
    835                 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );
     853                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    836854                if ( i != typedefNames.end() ) {
    837855                        typedefNames.erase( i ) ;
     
    841859
    842860        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
    843                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     861                TypedefMap oldNames = typedefNames;
    844862                DeclarationWithType *ret = Mutator::mutate( funcDecl );
    845863                typedefNames = oldNames;
     
    848866
    849867        ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
    850                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     868                TypedefMap oldNames = typedefNames;
    851869                ObjectDecl *ret = Mutator::mutate( objDecl );
    852870                typedefNames = oldNames;
     
    855873
    856874        Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
    857                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     875                TypedefMap oldNames = typedefNames;
    858876                Expression *ret = Mutator::mutate( castExpr );
    859877                typedefNames = oldNames;
     
    862880
    863881        CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
    864                 std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     882                TypedefMap oldNames = typedefNames;
     883                scopeLevel += 1;
    865884                CompoundStmt *ret = Mutator::mutate( compoundStmt );
     885                scopeLevel -= 1;
    866886                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    867887                while ( i != compoundStmt->get_kids().end() ) {
  • src/SymTab/module.mk

    r82dd287 rcff1143  
    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.