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 : Andrew Beach
|
---|
12 | // Last Modified On : Wed Aug 9 14:38:00 2017
|
---|
13 | // Update Count : 25
|
---|
14 | //
|
---|
15 |
|
---|
16 | #include <map> // for _Rb_tree_const_iterator, map<>::...
|
---|
17 | #include <ostream> // for ostream, operator<<, basic_ostre...
|
---|
18 | #include <string> // for string
|
---|
19 | #include <utility> // for pair
|
---|
20 |
|
---|
21 | #include "Common/utility.h" // for maybeClone
|
---|
22 | #include "Declaration.h"
|
---|
23 | #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode
|
---|
24 | #include "SynTree/Statement.h" // for AsmStmt
|
---|
25 | #include "SynTree/SynTree.h" // for UniqueId
|
---|
26 | #include "Type.h" // for Type, Type::StorageClasses
|
---|
27 |
|
---|
28 | static UniqueId lastUniqueId = 0;
|
---|
29 | typedef std::map< UniqueId, Declaration* > IdMapType;
|
---|
30 | static IdMapType idMap;
|
---|
31 |
|
---|
32 | Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
|
---|
33 | : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0 ) {
|
---|
34 | }
|
---|
35 |
|
---|
36 | Declaration::Declaration( const Declaration &other )
|
---|
37 | : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId ) {
|
---|
38 | }
|
---|
39 |
|
---|
40 | Declaration::~Declaration() {
|
---|
41 | }
|
---|
42 |
|
---|
43 | void Declaration::fixUniqueId() {
|
---|
44 | // don't need to set unique ID twice
|
---|
45 | if ( uniqueId ) return;
|
---|
46 | uniqueId = ++lastUniqueId;
|
---|
47 | idMap[ uniqueId ] = this;
|
---|
48 | }
|
---|
49 |
|
---|
50 | Declaration *Declaration::declFromId( UniqueId id ) {
|
---|
51 | IdMapType::const_iterator i = idMap.find( id );
|
---|
52 | return i != idMap.end() ? i->second : 0;
|
---|
53 | }
|
---|
54 |
|
---|
55 | void Declaration::dumpIds( std::ostream &os ) {
|
---|
56 | for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {
|
---|
57 | os << i->first << " -> ";
|
---|
58 | i->second->printShort( os );
|
---|
59 | os << std::endl;
|
---|
60 | } // for
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
|
---|
65 | }
|
---|
66 |
|
---|
67 | AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
|
---|
68 | }
|
---|
69 |
|
---|
70 | AsmDecl::~AsmDecl() {
|
---|
71 | delete stmt;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void AsmDecl::print( std::ostream &os, Indenter indent ) const {
|
---|
75 | stmt->print( os, indent );
|
---|
76 | }
|
---|
77 |
|
---|
78 | void AsmDecl::printShort( std::ostream &os, Indenter indent ) const {
|
---|
79 | stmt->print( os, indent );
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message ) {
|
---|
84 | }
|
---|
85 |
|
---|
86 | StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) ) {
|
---|
87 | }
|
---|
88 |
|
---|
89 | StaticAssertDecl::~StaticAssertDecl() {
|
---|
90 | delete condition;
|
---|
91 | delete message;
|
---|
92 | }
|
---|
93 |
|
---|
94 | void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const {
|
---|
95 | os << "Static Assert with condition: ";
|
---|
96 | condition->print( os, indent+1 );
|
---|
97 | os << std::endl << indent << "and message: ";
|
---|
98 | message->print( os, indent+1 );
|
---|
99 | os << std::endl;
|
---|
100 | }
|
---|
101 |
|
---|
102 | void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
|
---|
103 | print( os, indent );
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | // Local Variables: //
|
---|
108 | // tab-width: 4 //
|
---|
109 | // mode: c++ //
|
---|
110 | // compile-command: "make install" //
|
---|
111 | // End: //
|
---|