source: tools/prettyprinter/token.cc @ 2b878b4

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2b878b4 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change #ifndef to #pragma once

  • Property mode set to 100644
File size: 2.6 KB
Line 
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// Pretty Printer, Copyright (C) Richard C. Bilson and Rodolfo G. Esteves 2001
8//
9// token.cc --
10//
11// Author           : Peter A. Buhr
12// Created On       : Wed Jun 28 22:46:23 2017
13// Last Modified By : Peter A. Buhr
14// Last Modified On : Fri Jul 21 23:07:04 2017
15// Update Count     : 10
16//
17
18#include <string>
19using namespace std;
20#include "ParserTypes.h"
21#include "parser.hh"
22#include "filter.h"
23
24Token::Token( const string & text, int kind ) : text(text), kind(kind) {
25        left = down = NULL;
26} // Token::Token
27
28Token::Token( const string & text, list<string> & ws_list, int kind ) : text(text), kind(kind) {
29//    cerr << "Token3 : text \"" << text << "\"";
30//    for ( list<string>::iterator i = ws_list.begin(); i != ws_list.end(); i ++ ) {
31//      cerr << " WSt: \"" << *i << "\"";
32//    }
33//    cerr << endl;
34        left = down = NULL;
35        // O(1) transfer of the current lex whitespace list to the token's whitespace list, and clearing the lex whitespace
36        // list.
37        Token::ws_list.splice( Token::ws_list.end(), ws_list );
38} // Token::Token
39
40void Token::addLeftTail( Token * n ) {
41        Token * p = this;
42        while ( p->left != 0 ) {
43                p = p->left;
44        } // while
45        p->left = n;
46} // Token::addLeftTail
47
48void Token::addDownLeftTail( Token * n ) {
49        if ( down == 0 ) {
50                down = n;
51        } else {
52                down->addLeftTail( n );
53        } // if
54} // Token::addDownLeftTail
55
56bool Token::isTerminal() {
57        return kind < END_TERMINALS;
58} // Token::isTerminal
59
60int Token::getKind() const {
61        return kind;
62} // Token::getKind()
63
64string Token::getText() const {
65        return text;
66} // Token::getText()
67
68string Token::getWS() {
69        string ret;
70        // concatenate whitespace and comment text
71        for ( list<string>::iterator i = ws_list.begin(); i != ws_list.end(); i ++ ) {
72                ret += *i;
73        } // for
74        return ret;
75} // Token::getWS
76
77bool Token::isComment() {
78        return ws_list.size() > 1 || ( ws_list.size() == 1 && (*ws_list.begin())[0] == '/' );
79} // Token::isComment
80
81string Token::getComment() {
82        string ret;
83        // concatenate whitespace and comment text up to the last comment
84        if ( ws_list.size() > 1 ) {
85                list<string>::iterator end = -- ws_list.end();
86                if ( (*end)[0] == '/' ) end ++;
87                for ( list<string>::iterator i = ws_list.begin(); i != end; i ++ ) {
88                        ret += *i;
89                } // for
90        } else if ( ws_list.size() == 1 ) {
91                if ( (*ws_list.begin())[0] == '/' ) ret = *ws_list.begin();
92        } // if
93        return ret;
94} // Token::getComment
95
96// Local Variables: //
97// mode: c++ //
98// tab-width: 4 //
99// compile-command: "make install" //
100// End: //
Note: See TracBrowser for help on using the repository browser.