[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 | // |
---|
[f9cebb5] | 7 | // Declaration.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[8b7ee09] | 11 | // Last Modified By : Peter A. Buhr |
---|
[a7c90d4] | 12 | // Last Modified On : Tue Mar 7 07:31:11 2017 |
---|
| 13 | // Update Count : 23 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include <string> |
---|
| 17 | #include <map> |
---|
| 18 | #include "Declaration.h" |
---|
| 19 | #include "Expression.h" |
---|
| 20 | #include "Initializer.h" |
---|
| 21 | #include "Type.h" |
---|
[f9cebb5] | 22 | #include "Attribute.h" |
---|
[d3b7937] | 23 | #include "Common/utility.h" |
---|
[51b7345] | 24 | |
---|
| 25 | static UniqueId lastUniqueId = 0; |
---|
| 26 | typedef std::map< UniqueId, Declaration* > IdMapType; |
---|
| 27 | static IdMapType idMap; |
---|
| 28 | |
---|
[a7c90d4] | 29 | Declaration::Declaration( const std::string &name, DeclarationNode::StorageClasses scs, LinkageSpec::Spec linkage ) |
---|
| 30 | : name( name ), storageClasses( scs ), linkage( linkage ), uniqueId( 0 ) { |
---|
[51b7345] | 31 | } |
---|
| 32 | |
---|
| 33 | Declaration::Declaration( const Declaration &other ) |
---|
[a7c90d4] | 34 | : name( other.name ), storageClasses( other.storageClasses ), linkage( other.linkage ), uniqueId( other.uniqueId ) { |
---|
[51b7345] | 35 | } |
---|
| 36 | |
---|
[0dd3a2f] | 37 | Declaration::~Declaration() { |
---|
[51b7345] | 38 | } |
---|
| 39 | |
---|
[0dd3a2f] | 40 | void Declaration::fixUniqueId() { |
---|
| 41 | uniqueId = ++lastUniqueId; |
---|
| 42 | idMap[ uniqueId ] = this; |
---|
[51b7345] | 43 | } |
---|
| 44 | |
---|
[0dd3a2f] | 45 | Declaration *Declaration::declFromId( UniqueId id ) { |
---|
| 46 | IdMapType::const_iterator i = idMap.find( id ); |
---|
[68cd1ce] | 47 | return i != idMap.end() ? i->second : 0; |
---|
[51b7345] | 48 | } |
---|
| 49 | |
---|
[0dd3a2f] | 50 | void Declaration::dumpIds( std::ostream &os ) { |
---|
| 51 | for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) { |
---|
| 52 | os << i->first << " -> "; |
---|
| 53 | i->second->printShort( os ); |
---|
| 54 | os << std::endl; |
---|
| 55 | } // for |
---|
[51b7345] | 56 | } |
---|
| 57 | |
---|
[3906301] | 58 | std::ostream & operator<<( std::ostream & out, const Declaration * decl ) { |
---|
[8bf784a] | 59 | if ( decl ){ |
---|
| 60 | decl->print( out ); |
---|
| 61 | } else { |
---|
| 62 | out << "nullptr"; |
---|
| 63 | } |
---|
[baf7fee] | 64 | return out; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
[a7c90d4] | 68 | AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", DeclarationNode::StorageClasses(), LinkageSpec::C ), stmt( stmt ) { |
---|
[e994912] | 69 | } |
---|
| 70 | |
---|
| 71 | AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | AsmDecl::~AsmDecl() { |
---|
| 75 | delete stmt; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void AsmDecl::print( std::ostream &os, int indent ) const { |
---|
| 79 | stmt->print( os, indent ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void AsmDecl::printShort( std::ostream &os, int indent ) const { |
---|
| 83 | stmt->print( os, indent ); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
[0dd3a2f] | 87 | // Local Variables: // |
---|
| 88 | // tab-width: 4 // |
---|
| 89 | // mode: c++ // |
---|
| 90 | // compile-command: "make install" // |
---|
| 91 | // End: // |
---|