1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
13 * Szabo, Janos Zoltan – initial implementation
15 ******************************************************************************/
16 #ifndef _Asn_TokenBuf_HH
17 #define _Asn_TokenBuf_HH
19 #include "../vector.hh"
21 #include "AST_asn1.hh"
24 #include "../Typestuff.hh" // FIXME CTs
25 #include "../Value.hh"
26 #include "../Valuestuff.hh"
28 #include "TableConstraint.hh"
32 #include "asn1p.tab.hh"
34 #define yylval asn1_yylval
41 * Representation of a token.
43 class Token : public Node, public Location {
54 Token(const Token& p);
55 static bool has_semval(int p_token);
57 Token(int p_token, const Location& p_loc);
58 Token(int p_token, const YYSTYPE& p_semval, const Location& p_loc);
60 virtual Token* clone() const;
61 int get_token() const { return token; }
62 void set_token(int new_token);
63 void steal_semval(YYSTYPE& p_semval);
64 void set_loc_info() const;
65 bool is_literal_id() const;
66 bool is_literal_kw() const;
67 bool is_ampId() const;
69 static const char* get_token_name(int p_token);
70 const char* get_token_name() const { return get_token_name(token); }
71 const Identifier& get_semval_id() const;
72 /** Transforms \a this (which must be a '{' token) to a block
73 * containing \a tb. */
74 void create_block(TokenBuf *tb);
75 virtual void dump(unsigned level) const;
79 * Class to represent group of tokens. An instance of TokenBuf
80 * takes place between yyparse() and yylex(). yyparse() calls
81 * (indirectly) TokenBuf::lex(), which calls (indirectly)
82 * yylex(). TokenBuf::lex() never returns '{'; it buffers the entire
83 * {}-block in a new TokenBuf, and returns a single token which
84 * contains all the tokens (and line number information) in the
85 * block. Then this new TokenBuf can be used to parse the block.
87 class TokenBuf : public Node {
89 /** Vector type to store tokens. */
90 typedef vector<Token> tokens_t;
92 /** The Tokens. Not the band. :) */
94 /** Name of the file from where the tokens are. */
97 TokenBuf(const TokenBuf& p);
98 /** Constructs a new TokenBuf with the given tokens. */
99 TokenBuf(tokens_t *p_tokens);
100 /** Deletes the stored tokens. */
101 void delete_tokens();
102 /** Reads (yylex) the next token. Returns true on success, false
106 /** Default constructor. */
110 virtual TokenBuf* clone() const
111 {return new TokenBuf(*this);}
112 const char *get_filename() {return filename;}
113 /** Makes the buffer empty. */
114 void reset(const char *p_filename);
115 /** Inserts the given token as the first token. */
116 void push_front_token(Token *p_token);
117 /** Inserts the given keyword token as the first token. */
118 void push_front_kw_token(int p_kw);
119 /** Inserts the given token as the last token. */
120 void push_back_token(Token *p_token);
121 /** Inserts the given keyword token as the last token. */
122 void push_back_kw_token(int p_kw);
123 /** Moves the tokens from \a to to this. */
124 void move_tokens_from(TokenBuf *tb);
125 /** Removes and returns the first token. */
126 Token* pop_front_token();
127 /** Returns a reference to the token in buffer at position \a pos.
128 * Use it carefully. :) */
129 Token*& get_at(size_t pos);
130 /** Returns a token, sets the corresponding yylineno and
131 * yylval. As needed by yacc/bison. */
133 virtual void dump(unsigned level) const;
138 #endif /* _Asn_TokenBuf_HH */