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 | //
|
---|
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 )
|
---|
31 | : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) {
|
---|
32 | }
|
---|
33 |
|
---|
34 | Declaration::Declaration( const Declaration &other )
|
---|
35 | : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) {
|
---|
36 | }
|
---|
37 |
|
---|
38 | Declaration::~Declaration() {
|
---|
39 | }
|
---|
40 |
|
---|
41 | void Declaration::fixUniqueId() {
|
---|
42 | uniqueId = ++lastUniqueId;
|
---|
43 | idMap[ uniqueId ] = this;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /* static class method */
|
---|
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
|
---|
54 | }
|
---|
55 |
|
---|
56 | /* static class method */
|
---|
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
|
---|
63 | }
|
---|
64 |
|
---|
65 | // Local Variables: //
|
---|
66 | // tab-width: 4 //
|
---|
67 | // mode: c++ //
|
---|
68 | // compile-command: "make install" //
|
---|
69 | // End: //
|
---|