| 1 | //
|
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
|---|
| 3 | //
|
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
|---|
| 5 | // file "LICENCE" distributed with Cforall.
|
|---|
| 6 | //
|
|---|
| 7 | // ParseNode.cc --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Rodolfo G. Esteves
|
|---|
| 10 | // Created On : Sat May 16 13:26:29 2015
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Tue May 19 16:48:30 2015
|
|---|
| 13 | // Update Count : 3
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include "ParseNode.h"
|
|---|
| 17 | using namespace std;
|
|---|
| 18 |
|
|---|
| 19 | // Builder
|
|---|
| 20 | int ParseNode::indent_by = 4;
|
|---|
| 21 |
|
|---|
| 22 | ParseNode::ParseNode( void ) : next( 0 ) {};
|
|---|
| 23 | ParseNode::ParseNode( string _name ) : name( _name ), next( 0 ) {}
|
|---|
| 24 |
|
|---|
| 25 | ParseNode *ParseNode::set_name( string _name ) {
|
|---|
| 26 | name = _name;
|
|---|
| 27 | return this;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | ParseNode *ParseNode::set_name( string *_name ) {
|
|---|
| 31 | name = *_name; // deep copy
|
|---|
| 32 | delete _name;
|
|---|
| 33 |
|
|---|
| 34 | return this;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | ParseNode::~ParseNode( void ) {
|
|---|
| 38 | delete next;
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | string ParseNode::get_name( void ) {
|
|---|
| 42 | return name;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | ParseNode *ParseNode::get_link( void ) const {
|
|---|
| 46 | return next;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | ParseNode *ParseNode::get_last(void) {
|
|---|
| 50 | ParseNode *current = this;
|
|---|
| 51 |
|
|---|
| 52 | while ( current->get_link() != 0 )
|
|---|
| 53 | current = current->get_link();
|
|---|
| 54 |
|
|---|
| 55 | return current;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | ParseNode *ParseNode::set_link(ParseNode *_next) {
|
|---|
| 59 | ParseNode *follow;
|
|---|
| 60 |
|
|---|
| 61 | if ( _next == 0 ) return this;
|
|---|
| 62 |
|
|---|
| 63 | for ( follow = this; follow->next != 0; follow = follow->next );
|
|---|
| 64 | follow->next = _next;
|
|---|
| 65 |
|
|---|
| 66 | return this;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | const string ParseNode::get_name(void) const {
|
|---|
| 70 | return name;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | void ParseNode::print(std::ostream &os, int indent) const {}
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | void ParseNode::printList( std::ostream &os, int indent ) const {
|
|---|
| 77 | print( os, indent );
|
|---|
| 78 |
|
|---|
| 79 | if ( next ) {
|
|---|
| 80 | next->printList( os, indent );
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | ParseNode &ParseNode::operator,( ParseNode &p ) {
|
|---|
| 85 | set_link( &p );
|
|---|
| 86 |
|
|---|
| 87 | return *this;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | ParseNode *mkList( ParseNode &pn ) {
|
|---|
| 91 | // it just relies on `operator,' to take care of the "arguments" and provides a nice interface to an awful-looking
|
|---|
| 92 | // address-of, rendering, for example (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7))
|
|---|
| 93 | // (although "nice" is probably not the word)
|
|---|
| 94 | return &pn;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | // Local Variables: //
|
|---|
| 98 | // tab-width: 4 //
|
|---|
| 99 | // mode: c++ //
|
|---|
| 100 | // compile-command: "make install" //
|
|---|
| 101 | // End: //
|
|---|