source: src/Parser/TypedefTable.cc @ 7fdb94e

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerwith_gc
Last change on this file since 7fdb94e was 7fdb94e, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

rewrite TypedefTable?

  • Property mode set to 100644
File size: 3.2 KB
Line 
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//
9// Author           : Peter A. Buhr
10// Created On       : Sat May 16 15:20:13 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon May 21 20:55:24 2018
13// Update Count     : 117
14//
15
16
17#include "TypedefTable.h"
18#include <cassert>               // for assert
19
20#if 0
21#include <iostream>
22#define debugPrint( x ) cerr << x
23#else
24#define debugPrint( x )
25#endif
26
27using namespace std;
28
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
38
39int TypedefTable::isKind( const string & identifier ) const {
40        // Name lookup defaults to identifier, and then the identifier's kind is set by the parser.
41        KindTable::const_iterator posn = kindTable.find( identifier );
42        if ( posn == kindTable.end() ) return IDENTIFIER;
43        return posn->second;
44} // TypedefTable::isKind
45
46void TypedefTable::changeKind( const string & identifier, kind_t kind ) {
47        KindTable::iterator posn = kindTable.find( identifier );
48        if ( posn != kindTable.end() ) posn->second = kind;
49} // TypedefTable::changeKind
50
51// SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
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 ) {
55        if ( ! typedefTable.exists( name ) ) {
56                typedefTable.addToEnclosingScope( name, TypedefTable::TD );
57        } // if
58} // TypedefTable::makeTypedef
59
60void TypedefTable::addToEnclosingScope( const std::string & identifier, kind_t kind ) {
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 );
65        if ( ! ret.second ) { // already an element there
66                ret.first->second = kind; // update existing element with new kind
67        } // if
68} // TypedefTable::addToEnclosingScope
69
70void TypedefTable::enterScope() {
71        kindTable.beginScope();
72        debugPrint( "Entering scope " << kindTable.currentScope() << endl );
73} // TypedefTable::enterScope
74
75void TypedefTable::leaveScope() {
76        debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
77        kindTable.endScope();
78} // TypedefTable::leaveScope
79
80// void TypedefTable::print( void ) const {
81//      for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) {
82//              debugPrint( (*i ).first << ": " );
83//              list< Entry > declList = (*i).second;
84//              for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
85//                      debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
86//              }
87//              debugPrint( endl );
88//      } // for
89// }
90
91// Local Variables: //
92// tab-width: 4 //
93// mode: c++ //
94// compile-command: "make install" //
95// End: //
Note: See TracBrowser for help on using the repository browser.