source: translator/Parser/ParseNode.cc @ 8c17ab0

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 8c17ab0 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* -*- C++ -*- */
2#include "ParseNode.h"
3using namespace std;
4
5// Builder
6int ParseNode::indent_by = 4;
7
8ParseNode::ParseNode(void): next( 0 ) {};
9ParseNode::ParseNode (string _name) : name(_name), next( 0 ) {}
10
11ParseNode *ParseNode::set_name (string _name) {
12  name = _name;
13
14  return this;
15}
16
17ParseNode *ParseNode::set_name (string *_name) {
18  name = *_name; // deep copy
19  delete _name;
20
21  return this;
22}
23
24ParseNode::~ParseNode(void){
25  delete next;
26};
27
28string ParseNode::get_name(void) {
29  return name;
30}
31
32ParseNode *ParseNode::get_link(void) const {
33  return next;
34}
35
36ParseNode *ParseNode::get_last(void) {
37  ParseNode * current = this;
38
39  while(current->get_link() != 0)
40    current = current->get_link();
41
42  return current;
43}
44
45ParseNode *ParseNode::set_link(ParseNode *_next){
46  ParseNode *follow;
47
48  if(_next == 0) return this;
49
50  for(follow = this; follow->next != 0; follow = follow->next);
51  follow->next = _next;
52
53  return this;
54}
55
56const string ParseNode::get_name(void) const {
57  return name;
58}
59
60void ParseNode::print(std::ostream &os, int indent) const
61{
62}
63
64
65void 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
74ParseNode &ParseNode::operator,(ParseNode &p){
75  set_link(&p);
76
77  return *this;
78}
79
80ParseNode *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;
88}
89
90
91// Local Variables: //
92// mode: C++                //
93// compile-command: "gmake" //
94// End: //
Note: See TracBrowser for help on using the repository browser.