source: src/Parser/TypedefTable.cc @ 94b1022a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 94b1022a was 2f0a0678, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

simplify TypedefTable?

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// TypedefTable.cc --
8//
[7fdb94e]9// Author           : Peter A. Buhr
[b87a5ed]10// Created On       : Sat May 16 15:20:13 2015
11// Last Modified By : Peter A. Buhr
[2f0a0678]12// Last Modified On : Tue May 22 08:40:01 2018
13// Update Count     : 121
[b87a5ed]14//
15
[d180746]16
[984dce6]17#include "TypedefTable.h"
[2f0a0678]18#include <cassert>                                                                              // for assert
[51b7345]19
20#if 0
21#include <iostream>
[721f17a]22#define debugPrint( x ) cerr << x
[51b7345]23#else
[b87a5ed]24#define debugPrint( x )
[51b7345]25#endif
26
[2f0a0678]27using namespace std;                                                                    // string, iostream
[51b7345]28
[7fdb94e]29TypedefTable::~TypedefTable() {
30        if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) {
31                // std::cerr << "scope failure " << kindTable.currentScope() << endl;
32        } // if
33} // TypedefTable::~TypedefTable
34
35bool TypedefTable::exists( const string & identifier ) {
36        return kindTable.find( identifier ) != kindTable.end();
37} // TypedefTable::exists
[984dce6]38
[7fdb94e]39int TypedefTable::isKind( const string & identifier ) const {
40        KindTable::const_iterator posn = kindTable.find( identifier );
[2f0a0678]41        // Name lookup defaults to identifier, and then the identifier's kind is set by the parser.
[7fdb94e]42        if ( posn == kindTable.end() ) return IDENTIFIER;
43        return posn->second;
44} // TypedefTable::isKind
[45161b4d]45
[2f0a0678]46void TypedefTable::changeKind( const string & identifier, int kind ) {
[7fdb94e]47        KindTable::iterator posn = kindTable.find( identifier );
[2f0a0678]48        if ( posn != kindTable.end() ) posn->second = kind;     // exists => update
[7fdb94e]49} // TypedefTable::changeKind
[721f17a]50
[45161b4d]51// SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
[7fdb94e]52// "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if the
53// name is explicitly used.
54void TypedefTable::makeTypedef( const string & name ) {
[45161b4d]55        if ( ! typedefTable.exists( name ) ) {
[2f0a0678]56                typedefTable.addToEnclosingScope( name, TYPEDEFname );
[45161b4d]57        } // if
[7fdb94e]58} // TypedefTable::makeTypedef
59
[2f0a0678]60void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) {
[7fdb94e]61        assert( kindTable.currentScope() >= 1 );
62        auto scope = kindTable.currentScope() - 1;
63        debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl );
64        auto ret = kindTable.insertAt( scope, identifier, kind );
[2f0a0678]65        if ( ! ret.second ) ret.first->second = kind;           // exists => update
[7fdb94e]66} // TypedefTable::addToEnclosingScope
[51b7345]67
[de62360d]68void TypedefTable::enterScope() {
[7fdb94e]69        kindTable.beginScope();
70        debugPrint( "Entering scope " << kindTable.currentScope() << endl );
71} // TypedefTable::enterScope
[51b7345]72
[de62360d]73void TypedefTable::leaveScope() {
[7fdb94e]74        debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
75        kindTable.endScope();
76} // TypedefTable::leaveScope
77
78// void TypedefTable::print( void ) const {
79//      for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) {
80//              debugPrint( (*i ).first << ": " );
81//              list< Entry > declList = (*i).second;
82//              for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
83//                      debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
84//              }
85//              debugPrint( endl );
86//      } // for
87// }
[b87a5ed]88
89// Local Variables: //
90// tab-width: 4 //
91// mode: c++ //
92// compile-command: "make install" //
93// End: //
Note: See TracBrowser for help on using the repository browser.