source: translator/Parser/ParseNode.cc@ fe3b61b

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since fe3b61b was 3848e0e, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

underscore changes, ptrdiff_t changes, formating, _Bool prelude

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include "ParseNode.h"
2using namespace std;
3
4// Builder
5int ParseNode::indent_by = 4;
6
7ParseNode::ParseNode( void ) : next( 0 ) {};
8ParseNode::ParseNode( string _name ) : name( _name ), next( 0 ) {}
9
10ParseNode *ParseNode::set_name( string _name ) {
11 name = _name;
12 return this;
13}
14
15ParseNode *ParseNode::set_name( string *_name ) {
16 name = *_name; // deep copy
17 delete _name;
18
19 return this;
20}
21
22ParseNode::~ParseNode( void ) {
23 delete next;
24};
25
26string ParseNode::get_name( void ) {
27 return name;
28}
29
30ParseNode *ParseNode::get_link( void ) const {
31 return next;
32}
33
34ParseNode *ParseNode::get_last(void) {
35 ParseNode *current = this;
36
37 while( current->get_link() != 0 )
38 current = current->get_link();
39
40 return current;
41}
42
43ParseNode *ParseNode::set_link(ParseNode *_next){
44 ParseNode *follow;
45
46 if ( _next == 0 ) return this;
47
48 for ( follow = this; follow->next != 0; follow = follow->next );
49 follow->next = _next;
50
51 return this;
52}
53
54const string ParseNode::get_name(void) const {
55 return name;
56}
57
58void ParseNode::print(std::ostream &os, int indent) const {}
59
60
61void ParseNode::printList( std::ostream &os, int indent ) const {
62 print( os, indent );
63
64 if ( next ) {
65 next->printList( os, indent );
66 }
67}
68
69ParseNode &ParseNode::operator,( ParseNode &p ) {
70 set_link( &p );
71
72 return *this;
73}
74
75ParseNode *mkList(ParseNode &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;
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.