| [0dd3a2f] | 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 | // Declaration.cc -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Mon May 18 07:44:20 2015 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
|  | 12 | // Last Modified On : Mon May 18 08:18:35 2015 | 
|---|
|  | 13 | // Update Count     : 2 | 
|---|
|  | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
|  | 16 | #include <string> | 
|---|
|  | 17 | #include <map> | 
|---|
|  | 18 | #include "Declaration.h" | 
|---|
|  | 19 | #include "Expression.h" | 
|---|
|  | 20 | #include "Initializer.h" | 
|---|
|  | 21 | #include "Type.h" | 
|---|
|  | 22 | #include "utility.h" | 
|---|
|  | 23 |  | 
|---|
|  | 24 | const char* Declaration::storageClassName[] = { "", "auto", "static", "extern", "register" }; | 
|---|
|  | 25 |  | 
|---|
|  | 26 | static UniqueId lastUniqueId = 0; | 
|---|
|  | 27 | typedef std::map< UniqueId, Declaration* > IdMapType; | 
|---|
|  | 28 | static IdMapType idMap; | 
|---|
|  | 29 |  | 
|---|
|  | 30 | Declaration::Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ) | 
|---|
| [0dd3a2f] | 31 | : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) { | 
|---|
| [51b73452] | 32 | } | 
|---|
|  | 33 |  | 
|---|
|  | 34 | Declaration::Declaration( const Declaration &other ) | 
|---|
| [0dd3a2f] | 35 | : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) { | 
|---|
| [51b73452] | 36 | } | 
|---|
|  | 37 |  | 
|---|
| [0dd3a2f] | 38 | Declaration::~Declaration() { | 
|---|
| [51b73452] | 39 | } | 
|---|
|  | 40 |  | 
|---|
| [0dd3a2f] | 41 | void Declaration::fixUniqueId() { | 
|---|
|  | 42 | uniqueId = ++lastUniqueId; | 
|---|
|  | 43 | idMap[ uniqueId ] = this; | 
|---|
| [51b73452] | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 | /* static class method */ | 
|---|
| [0dd3a2f] | 47 | Declaration *Declaration::declFromId( UniqueId id ) { | 
|---|
|  | 48 | IdMapType::const_iterator i = idMap.find( id ); | 
|---|
|  | 49 | if ( i != idMap.end() ) { | 
|---|
|  | 50 | return i->second; | 
|---|
|  | 51 | } else { | 
|---|
|  | 52 | return 0; | 
|---|
|  | 53 | } // if | 
|---|
| [51b73452] | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 | /* static class method */ | 
|---|
| [0dd3a2f] | 57 | void Declaration::dumpIds( std::ostream &os ) { | 
|---|
|  | 58 | for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) { | 
|---|
|  | 59 | os << i->first << " -> "; | 
|---|
|  | 60 | i->second->printShort( os ); | 
|---|
|  | 61 | os << std::endl; | 
|---|
|  | 62 | } // for | 
|---|
| [51b73452] | 63 | } | 
|---|
|  | 64 |  | 
|---|
| [0dd3a2f] | 65 | // Local Variables: // | 
|---|
|  | 66 | // tab-width: 4 // | 
|---|
|  | 67 | // mode: c++ // | 
|---|
|  | 68 | // compile-command: "make install" // | 
|---|
|  | 69 | // End: // | 
|---|