source: src/SynTree/Declaration.cc @ 0092853

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0092853 was 312029a, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

move enum Aggregate from DeclarationNode? to AggregateDecl?, add control-keyword field-dereference to replace control-keyword cast

  • Property mode set to 100644
File size: 3.0 KB
Line 
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 : Peter A. Buhr
12// Last Modified On : Wed Dec 11 16:39:56 2019
13// Update Count     : 36
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 "SynTree/Expression.h"
27#include "Type.h"                    // for Type, Type::StorageClasses
28
29// To canonicalize declarations
30static UniqueId lastUniqueId = 0;
31
32Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
33                : name( name ), linkage( linkage ), uniqueId( 0 ), storageClasses( scs ) {
34}
35
36Declaration::Declaration( const Declaration &other )
37        : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), uniqueId( other.uniqueId ), storageClasses( other.storageClasses ) {
38}
39
40Declaration::~Declaration() {
41}
42
43void Declaration::fixUniqueId() {
44        // don't need to set unique ID twice
45        if ( uniqueId ) return;
46        uniqueId = ++lastUniqueId;
47}
48
49AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
50}
51
52AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
53}
54
55AsmDecl::~AsmDecl() {
56        delete stmt;
57}
58
59void AsmDecl::print( std::ostream &os, Indenter indent ) const {
60        stmt->print( os, indent );
61}
62
63void AsmDecl::printShort( std::ostream &os, Indenter indent ) const {
64        stmt->print( os, indent );
65}
66
67
68StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
69}
70
71StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
72}
73
74StaticAssertDecl::~StaticAssertDecl() {
75        delete condition;
76        delete message;
77}
78
79void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const {
80        os << "Static Assert with condition: ";
81        condition->print( os, indent+1 );
82        os << std::endl << indent << "and message: ";
83        message->print( os, indent+1 );
84os << std::endl;
85}
86
87void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
88        print( os, indent );
89}
90
91
92// Local Variables: //
93// tab-width: 4 //
94// mode: c++ //
95// compile-command: "make install" //
96// End: //
Note: See TracBrowser for help on using the repository browser.