source: src/SynTree/Declaration.cc@ 1189946

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 1189946 was e149f77, checked in by Thierry Delisle <tdelisle@…>, 8 years ago
  • moved print routine to base syntax node and implementated in code gen.
  • added virtual and override where needed in the syntree.
  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[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
28static UniqueId lastUniqueId = 0;
29typedef std::map< UniqueId, Declaration* > IdMapType;
30static IdMapType idMap;
31
[68fe077a]32Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
[65cdc1e]33 : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0 ) {
[51b73452]34}
35
36Declaration::Declaration( const Declaration &other )
[65cdc1e]37 : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId ) {
[51b73452]38}
39
[0dd3a2f]40Declaration::~Declaration() {
[51b73452]41}
42
[0dd3a2f]43void Declaration::fixUniqueId() {
44 uniqueId = ++lastUniqueId;
45 idMap[ uniqueId ] = this;
[51b73452]46}
47
[0dd3a2f]48Declaration *Declaration::declFromId( UniqueId id ) {
49 IdMapType::const_iterator i = idMap.find( id );
[68cd1ce]50 return i != idMap.end() ? i->second : 0;
[51b73452]51}
52
[0dd3a2f]53void Declaration::dumpIds( std::ostream &os ) {
54 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {
55 os << i->first << " -> ";
56 i->second->printShort( os );
57 os << std::endl;
58 } // for
[51b73452]59}
60
[baf7fee]61
[68fe077a]62AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
[e994912]63}
64
65AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
66}
67
68AsmDecl::~AsmDecl() {
69 delete stmt;
70}
71
72void AsmDecl::print( std::ostream &os, int indent ) const {
73 stmt->print( os, indent );
74}
75
76void AsmDecl::printShort( std::ostream &os, int indent ) const {
77 stmt->print( os, indent );
78}
79
80
[0dd3a2f]81// Local Variables: //
82// tab-width: 4 //
83// mode: c++ //
84// compile-command: "make install" //
85// End: //
Note: See TracBrowser for help on using the repository browser.