Changeset 3848e0e for translator/Parser/ParseNode.cc
- Timestamp:
- Dec 3, 2014, 3:08:38 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- d9a0e76
- Parents:
- 42dcae7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/ParseNode.cc
r42dcae7 r3848e0e 1 /* -*- C++ -*- */2 1 #include "ParseNode.h" 3 2 using namespace std; … … 6 5 int ParseNode::indent_by = 4; 7 6 8 ParseNode::ParseNode( void): next( 0 ) {};9 ParseNode::ParseNode (string _name) : name(_name), next( 0 ) {}7 ParseNode::ParseNode( void ) : next( 0 ) {}; 8 ParseNode::ParseNode( string _name ) : name( _name ), next( 0 ) {} 10 9 11 ParseNode *ParseNode::set_name (string _name) { 12 name = _name; 13 14 return this; 10 ParseNode *ParseNode::set_name( string _name ) { 11 name = _name; 12 return this; 15 13 } 16 14 17 ParseNode *ParseNode::set_name (string *_name) {18 name = *_name; // deep copy19 delete _name;15 ParseNode *ParseNode::set_name( string *_name ) { 16 name = *_name; // deep copy 17 delete _name; 20 18 21 return this;19 return this; 22 20 } 23 21 24 ParseNode::~ParseNode( void){25 delete next;22 ParseNode::~ParseNode( void ) { 23 delete next; 26 24 }; 27 25 28 string ParseNode::get_name( void) {29 return name;26 string ParseNode::get_name( void ) { 27 return name; 30 28 } 31 29 32 ParseNode *ParseNode::get_link( void) const {33 return next;30 ParseNode *ParseNode::get_link( void ) const { 31 return next; 34 32 } 35 33 36 34 ParseNode *ParseNode::get_last(void) { 37 ParseNode *current = this;35 ParseNode *current = this; 38 36 39 while(current->get_link() != 0)40 37 while( current->get_link() != 0 ) 38 current = current->get_link(); 41 39 42 return current;40 return current; 43 41 } 44 42 45 43 ParseNode *ParseNode::set_link(ParseNode *_next){ 46 ParseNode *follow;44 ParseNode *follow; 47 45 48 if(_next == 0) return this;46 if ( _next == 0 ) return this; 49 47 50 for(follow = this; follow->next != 0; follow = follow->next);51 follow->next = _next;48 for ( follow = this; follow->next != 0; follow = follow->next ); 49 follow->next = _next; 52 50 53 return this;51 return this; 54 52 } 55 53 56 54 const string ParseNode::get_name(void) const { 57 return name;55 return name; 58 56 } 59 57 60 void ParseNode::print(std::ostream &os, int indent) const 61 { 58 void ParseNode::print(std::ostream &os, int indent) const {} 59 60 61 void ParseNode::printList( std::ostream &os, int indent ) const { 62 print( os, indent ); 63 64 if ( next ) { 65 next->printList( os, indent ); 66 } 62 67 } 63 68 69 ParseNode &ParseNode::operator,( ParseNode &p ) { 70 set_link( &p ); 64 71 65 void ParseNode::printList(std::ostream &os, int indent) const 66 { 67 print( os, indent ); 68 69 if( next ) { 70 next->printList( os, indent ); 71 } 72 } 73 74 ParseNode &ParseNode::operator,(ParseNode &p){ 75 set_link(&p); 76 77 return *this; 72 return *this; 78 73 } 79 74 80 75 ParseNode *mkList(ParseNode &pn){ 81 /* it just relies on `operator,' to take care of the "arguments" and provides 82 a nice interface to an awful-looking address-of, rendering, for example 83 (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7)) 84 (although "nice" is probably not the word) 85 */ 86 87 return &pn; 76 /* it just relies on `operator,' to take care of the "arguments" and provides 77 a nice interface to an awful-looking address-of, rendering, for example 78 (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7)) 79 (although "nice" is probably not the word) 80 */ 81 return &pn; 88 82 } 89 83
Note: See TracChangeset
for help on using the changeset viewer.