ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change
on this file since 17cd4eb was
3848e0e,
checked in by Peter A. Buhr <pabuhr@…>, 10 years ago
|
underscore changes, ptrdiff_t changes, formating, _Bool prelude
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[51b7345] | 1 | #include "ParseNode.h" |
---|
| 2 | using namespace std; |
---|
| 3 | |
---|
| 4 | // Builder |
---|
| 5 | int ParseNode::indent_by = 4; |
---|
| 6 | |
---|
[3848e0e] | 7 | ParseNode::ParseNode( void ) : next( 0 ) {}; |
---|
| 8 | ParseNode::ParseNode( string _name ) : name( _name ), next( 0 ) {} |
---|
[51b7345] | 9 | |
---|
[3848e0e] | 10 | ParseNode *ParseNode::set_name( string _name ) { |
---|
| 11 | name = _name; |
---|
| 12 | return this; |
---|
[51b7345] | 13 | } |
---|
| 14 | |
---|
[3848e0e] | 15 | ParseNode *ParseNode::set_name( string *_name ) { |
---|
| 16 | name = *_name; // deep copy |
---|
| 17 | delete _name; |
---|
[51b7345] | 18 | |
---|
[3848e0e] | 19 | return this; |
---|
[51b7345] | 20 | } |
---|
| 21 | |
---|
[3848e0e] | 22 | ParseNode::~ParseNode( void ) { |
---|
| 23 | delete next; |
---|
[51b7345] | 24 | }; |
---|
| 25 | |
---|
[3848e0e] | 26 | string ParseNode::get_name( void ) { |
---|
| 27 | return name; |
---|
[51b7345] | 28 | } |
---|
| 29 | |
---|
[3848e0e] | 30 | ParseNode *ParseNode::get_link( void ) const { |
---|
| 31 | return next; |
---|
[51b7345] | 32 | } |
---|
| 33 | |
---|
| 34 | ParseNode *ParseNode::get_last(void) { |
---|
[3848e0e] | 35 | ParseNode *current = this; |
---|
[51b7345] | 36 | |
---|
[3848e0e] | 37 | while( current->get_link() != 0 ) |
---|
| 38 | current = current->get_link(); |
---|
[51b7345] | 39 | |
---|
[3848e0e] | 40 | return current; |
---|
[51b7345] | 41 | } |
---|
| 42 | |
---|
| 43 | ParseNode *ParseNode::set_link(ParseNode *_next){ |
---|
[3848e0e] | 44 | ParseNode *follow; |
---|
[51b7345] | 45 | |
---|
[3848e0e] | 46 | if ( _next == 0 ) return this; |
---|
[51b7345] | 47 | |
---|
[3848e0e] | 48 | for ( follow = this; follow->next != 0; follow = follow->next ); |
---|
| 49 | follow->next = _next; |
---|
[51b7345] | 50 | |
---|
[3848e0e] | 51 | return this; |
---|
[51b7345] | 52 | } |
---|
| 53 | |
---|
| 54 | const string ParseNode::get_name(void) const { |
---|
[3848e0e] | 55 | return name; |
---|
[51b7345] | 56 | } |
---|
| 57 | |
---|
[3848e0e] | 58 | void ParseNode::print(std::ostream &os, int indent) const {} |
---|
[51b7345] | 59 | |
---|
| 60 | |
---|
[3848e0e] | 61 | void ParseNode::printList( std::ostream &os, int indent ) const { |
---|
| 62 | print( os, indent ); |
---|
[51b7345] | 63 | |
---|
[3848e0e] | 64 | if ( next ) { |
---|
| 65 | next->printList( os, indent ); |
---|
| 66 | } |
---|
[51b7345] | 67 | } |
---|
| 68 | |
---|
[3848e0e] | 69 | ParseNode &ParseNode::operator,( ParseNode &p ) { |
---|
| 70 | set_link( &p ); |
---|
[51b7345] | 71 | |
---|
[3848e0e] | 72 | return *this; |
---|
[51b7345] | 73 | } |
---|
| 74 | |
---|
| 75 | ParseNode *mkList(ParseNode &pn){ |
---|
[3848e0e] | 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; |
---|
[51b7345] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | // Local Variables: // |
---|
| 86 | // mode: C++ // |
---|
| 87 | // compile-command: "gmake" // |
---|
| 88 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.