Ignore:
Timestamp:
May 21, 2018, 10:48:05 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
b12c036
Parents:
4358c1e
Message:

rewrite TypedefTable?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypedefTable.h

    r4358c1e r7fdb94e  
    77// TypedefTable.h --
    88//
    9 // Author           : Rodolfo G. Esteves
     9// Author           : Peter A. Buhr
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:33:14 2017
    13 // Update Count     : 34
     12// Last Modified On : Mon May 21 20:28:01 2018
     13// Update Count     : 76
    1414//
    1515
    1616#pragma once
    1717
    18 #include <list>       // for list
    19 #include <map>        // for map, map<>::value_compare
    20 #include <stack>      // for stack
    21 #include <string>     // for string
     18#include <string>                                                                               // for string
    2219
     20#include "Common/ScopedMap.h"                                                   // for ScopedMap
    2321#include "ParserTypes.h"
    24 #include "parser.hh"  // for IDENTIFIER, TYPEDEFname, TYPEGENname
     22#include "parser.hh"                                                                    // for IDENTIFIER, TYPEDEFname, TYPEGENname
    2523
    2624class TypedefTable {
     
    2826        enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname };
    2927  private:
    30         struct Entry {
    31                 int scope;
    32                 kind_t kind;
    33         };
     28        typedef ScopedMap< std::string, kind_t > KindTable;
     29        KindTable kindTable;   
     30  public:
     31        ~TypedefTable();
    3432
    35         struct DeferredEntry {
    36                 std::string identifier;
    37                 kind_t kind;
    38         };
    39 
    40         typedef std::map< std::string, std::list< Entry > > tableType;
    41         tableType table;
    42 
    43         int currentScope;
    44         std::string currentTrait;
    45         int contextScope;
    46 
    47         typedef std::list< DeferredEntry > deferListType;
    48         std::stack< deferListType > deferListStack;
    49         std::map< std::string, deferListType > contexts;
    50 
    51         std::stack< std::string > nextIdentifiers;
    52 
    53         void addToScope( const std::string &identifier, kind_t kind, int scope );
    54   public:
    55         TypedefTable();
    56 
    57         bool exists( const std::string &identifier );
    58         int isKind( const std::string &identifier ) const;
    59         void changeKind( const std::string &identifier, kind_t kind );
    60 
    61         void makeTypedef( const std::string &name );
    62 
    63         // "addToCurrentScope" adds the identifier/type pair to the current scope. This does less than you think it does,
    64         // since each declaration is within its own scope.  Mostly useful for type parameters.
    65         void addToCurrentScope( const std::string &identifier, kind_t kind );
    66         void addToCurrentScope( kind_t kind );                  // use nextIdentifiers.top()
    67 
    68         // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current one.  This is the
    69         // right way to handle type and typedef names
    70         void addToEnclosingScope( const std::string &identifier, kind_t kind );
    71         void addToEnclosingScope( kind_t kind );                // use nextIdentifiers.top()
    72 
    73         // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope enclosing the the
    74         // current one.  This is the right way to handle assertion names
    75         void addToEnclosingScope2( const std::string &identifier, kind_t kind );
    76         void addToEnclosingScope2( kind_t kind );               // use nextIdentifiers.top()
    77 
    78         // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope
    79         void setNextIdentifier( const std::string &identifier );
    80 
    81         // dump the definitions from a pre-defined context into the current scope
    82         void openTrait( const std::string &contextName );
     33        bool exists( const std::string & identifier );
     34        int isKind( const std::string & identifier ) const;
     35        void changeKind( const std::string & identifier, kind_t kind );
     36        void makeTypedef( const std::string & name );
     37        void addToEnclosingScope( const std::string & identifier, kind_t kind );
    8338
    8439        void enterScope();
    8540        void leaveScope();
    86         void enterTrait( const std::string &contextName );
    87         void leaveTrait();
    88 
    89         void print() const;
    90 };
     41}; // TypedefTable
    9142
    9243// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.