| [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
 | 
|---|
| [312029a] | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| [2d019af] | 12 | // Last Modified On : Fri Mar 12 18:35:39 2021
 | 
|---|
 | 13 | // Update Count     : 37
 | 
|---|
| [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
 | 
|---|
| [312029a] | 26 | #include "SynTree/Expression.h"
 | 
|---|
| [ea6332d] | 27 | #include "Type.h"                    // for Type, Type::StorageClasses
 | 
|---|
| [51b73452] | 28 | 
 | 
|---|
| [312029a] | 29 | // To canonicalize declarations
 | 
|---|
| [51b73452] | 30 | static UniqueId lastUniqueId = 0;
 | 
|---|
 | 31 | 
 | 
|---|
| [68fe077a] | 32 | Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
 | 
|---|
| [77bfc80] | 33 |                 : name( name ), linkage( linkage ), uniqueId( 0 ), storageClasses( scs ) {
 | 
|---|
| [51b73452] | 34 | }
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | Declaration::Declaration( const Declaration &other )
 | 
|---|
| [77bfc80] | 37 |         : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), uniqueId( other.uniqueId ), storageClasses( other.storageClasses ) {
 | 
|---|
| [51b73452] | 38 | }
 | 
|---|
 | 39 | 
 | 
|---|
| [0dd3a2f] | 40 | Declaration::~Declaration() {
 | 
|---|
| [51b73452] | 41 | }
 | 
|---|
 | 42 | 
 | 
|---|
| [0dd3a2f] | 43 | void Declaration::fixUniqueId() {
 | 
|---|
| [582ee28] | 44 |         // don't need to set unique ID twice
 | 
|---|
 | 45 |         if ( uniqueId ) return;
 | 
|---|
| [0dd3a2f] | 46 |         uniqueId = ++lastUniqueId;
 | 
|---|
| [51b73452] | 47 | }
 | 
|---|
 | 48 | 
 | 
|---|
| [68fe077a] | 49 | AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
 | 
|---|
| [e994912] | 50 | }
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
 | 
|---|
 | 53 | }
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | AsmDecl::~AsmDecl() {
 | 
|---|
 | 56 |         delete stmt;
 | 
|---|
 | 57 | }
 | 
|---|
 | 58 | 
 | 
|---|
| [50377a4] | 59 | void AsmDecl::print( std::ostream &os, Indenter indent ) const {
 | 
|---|
| [e994912] | 60 |         stmt->print( os, indent );
 | 
|---|
 | 61 | }
 | 
|---|
 | 62 | 
 | 
|---|
| [50377a4] | 63 | void AsmDecl::printShort( std::ostream &os, Indenter indent ) const {
 | 
|---|
| [e994912] | 64 |         stmt->print( os, indent );
 | 
|---|
 | 65 | }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | 
 | 
|---|
| [2d019af] | 68 | DirectiveDecl::DirectiveDecl( DirectiveStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
 | 
|---|
 | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | DirectiveDecl::DirectiveDecl( const DirectiveDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
 | 
|---|
 | 72 | }
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | DirectiveDecl::~DirectiveDecl() {
 | 
|---|
 | 75 |         delete stmt;
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | void DirectiveDecl::print( std::ostream &os, Indenter indent ) const {
 | 
|---|
 | 79 |         stmt->print( os, indent );
 | 
|---|
 | 80 | }
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | void DirectiveDecl::printShort( std::ostream &os, Indenter indent ) const {
 | 
|---|
 | 83 |         stmt->print( os, indent );
 | 
|---|
 | 84 | }
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | 
 | 
|---|
| [f6e3e34] | 87 | StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | StaticAssertDecl::~StaticAssertDecl() {
 | 
|---|
 | 94 |         delete condition;
 | 
|---|
 | 95 |         delete message;
 | 
|---|
 | 96 | }
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 | void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const {
 | 
|---|
 | 99 |         os << "Static Assert with condition: ";
 | 
|---|
 | 100 |         condition->print( os, indent+1 );
 | 
|---|
 | 101 |         os << std::endl << indent << "and message: ";
 | 
|---|
 | 102 |         message->print( os, indent+1 );
 | 
|---|
 | 103 | os << std::endl;
 | 
|---|
 | 104 | }
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 | void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
 | 
|---|
 | 107 |         print( os, indent );
 | 
|---|
 | 108 | }
 | 
|---|
 | 109 | 
 | 
|---|
| [3ed994e] | 110 | 
 | 
|---|
| [0dd3a2f] | 111 | // Local Variables: //
 | 
|---|
 | 112 | // tab-width: 4 //
 | 
|---|
 | 113 | // mode: c++ //
 | 
|---|
 | 114 | // compile-command: "make install" //
 | 
|---|
 | 115 | // End: //
 | 
|---|