Ignore:
Timestamp:
Nov 13, 2014, 3:09:54 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
c8ffe20b
Parents:
134b86a
Message:

add quoted identifiers, add compilation include directory, reformatted some files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/TypedefTable.cc

    r134b86a r8c17ab0  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypedefTable.cc,v 1.7 2004/09/14 17:21:12 rcbilson Exp $
    5  *
    6  */
    7 
    81#include <map>
    92#include <list>
     
    1912#endif
    2013
    21 TypedefTable::TypedefTable()
    22     : currentScope(0)
    23 {
    24 }
     14TypedefTable::TypedefTable() : currentScope(0) {}
    2515
    26 bool
    27 TypedefTable::isKind(string identifier, kind_t kind) const
    28 {
     16bool TypedefTable::isKind(string identifier, kind_t kind) const {
    2917    tableType::const_iterator id_pos = table.find(identifier);
    3018    if (id_pos == table.end()) {
     
    3523}
    3624
    37 bool
    38 TypedefTable::isIdentifier(string identifier) const
    39 {
     25bool TypedefTable::isIdentifier(string identifier) const {
    4026    return isKind(identifier, ID);
    4127}
    4228
    43 bool
    44 TypedefTable::isTypedef(string identifier) const
    45 {
     29bool TypedefTable::isTypedef(string identifier) const {
    4630    return isKind(identifier, TD);
    4731}
    4832
    49 bool
    50 TypedefTable::isTypegen(string identifier) const
    51 {
     33bool TypedefTable::isTypegen(string identifier) const {
    5234    return isKind(identifier, TG);
    5335}
    5436
    55 void
    56 TypedefTable::addToScope(const std::string &identifier, kind_t kind, int scope)
    57 {
    58   if( currentContext != "" && scope == contextScope ) {
    59     DeferredEntry entry = { identifier, kind };
    60     contexts[currentContext].push_back( entry );
    61   } else {
    62     debugPrint( "Adding " << identifier << " as type " << kind << " scope " << scope << " from scope " << currentScope << endl );
    63     Entry newEntry = { scope, kind };
    64     tableType::iterator curPos = table.find(identifier);
    65     if (curPos == table.end()) {
    66       list<Entry> newList;
    67       newList.push_front(newEntry);
    68       table[identifier] = newList;
     37void TypedefTable::addToScope(const std::string &identifier, kind_t kind, int scope) {
     38    if ( currentContext != "" && scope == contextScope ) {
     39        DeferredEntry entry = { identifier, kind };
     40        contexts[currentContext].push_back( entry );
    6941    } else {
    70       list<Entry>::iterator listPos = (*curPos).second.begin();
    71       while( listPos != (*curPos).second.end() && listPos->scope > scope ) {
    72         listPos++;
    73       }
    74       (*curPos).second.insert(listPos, newEntry);
     42        debugPrint( "Adding " << identifier << " as type " << kind << " scope " << scope << " from scope " << currentScope << endl );
     43        Entry newEntry = { scope, kind };
     44        tableType::iterator curPos = table.find(identifier);
     45        if (curPos == table.end()) {
     46            list<Entry> newList;
     47            newList.push_front(newEntry);
     48            table[identifier] = newList;
     49        } else {
     50            list<Entry>::iterator listPos = (*curPos).second.begin();
     51            while( listPos != (*curPos).second.end() && listPos->scope > scope ) {
     52                listPos++;
     53            }
     54            (*curPos).second.insert(listPos, newEntry);
     55        }
    7556    }
    76   }
    7757}
    7858
    79 void
    80 TypedefTable::addToCurrentScope(const std::string &identifier, kind_t kind)
    81 {
    82   addToScope( identifier, kind, currentScope );
     59void TypedefTable::addToCurrentScope(const std::string &identifier, kind_t kind) {
     60    addToScope( identifier, kind, currentScope );
    8361}
    8462
    85 void
    86 TypedefTable::addToCurrentScope(kind_t kind)
    87 {
    88   addToCurrentScope( nextIdentifiers.top(), kind );
     63void TypedefTable::addToCurrentScope(kind_t kind) {
     64    addToCurrentScope( nextIdentifiers.top(), kind );
    8965}
    9066
    91 void
    92 TypedefTable::addToEnclosingScope(const std::string &identifier, kind_t kind)
    93 {
    94   assert( currentScope >= 1 );
    95   addToScope( identifier, kind, currentScope - 1 );
     67void TypedefTable::addToEnclosingScope(const std::string &identifier, kind_t kind) {
     68    assert( currentScope >= 1 );
     69    addToScope( identifier, kind, currentScope - 1 );
    9670}
    9771
    98 void
    99 TypedefTable::addToEnclosingScope(kind_t kind)
    100 {
    101   addToEnclosingScope( nextIdentifiers.top(), kind );
     72void TypedefTable::addToEnclosingScope(kind_t kind) {
     73    addToEnclosingScope( nextIdentifiers.top(), kind );
    10274}
    10375
    104 void
    105 TypedefTable::addToEnclosingScope2(const std::string &identifier, kind_t kind)
    106 {
    107   assert( currentScope >= 2 );
    108   addToScope( identifier, kind, currentScope - 2 );
     76void TypedefTable::addToEnclosingScope2(const std::string &identifier, kind_t kind) {
     77    assert( currentScope >= 2 );
     78    addToScope( identifier, kind, currentScope - 2 );
    10979}
    11080
    111 void
    112 TypedefTable::addToEnclosingScope2(kind_t kind)
    113 {
    114   addToEnclosingScope2( nextIdentifiers.top(), kind );
     81void TypedefTable::addToEnclosingScope2(kind_t kind) {
     82    addToEnclosingScope2( nextIdentifiers.top(), kind );
    11583}
    11684
    117 void
    118 TypedefTable::setNextIdentifier( const std::string &identifier )
    119 {
    120   nextIdentifiers.top() = identifier;
     85void TypedefTable::setNextIdentifier( const std::string &identifier ) {
     86    nextIdentifiers.top() = identifier;
    12187}
    12288
    123 void
    124 TypedefTable::openContext( std::string contextName )
    125 {
    126   map< string, deferListType >::iterator i = contexts.find( contextName );
    127   if( i != contexts.end() ) {
    128     deferListType &entries = i->second;
    129     for (deferListType::iterator i = entries.begin(); i != entries.end(); i++) {
    130       addToEnclosingScope( i->identifier, i->kind );
     89void TypedefTable::openContext( std::string contextName ) {
     90    map< string, deferListType >::iterator i = contexts.find( contextName );
     91    if ( i != contexts.end() ) {
     92        deferListType &entries = i->second;
     93        for (deferListType::iterator i = entries.begin(); i != entries.end(); i++) {
     94            addToEnclosingScope( i->identifier, i->kind );
     95        }
    13196    }
    132   }
    13397}
    13498
    135 void
    136 TypedefTable::enterScope(void)
    137 {
     99void TypedefTable::enterScope(void) {
    138100    currentScope += 1;
    139101    deferListStack.push( deferListType() );
     
    142104}
    143105
    144 void
    145 TypedefTable::leaveScope(void)
    146 {
     106void TypedefTable::leaveScope(void) {
    147107    debugPrint( "Leaving scope " << currentScope << endl );
    148108    for (tableType::iterator i = table.begin(); i != table.end(); i++) {
     
    151111            declList.pop_front();
    152112        }
    153         if( declList.empty() ) {
    154           table.erase( i );
     113        if ( declList.empty() ) {
     114            table.erase( i );
    155115        }
    156116    }
    157117    currentScope -= 1;
    158118    for (deferListType::iterator i = deferListStack.top().begin(); i != deferListStack.top().end(); i++) {
    159       addToCurrentScope( i->identifier, i->kind );
     119        addToCurrentScope( i->identifier, i->kind );
    160120    }
    161121    deferListStack.pop();
     
    164124}
    165125
    166 void
    167 TypedefTable::enterContext( std::string contextName )
    168 {
    169   currentContext = contextName;
    170   contextScope = currentScope;
     126void TypedefTable::enterContext( std::string contextName ) {
     127    currentContext = contextName;
     128    contextScope = currentScope;
    171129}
    172130
    173 void
    174 TypedefTable::leaveContext(void)
    175 {
    176   currentContext = "";
     131void TypedefTable::leaveContext(void) {
     132    currentContext = "";
    177133}
    178134
    179 void
    180 TypedefTable::print(void) const
    181 {
     135void TypedefTable::print(void) const {
    182136    for (tableType::const_iterator i = table.begin(); i != table.end(); i++) {
    183137        debugPrint( (*i).first << ": " );
Note: See TracChangeset for help on using the changeset viewer.