| [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 | // | 
|---|
| [51b73452] | 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 | 
|---|
| [51b73452] | 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 | 
|---|
| [51b73452] | 27 |  | 
|---|
|  | 28 | static UniqueId lastUniqueId = 0; | 
|---|
|  | 29 |  | 
|---|
| [68fe077a] | 30 | Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) | 
|---|
| [77bfc80] | 31 | : name( name ), linkage( linkage ), uniqueId( 0 ), storageClasses( scs ) { | 
|---|
| [51b73452] | 32 | } | 
|---|
|  | 33 |  | 
|---|
|  | 34 | Declaration::Declaration( const Declaration &other ) | 
|---|
| [77bfc80] | 35 | : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), uniqueId( other.uniqueId ), storageClasses( other.storageClasses ) { | 
|---|
| [51b73452] | 36 | } | 
|---|
|  | 37 |  | 
|---|
| [0dd3a2f] | 38 | Declaration::~Declaration() { | 
|---|
| [51b73452] | 39 | } | 
|---|
|  | 40 |  | 
|---|
| [0dd3a2f] | 41 | void Declaration::fixUniqueId() { | 
|---|
| [582ee28] | 42 | // don't need to set unique ID twice | 
|---|
|  | 43 | if ( uniqueId ) return; | 
|---|
| [0dd3a2f] | 44 | uniqueId = ++lastUniqueId; | 
|---|
| [51b73452] | 45 | } | 
|---|
|  | 46 |  | 
|---|
| [68fe077a] | 47 | AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) { | 
|---|
| [e994912] | 48 | } | 
|---|
|  | 49 |  | 
|---|
|  | 50 | AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { | 
|---|
|  | 51 | } | 
|---|
|  | 52 |  | 
|---|
|  | 53 | AsmDecl::~AsmDecl() { | 
|---|
|  | 54 | delete stmt; | 
|---|
|  | 55 | } | 
|---|
|  | 56 |  | 
|---|
| [50377a4] | 57 | void AsmDecl::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [e994912] | 58 | stmt->print( os, indent ); | 
|---|
|  | 59 | } | 
|---|
|  | 60 |  | 
|---|
| [50377a4] | 61 | void AsmDecl::printShort( std::ostream &os, Indenter indent ) const { | 
|---|
| [e994912] | 62 | stmt->print( os, indent ); | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 |  | 
|---|
| [f6e3e34] | 66 | StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  { | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  { | 
|---|
|  | 70 | } | 
|---|
|  | 71 |  | 
|---|
|  | 72 | StaticAssertDecl::~StaticAssertDecl() { | 
|---|
|  | 73 | delete condition; | 
|---|
|  | 74 | delete message; | 
|---|
|  | 75 | } | 
|---|
|  | 76 |  | 
|---|
|  | 77 | void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 78 | os << "Static Assert with condition: "; | 
|---|
|  | 79 | condition->print( os, indent+1 ); | 
|---|
|  | 80 | os << std::endl << indent << "and message: "; | 
|---|
|  | 81 | message->print( os, indent+1 ); | 
|---|
|  | 82 | os << std::endl; | 
|---|
|  | 83 | } | 
|---|
|  | 84 |  | 
|---|
|  | 85 | void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 86 | print( os, indent ); | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
| [3ed994e] | 89 |  | 
|---|
| [0dd3a2f] | 90 | // Local Variables: // | 
|---|
|  | 91 | // tab-width: 4 // | 
|---|
|  | 92 | // mode: c++ // | 
|---|
|  | 93 | // compile-command: "make install" // | 
|---|
|  | 94 | // End: // | 
|---|