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