Changeset 17cd4eb for translator/SymTab


Ignore:
Timestamp:
Jan 7, 2015, 6:04:42 PM (11 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
0b8cd722
Parents:
d9a0e76
Message:

fixed restrict, fixed parameter copy, introduced name table for types, changed variable after to string

Location:
translator/SymTab
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • translator/SymTab/Indexer.cc

    rd9a0e76 r17cd4eb  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Indexer.cc,v 1.12 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
    7 
    81#include "SynTree/Declaration.h"
    92#include "SynTree/Type.h"
     
    158#include "utility.h"
    169
    17 #define debugPrint(x) if( doDebug ) { std::cout << x; }
     10#define debugPrint(x) if ( doDebug ) { std::cout << x; }
    1811
    1912namespace SymTab {
    20 
    21 Indexer::Indexer( bool useDebug )
    22   : doDebug( useDebug )
    23 {
    24 }
    25 
    26 Indexer::~Indexer()
    27 {
    28 }
    29 
    30 void
    31 Indexer::visit( ObjectDecl *objectDecl )
    32 {
    33   maybeAccept( objectDecl->get_type(), *this );
    34   maybeAccept( objectDecl->get_init(), *this );
    35   maybeAccept( objectDecl->get_bitfieldWidth(), *this );
    36   if( objectDecl->get_name() != "" ) {
    37     debugPrint( "Adding object " << objectDecl->get_name() << std::endl );
    38     idTable.addDecl( objectDecl );
    39   }
    40 }
    41 
    42 void
    43 Indexer::visit( FunctionDecl *functionDecl )
    44 {
    45   if( functionDecl->get_name() == "" ) return;
    46   debugPrint( "Adding function " << functionDecl->get_name() << std::endl );
    47   idTable.addDecl( functionDecl );
    48   enterScope();
    49   maybeAccept( functionDecl->get_functionType(), *this );
    50   acceptAll( functionDecl->get_oldDecls(), *this );
    51   maybeAccept( functionDecl->get_statements(), *this );
    52   leaveScope();
    53 }
     13    Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}
     14
     15    Indexer::~Indexer() {}
     16
     17    void Indexer::visit( ObjectDecl *objectDecl ) {
     18        maybeAccept( objectDecl->get_type(), *this );
     19        maybeAccept( objectDecl->get_init(), *this );
     20        maybeAccept( objectDecl->get_bitfieldWidth(), *this );
     21        if ( objectDecl->get_name() != "" ) {
     22            debugPrint( "Adding object " << objectDecl->get_name() << std::endl );
     23            idTable.addDecl( objectDecl );
     24        }
     25    }
     26
     27    void Indexer::visit( FunctionDecl *functionDecl ) {
     28        if ( functionDecl->get_name() == "" ) return;
     29        debugPrint( "Adding function " << functionDecl->get_name() << std::endl );
     30        idTable.addDecl( functionDecl );
     31        enterScope();
     32        maybeAccept( functionDecl->get_functionType(), *this );
     33        acceptAll( functionDecl->get_oldDecls(), *this );
     34        maybeAccept( functionDecl->get_statements(), *this );
     35        leaveScope();
     36    }
    5437
    5538/********
     
    7255 */
    7356
    74 void
    75 Indexer::visit( TypeDecl *typeDecl )
    76 {
    77   // see A NOTE ON THE ORDER OF TRAVERSAL, above
    78   // note that assertions come after the type is added to the symtab, since they aren't part
    79   // of the type proper and may depend on the type itself
    80   enterScope();
    81   acceptAll( typeDecl->get_parameters(), *this );
    82   maybeAccept( typeDecl->get_base(), *this );
    83   leaveScope();
    84   debugPrint( "Adding type " << typeDecl->get_name() << std::endl );
    85   typeTable.add( typeDecl );
    86   acceptAll( typeDecl->get_assertions(), *this );
    87 }
    88 
    89 void
    90 Indexer::visit( TypedefDecl *typeDecl )
    91 {
    92   enterScope();
    93   acceptAll( typeDecl->get_parameters(), *this );
    94   maybeAccept( typeDecl->get_base(), *this );
    95   leaveScope();
    96   debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );
    97   typeTable.add( typeDecl );
    98 }
    99 
    100 void
    101 Indexer::visit( StructDecl *aggregateDecl )
    102 {
    103   // make up a forward declaration and add it before processing the members
    104   StructDecl fwdDecl( aggregateDecl->get_name() );
    105   cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    106   debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
    107   structTable.add( &fwdDecl );
    108  
    109   enterScope();
    110   acceptAll( aggregateDecl->get_parameters(), *this );
    111   acceptAll( aggregateDecl->get_members(), *this );
    112   leaveScope();
    113  
    114   debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
    115   // this addition replaces the forward declaration
    116   structTable.add( aggregateDecl );
    117 }
    118 
    119 void
    120 Indexer::visit( UnionDecl *aggregateDecl )
    121 {
    122   // make up a forward declaration and add it before processing the members
    123   UnionDecl fwdDecl( aggregateDecl->get_name() );
    124   cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    125   debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
    126   unionTable.add( &fwdDecl );
    127  
    128   enterScope();
    129   acceptAll( aggregateDecl->get_parameters(), *this );
    130   acceptAll( aggregateDecl->get_members(), *this );
    131   leaveScope();
    132  
    133   debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
    134   unionTable.add( aggregateDecl );
    135 }
    136 
    137 void
    138 Indexer::visit( EnumDecl *aggregateDecl )
    139 {
    140   debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );
    141   enumTable.add( aggregateDecl );
    142   // unlike structs, contexts, and unions, enums inject their members into the
    143   // global scope
    144   acceptAll( aggregateDecl->get_members(), *this );
    145 }
    146 
    147 void
    148 Indexer::visit( ContextDecl *aggregateDecl )
    149 {
    150   enterScope();
    151   acceptAll( aggregateDecl->get_parameters(), *this );
    152   acceptAll( aggregateDecl->get_members(), *this );
    153   leaveScope();
    154  
    155   debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
    156   contextTable.add( aggregateDecl );
    157 }
    158 
    159 void
    160 Indexer::visit( CompoundStmt *compoundStmt )
    161 {
    162   enterScope();
    163   acceptAll( compoundStmt->get_kids(), *this );
    164   leaveScope();
    165 }
    166 
    167 void
    168 Indexer::visit( ContextInstType *contextInst )
    169 {
    170   acceptAll( contextInst->get_parameters(), *this );
    171   acceptAll( contextInst->get_members(), *this );
    172 }
    173 
    174 void
    175 Indexer::visit( StructInstType *structInst )
    176 {
    177   if( !structTable.lookup( structInst->get_name() ) ) {
    178     debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl );
    179     structTable.add( structInst->get_name() );
    180   }
    181   enterScope();
    182   acceptAll( structInst->get_parameters(), *this );
    183   leaveScope();
    184 }
    185 
    186 void
    187 Indexer::visit( UnionInstType *unionInst )
    188 {
    189   if( !unionTable.lookup( unionInst->get_name() ) ) {
    190     debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl );
    191     unionTable.add( unionInst->get_name() );
    192   }
    193   enterScope();
    194   acceptAll( unionInst->get_parameters(), *this );
    195   leaveScope();
    196 }
    197 
    198 void
    199 Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const
    200 {
    201   idTable.lookupId( id, list );
    202 }
    203 
    204 NamedTypeDecl *
    205 Indexer::lookupType( const std::string &id ) const
    206 {
    207   return typeTable.lookup( id );
    208 }
    209 
    210 StructDecl *
    211 Indexer::lookupStruct( const std::string &id ) const
    212 {
    213   return structTable.lookup( id );
    214 }
    215 
    216 EnumDecl *
    217 Indexer::lookupEnum( const std::string &id ) const
    218 {
    219   return enumTable.lookup( id );
    220 }
    221 
    222 UnionDecl *
    223 Indexer::lookupUnion( const std::string &id ) const
    224 {
    225   return unionTable.lookup( id );
    226 }
    227 
    228 ContextDecl *
    229 Indexer::lookupContext( const std::string &id ) const
    230 {
    231   return contextTable.lookup( id );
    232 }
    233 
    234 void
    235 Indexer::enterScope()
    236 {
    237   if( doDebug ) {
    238     std::cout << "--- Entering scope" << std::endl;
    239   }
    240   idTable.enterScope();
    241   typeTable.enterScope();
    242   structTable.enterScope();
    243   enumTable.enterScope();
    244   unionTable.enterScope();
    245   contextTable.enterScope();
    246 }
    247 
    248 void
    249 Indexer::leaveScope()
    250 {
    251   using std::cout;
    252   using std::endl;
    253  
    254   if( doDebug ) {
    255     cout << "--- Leaving scope containing" << endl;
    256     idTable.dump( cout );
    257     typeTable.dump( cout );
    258     structTable.dump( cout );
    259     enumTable.dump( cout );
    260     unionTable.dump( cout );
    261     contextTable.dump( cout );
    262   }
    263   idTable.leaveScope();
    264   typeTable.leaveScope();
    265   structTable.leaveScope();
    266   enumTable.leaveScope();
    267   unionTable.leaveScope();
    268   contextTable.leaveScope();
    269 }
    270 
    271 void
    272 Indexer::print( std::ostream &os, int indent ) const
    273 {
    274     idTable.dump( os );
    275     typeTable.dump( os );
    276     structTable.dump( os );
    277     enumTable.dump( os );
    278     unionTable.dump( os );
    279     contextTable.dump( os );
    280 }
    281 
     57    void Indexer::visit( TypeDecl *typeDecl ) {
     58        // see A NOTE ON THE ORDER OF TRAVERSAL, above
     59        // note that assertions come after the type is added to the symtab, since they aren't part
     60        // of the type proper and may depend on the type itself
     61        enterScope();
     62        acceptAll( typeDecl->get_parameters(), *this );
     63        maybeAccept( typeDecl->get_base(), *this );
     64        leaveScope();
     65        debugPrint( "Adding type " << typeDecl->get_name() << std::endl );
     66        typeTable.add( typeDecl );
     67        acceptAll( typeDecl->get_assertions(), *this );
     68    }
     69
     70    void Indexer::visit( TypedefDecl *typeDecl ) {
     71        enterScope();
     72        acceptAll( typeDecl->get_parameters(), *this );
     73        maybeAccept( typeDecl->get_base(), *this );
     74        leaveScope();
     75        debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );
     76        typeTable.add( typeDecl );
     77    }
     78
     79    void Indexer::visit( StructDecl *aggregateDecl ) {
     80        // make up a forward declaration and add it before processing the members
     81        StructDecl fwdDecl( aggregateDecl->get_name() );
     82        cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
     83        debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
     84        structTable.add( &fwdDecl );
     85 
     86        enterScope();
     87        acceptAll( aggregateDecl->get_parameters(), *this );
     88        acceptAll( aggregateDecl->get_members(), *this );
     89        leaveScope();
     90 
     91        debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
     92        // this addition replaces the forward declaration
     93        structTable.add( aggregateDecl );
     94    }
     95
     96    void Indexer::visit( UnionDecl *aggregateDecl ) {
     97        // make up a forward declaration and add it before processing the members
     98        UnionDecl fwdDecl( aggregateDecl->get_name() );
     99        cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
     100        debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
     101        unionTable.add( &fwdDecl );
     102 
     103        enterScope();
     104        acceptAll( aggregateDecl->get_parameters(), *this );
     105        acceptAll( aggregateDecl->get_members(), *this );
     106        leaveScope();
     107 
     108        debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
     109        unionTable.add( aggregateDecl );
     110    }
     111
     112    void Indexer::visit( EnumDecl *aggregateDecl ) {
     113        debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );
     114        enumTable.add( aggregateDecl );
     115        // unlike structs, contexts, and unions, enums inject their members into the global scope
     116        acceptAll( aggregateDecl->get_members(), *this );
     117    }
     118
     119    void Indexer::visit( ContextDecl *aggregateDecl ) {
     120        enterScope();
     121        acceptAll( aggregateDecl->get_parameters(), *this );
     122        acceptAll( aggregateDecl->get_members(), *this );
     123        leaveScope();
     124 
     125        debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
     126        contextTable.add( aggregateDecl );
     127    }
     128
     129    void Indexer::visit( CompoundStmt *compoundStmt ) {
     130        enterScope();
     131        acceptAll( compoundStmt->get_kids(), *this );
     132        leaveScope();
     133    }
     134
     135    void Indexer::visit( ContextInstType *contextInst ) {
     136        acceptAll( contextInst->get_parameters(), *this );
     137        acceptAll( contextInst->get_members(), *this );
     138    }
     139
     140    void Indexer::visit( StructInstType *structInst ) {
     141        if ( ! structTable.lookup( structInst->get_name() ) ) {
     142            debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl );
     143            structTable.add( structInst->get_name() );
     144        }
     145        enterScope();
     146        acceptAll( structInst->get_parameters(), *this );
     147        leaveScope();
     148    }
     149
     150    void Indexer::visit( UnionInstType *unionInst ) {
     151        if ( ! unionTable.lookup( unionInst->get_name() ) ) {
     152            debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl );
     153            unionTable.add( unionInst->get_name() );
     154        }
     155        enterScope();
     156        acceptAll( unionInst->get_parameters(), *this );
     157        leaveScope();
     158    }
     159
     160    void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {
     161        idTable.lookupId( id, list );
     162    }
     163
     164    NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
     165        return typeTable.lookup( id );
     166    }
     167
     168    StructDecl *Indexer::lookupStruct( const std::string &id ) const {
     169        return structTable.lookup( id );
     170    }
     171
     172    EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
     173        return enumTable.lookup( id );
     174    }
     175
     176    UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
     177        return unionTable.lookup( id );
     178    }
     179
     180    ContextDecl  * Indexer::lookupContext( const std::string &id ) const {
     181        return contextTable.lookup( id );
     182    }
     183
     184    void Indexer::enterScope() {
     185        if ( doDebug ) {
     186            std::cout << "--- Entering scope" << std::endl;
     187        }
     188        idTable.enterScope();
     189        typeTable.enterScope();
     190        structTable.enterScope();
     191        enumTable.enterScope();
     192        unionTable.enterScope();
     193        contextTable.enterScope();
     194    }
     195
     196    void Indexer::leaveScope() {
     197        using std::cout;
     198        using std::endl;
     199 
     200        if ( doDebug ) {
     201            cout << "--- Leaving scope containing" << endl;
     202            idTable.dump( cout );
     203            typeTable.dump( cout );
     204            structTable.dump( cout );
     205            enumTable.dump( cout );
     206            unionTable.dump( cout );
     207            contextTable.dump( cout );
     208        }
     209        idTable.leaveScope();
     210        typeTable.leaveScope();
     211        structTable.leaveScope();
     212        enumTable.leaveScope();
     213        unionTable.leaveScope();
     214        contextTable.leaveScope();
     215    }
     216
     217    void Indexer::print( std::ostream &os, int indent ) const {
     218        idTable.dump( os );
     219        typeTable.dump( os );
     220        structTable.dump( os );
     221        enumTable.dump( os );
     222        unionTable.dump( os );
     223        contextTable.dump( os );
     224    }
    282225} // namespace SymTab
  • translator/SymTab/Indexer.h

    rd9a0e76 r17cd4eb  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * A class that indexes the syntax tree.  It is intended to be subclassed by a visitor class
    5  * that wants to use the index.
    6  *
    7  * $Id: Indexer.h,v 1.9 2005/08/29 20:14:18 rcbilson Exp $
    8  *
    9  */
    10 
    111#ifndef SYMTAB_INDEXER_H
    122#define SYMTAB_INDEXER_H
     
    2212
    2313namespace SymTab {
     14    class Indexer : public Visitor {
     15      public:
     16        Indexer( bool useDebug = false );
     17        virtual ~Indexer();
    2418
    25 class Indexer : public Visitor
    26 {
    27 public:
    28   Indexer( bool useDebug = false );
    29   virtual ~Indexer();
     19        //using Visitor::visit;
     20        virtual void visit( ObjectDecl *objectDecl );
     21        virtual void visit( FunctionDecl *functionDecl );
     22        virtual void visit( TypeDecl *typeDecl );
     23        virtual void visit( TypedefDecl *typeDecl );
     24        virtual void visit( StructDecl *aggregateDecl );
     25        virtual void visit( UnionDecl *aggregateDecl );
     26        virtual void visit( EnumDecl *aggregateDecl );
     27        virtual void visit( ContextDecl *aggregateDecl );
    3028
    31 ///   using Visitor::visit;
    32   virtual void visit( ObjectDecl *objectDecl );
    33   virtual void visit( FunctionDecl *functionDecl );
    34   virtual void visit( TypeDecl *typeDecl );
    35   virtual void visit( TypedefDecl *typeDecl );
    36   virtual void visit( StructDecl *aggregateDecl );
    37   virtual void visit( UnionDecl *aggregateDecl );
    38   virtual void visit( EnumDecl *aggregateDecl );
    39   virtual void visit( ContextDecl *aggregateDecl );
     29        virtual void visit( CompoundStmt *compoundStmt );
    4030
    41   virtual void visit( CompoundStmt *compoundStmt );
     31        virtual void visit( ContextInstType *contextInst );
     32        virtual void visit( StructInstType *contextInst );
     33        virtual void visit( UnionInstType *contextInst );
     34 
     35        // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
     36        // explicitly when scopes begin and end
     37        void enterScope();
     38        void leaveScope();
    4239
    43   virtual void visit( ContextInstType *contextInst );
    44   virtual void visit( StructInstType *contextInst );
    45   virtual void visit( UnionInstType *contextInst );
     40        void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const;
     41        NamedTypeDecl *lookupType( const std::string &id ) const;
     42        StructDecl *lookupStruct( const std::string &id ) const;
     43        EnumDecl *lookupEnum( const std::string &id ) const;
     44        UnionDecl *lookupUnion( const std::string &id ) const;
     45        ContextDecl *lookupContext( const std::string &id ) const;
    4646 
    47   // when using an indexer manually (e.g., within a mutator traversal), it is
    48   // necessary to tell the indexer explicitly when scopes begin and end
    49   void enterScope();
    50   void leaveScope();
    51 
    52   void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const;
    53   NamedTypeDecl *lookupType( const std::string &id ) const;
    54   StructDecl *lookupStruct( const std::string &id ) const;
    55   EnumDecl *lookupEnum( const std::string &id ) const;
    56   UnionDecl *lookupUnion( const std::string &id ) const;
    57   ContextDecl *lookupContext( const std::string &id ) const;
     47        void print( std::ostream &os, int indent = 0 ) const;
     48      private:
     49        IdTable idTable;
     50        TypeTable typeTable;
     51        StructTable structTable;
     52        EnumTable enumTable;
     53        UnionTable unionTable;
     54        ContextTable contextTable;
    5855 
    59   void print( std::ostream &os, int indent = 0 ) const;
    60 
    61  private:
    62   IdTable idTable;
    63   TypeTable typeTable;
    64   StructTable structTable;
    65   EnumTable enumTable;
    66   UnionTable unionTable;
    67   ContextTable contextTable;
    68  
    69   bool doDebug;         // display debugging trace
    70 };
    71 
     56        bool doDebug;                                   // display debugging trace
     57    };
    7258} // namespace SymTab
    7359
  • translator/SymTab/Validate.cc

    rd9a0e76 r17cd4eb  
    185185            if ( ! visitor.get_declsToAdd().empty() ) {
    186186                translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
    187             }
     187            } // if
    188188            i = next;
    189         }
     189        } // while
    190190    }
    191191
     
    206206                if ( doDelete ) {
    207207                    delete *i;
    208                 }
     208                } // if
    209209                declList.erase( i );
    210             }
     210            } // if
    211211            i = next;
    212         }
     212        } // while
    213213    }
    214214
     
    227227            Visitor::visit( aggregateDecl );
    228228            inStruct = false;
    229         }
     229        } // if
    230230        // Always remove the hoisted aggregate from the inner structure.
    231231        filter( aggregateDecl->get_members(), isStructOrUnion, false );
     
    275275        // Set the type of each member of the enumeration to be EnumConstant
    276276 
    277         for( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     277        for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
    278278            ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i );
    279279            assert( obj );
    280280            obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false ), enumDecl->get_name() ) );
    281         }
     281        } // for
    282282        Parent::visit( enumDecl );
    283283    }
     
    285285    namespace {
    286286        template< typename DWTIterator >
    287         void
    288         fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) {
     287        void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) {
    289288            // the only case in which "void" is valid is where it is the only one in the list; then
    290289            // it should be removed entirely
     
    300299                if ( i != end ) {
    301300                    throw SemanticError( "invalid type void in function type ", func );
    302                 }
     301                } // if
    303302            } else {
    304303                ++i;
    305                 for( ; i != end; ++i ) {
     304                for ( ; i != end; ++i ) {
    306305                    FixFunction fixer;
    307306                    *i = (*i )->acceptMutator( fixer );
    308307                    if ( fixer.get_isVoid() ) {
    309308                        throw SemanticError( "invalid type void in function type ", func );
    310                     }
    311                 }
    312             }
     309                    } // if
     310                } // for
     311            } // if
    313312        }
    314313    }
     
    326325        } else {
    327326            indexer = this;
    328         }
     327        } // if
    329328    }
    330329
     
    336335            assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
    337336            structInst->set_baseStruct( st );
    338         }
     337        } // if
    339338        if ( ! st || st->get_members().empty() ) {
    340339            // use of forward declaration
    341340            forwardStructs[ structInst->get_name() ].push_back( structInst );
    342         }
     341        } // if
    343342    }
    344343
     
    349348        if ( un ) {
    350349            unionInst->set_baseUnion( un );
    351         }
     350        } // if
    352351        if ( ! un || un->get_members().empty() ) {
    353352            // use of forward declaration
    354353            forwardUnions[ unionInst->get_name() ].push_back( unionInst );
    355         }
     354        } // if
    356355    }
    357356
     
    361360        if ( ! ctx ) {
    362361            throw SemanticError( "use of undeclared context " + contextInst->get_name() );
    363         }
    364         for( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
    365             for( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
     362        } // if
     363        for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
     364            for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    366365                if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) {
    367366                    cloneAll( otherCtx->get_members(), contextInst->get_members() );
    368367                } else {
    369368                    contextInst->get_members().push_back( (*assert )->clone() );
    370                 }
    371             }
    372         }
     369                } // if
     370            } // for
     371        } // for
    373372        applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
    374373    }
     
    378377            ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
    379378            if ( fwds != forwardStructs.end() ) {
    380                 for( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
     379                for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    381380                    (*inst )->set_baseStruct( structDecl );
    382                 }
     381                } // for
    383382                forwardStructs.erase( fwds );
    384             }
    385         }
     383            } // if
     384        } // if
    386385        Indexer::visit( structDecl );
    387386    }
     
    391390            ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
    392391            if ( fwds != forwardUnions.end() ) {
    393                 for( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
     392                for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    394393                    (*inst )->set_baseUnion( unionDecl );
    395                 }
     394                } // for
    396395                forwardUnions.erase( fwds );
    397             }
    398         }
     396            } // if
     397        } // if
    399398        Indexer::visit( unionDecl );
    400399    }
     
    404403            if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
    405404                typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
    406             }
    407         }
     405            } // if
     406        } // if
    408407    }
    409408
     
    413412        } else {
    414413            indexer = this;
    415         }
     414        } // if
    416415    }
    417416
    418417    void forallFixer( Type *func ) {
    419418        // Fix up assertions
    420         for( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
     419        for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
    421420            std::list< DeclarationWithType * > toBeDone, nextRound;
    422421            toBeDone.splice( toBeDone.end(), (*type )->get_assertions() );
    423422            while ( ! toBeDone.empty() ) {
    424                 for( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
     423                for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
    425424                    if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) {
    426                         for( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
     425                        for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
    427426                            DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );
    428427                            assert( dwt );
     
    449448        if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
    450449            forallFixer( pointer->get_base() );
    451         }
     450        } // if
    452451        Parent::visit( object );
    453452        object->fixUniqueId();
     
    546545        assignDecl->fixUniqueId();
    547546 
    548         for( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
     547        for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
    549548            if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) {
    550549                if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
     
    552551                } else {
    553552                    makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
    554                 }
    555             }
    556         }
     553                } // if
     554            } // if
     555        } // for
    557556        assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    558557 
     
    594593            declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
    595594            structsDone.insert( structDecl->get_name() );
    596         }
     595        } // if
    597596    }
    598597
     
    602601            unionInst->set_baseUnion( unionDecl );
    603602            declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
    604         }
     603        } // if
    605604    }
    606605
     
    617616            assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) );
    618617            stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) );
    619         }
     618        } // if
    620619        FunctionType *type = new FunctionType( Type::Qualifiers(), false );
    621620        type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) );
     
    628627    void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) {
    629628        if ( ! declsToAdd.empty() ) {
    630             for( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
     629            for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
    631630                statements.insert( i, new DeclStmt( noLabels, *decl ) );
    632             }
     631            } // for
    633632            declsToAdd.clear();
    634         }
     633        } // if
    635634    }
    636635
    637636    void AddStructAssignment::visit( FunctionType *) {
    638         // ensure that we don't add assignment ops for types defined
    639         // as part of the function
     637        // ensure that we don't add assignment ops for types defined as part of the function
    640638    }
    641639
    642640    void AddStructAssignment::visit( PointerType *) {
    643         // ensure that we don't add assignment ops for types defined
    644         // as part of the pointer
     641        // ensure that we don't add assignment ops for types defined as part of the pointer
    645642    }
    646643
    647644    void AddStructAssignment::visit( ContextDecl *) {
    648         // ensure that we don't add assignment ops for types defined
    649         // as part of the context
     645        // ensure that we don't add assignment ops for types defined as part of the context
    650646    }
    651647
     
    714710            delete typeInst;
    715711            return ret;
    716         }
     712        } // if
    717713        return typeInst;
    718714    }
     
    721717        Declaration *ret = Mutator::mutate( tyDecl );
    722718        typedefNames[ tyDecl->get_name() ] = tyDecl;
    723         if ( AggregateDecl *aggDecl = dynamic_cast< AggregateDecl * >( tyDecl->get_base() ) ) {
    724             tyDecl->set_base( 0 );
    725             delete tyDecl;
    726             return aggDecl;
     719        // When a typedef is a forward declaration:
     720        //    typedef struct screen SCREEN;
     721        // the declaration portion must be retained:
     722        //    struct screen;
     723        // because the expansion of the typedef is:
     724        //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
     725        // hence the type-name "screen" must be defined.
     726        // Note, qualifiers on the typedef are superfluous for the forward declaration.
     727        if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( tyDecl->get_base() ) ) {
     728            return new StructDecl( aggDecl->get_name() );
     729        } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( tyDecl->get_base() ) ) {
     730            return new UnionDecl( aggDecl->get_name() );
    727731        } else {
    728732            return ret;
    729         }
     733        } // if
    730734    }
    731735
     
    734738        if ( i != typedefNames.end() ) {
    735739            typedefNames.erase( i ) ;
    736         }
     740        } // if
    737741        return typeDecl;
    738742    }
     
    770774                    delete *i;
    771775                    compoundStmt->get_kids().erase( i );
    772                 }
    773             }
     776                } // if
     777            } // if
    774778            i = next;
    775         }
     779        } // while
    776780        typedefNames = oldNames;
    777781        return ret;
Note: See TracChangeset for help on using the changeset viewer.