source: translator/Parser.old/ParseNode.cc@ c8ffe20b

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 c8ffe20b was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/* -*- C++ -*- */
2#include "ParseNode.h"
3using namespace std;
4
5// Builder
6int ParseNode::indent_by = 4;
7
8// ParseNode::ParseNode(void): next( 0 ) {};
9ParseNode::ParseNode( std::string _name, char *filename, int lineno )
10 : name(_name), next( 0 ), filename( filename ), lineno( lineno )
11{
12}
13
14ParseNode *ParseNode::set_name (string _name) {
15 name = _name;
16
17 return this;
18}
19
20ParseNode *ParseNode::set_name (string *_name) {
21 name = *_name; // deep copy
22 delete _name;
23
24 return this;
25}
26
27ParseNode::~ParseNode(void){
28 delete next;
29};
30
31string ParseNode::get_name(void) {
32 return name;
33}
34
35ParseNode *ParseNode::get_link(void) const {
36 return next;
37}
38
39ParseNode *ParseNode::get_last(void) {
40 ParseNode * current = this;
41
42 while(current->get_link() != 0)
43 current = current->get_link();
44
45 return current;
46}
47
48ParseNode *ParseNode::set_link(ParseNode *_next){
49 ParseNode *follow;
50
51 if(_next == 0) return this;
52
53 for(follow = this; follow->next != 0; follow = follow->next);
54 follow->next = _next;
55
56 return this;
57}
58
59const string ParseNode::get_name(void) const {
60 return name;
61}
62
63void ParseNode::print(std::ostream &os, int indent) const
64{
65}
66
67
68void ParseNode::printList(std::ostream &os, int indent) const
69{
70 print( os, indent );
71
72 if( next ) {
73 next->printList( os, indent );
74 }
75}
76
77ParseNode &ParseNode::operator,(ParseNode &p){
78 set_link(&p);
79
80 return *this;
81}
82
83ParseNode *mkList(ParseNode &pn){
84 /* it just relies on `operator,' to take care of the "arguments" and provides
85 a nice interface to an awful-looking address-of, rendering, for example
86 (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7))
87 (although "nice" is probably not the word)
88 */
89
90 return &pn;
91}
92
93
94// Local Variables: //
95// mode: C++ //
96// compile-command: "gmake" //
97// End: //
Note: See TracBrowser for help on using the repository browser.