| 1 | /* -*- C++ -*- */
|
|---|
| 2 | #include "ParseNode.h"
|
|---|
| 3 | using namespace std;
|
|---|
| 4 |
|
|---|
| 5 | // Builder
|
|---|
| 6 | int ParseNode::indent_by = 4;
|
|---|
| 7 |
|
|---|
| 8 | // ParseNode::ParseNode(void): next( 0 ) {};
|
|---|
| 9 | ParseNode::ParseNode( std::string _name, char *filename, int lineno )
|
|---|
| 10 | : name(_name), next( 0 ), filename( filename ), lineno( lineno )
|
|---|
| 11 | {
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | ParseNode *ParseNode::set_name (string _name) {
|
|---|
| 15 | name = _name;
|
|---|
| 16 |
|
|---|
| 17 | return this;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | ParseNode *ParseNode::set_name (string *_name) {
|
|---|
| 21 | name = *_name; // deep copy
|
|---|
| 22 | delete _name;
|
|---|
| 23 |
|
|---|
| 24 | return this;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | ParseNode::~ParseNode(void){
|
|---|
| 28 | delete next;
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 | string ParseNode::get_name(void) {
|
|---|
| 32 | return name;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | ParseNode *ParseNode::get_link(void) const {
|
|---|
| 36 | return next;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | ParseNode *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 |
|
|---|
| 48 | ParseNode *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 |
|
|---|
| 59 | const string ParseNode::get_name(void) const {
|
|---|
| 60 | return name;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void ParseNode::print(std::ostream &os, int indent) const
|
|---|
| 64 | {
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | void 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 |
|
|---|
| 77 | ParseNode &ParseNode::operator,(ParseNode &p){
|
|---|
| 78 | set_link(&p);
|
|---|
| 79 |
|
|---|
| 80 | return *this;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | ParseNode *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: //
|
|---|