| 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 |
|
|---|
| 11 | #ifndef SYMTAB_INDEXER_H
|
|---|
| 12 | #define SYMTAB_INDEXER_H
|
|---|
| 13 |
|
|---|
| 14 | #include <list>
|
|---|
| 15 | #include <string>
|
|---|
| 16 | #include <map>
|
|---|
| 17 |
|
|---|
| 18 | #include "SynTree/Visitor.h"
|
|---|
| 19 | #include "IdTable.h"
|
|---|
| 20 | #include "AggregateTable.h"
|
|---|
| 21 | #include "TypeTable.h"
|
|---|
| 22 |
|
|---|
| 23 | namespace SymTab {
|
|---|
| 24 |
|
|---|
| 25 | class Indexer : public Visitor
|
|---|
| 26 | {
|
|---|
| 27 | public:
|
|---|
| 28 | Indexer( bool useDebug = false );
|
|---|
| 29 | virtual ~Indexer();
|
|---|
| 30 |
|
|---|
| 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 );
|
|---|
| 40 |
|
|---|
| 41 | virtual void visit( CompoundStmt *compoundStmt );
|
|---|
| 42 |
|
|---|
| 43 | virtual void visit( ContextInstType *contextInst );
|
|---|
| 44 | virtual void visit( StructInstType *contextInst );
|
|---|
| 45 | virtual void visit( UnionInstType *contextInst );
|
|---|
| 46 |
|
|---|
| 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;
|
|---|
| 58 |
|
|---|
| 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 |
|
|---|
| 72 | } // namespace SymTab
|
|---|
| 73 |
|
|---|
| 74 | #endif /* #ifndef SYMTAB_INDEXER_H */
|
|---|