| 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 |
| 7 | * |
| 8 | * Contributors: |
| 9 | * Balasko, Jeno |
| 10 | * Forstner, Matyas |
| 11 | * Raduly, Csaba |
| 12 | * |
| 13 | ******************************************************************************/ |
| 14 | #ifndef _Asn_Block_HH |
| 15 | #define _Asn_Block_HH |
| 16 | |
| 17 | #include "../AST.hh" |
| 18 | |
| 19 | namespace Asn { |
| 20 | |
| 21 | using namespace Common; |
| 22 | |
| 23 | extern Node *parsed_node; |
| 24 | |
| 25 | class TokenBuf; |
| 26 | |
| 27 | /** |
| 28 | * A node which represents an unparsed block. When parsing a file, |
| 29 | * it is not always known what to expect when a block begins |
| 30 | * ('{'). So, the tokens of the block are pushed into a TokenBuf. |
| 31 | * Block is a wrapping-class for TokenBuf. As Block is a |
| 32 | * Node-descendant, it can be used in the AST. |
| 33 | * |
| 34 | * After the examination of the block's context, it is known what to |
| 35 | * expect in the block, so the block can be parsed. |
| 36 | */ |
| 37 | class Block : public Node, public Location { |
| 38 | private: |
| 39 | /** The wrapped token buffer. */ |
| 40 | TokenBuf *tokenbuf; |
| 41 | |
| 42 | Block(const Block& p); |
| 43 | public: |
| 44 | /** Constructs a Block from a TokenBuf. */ |
| 45 | Block(TokenBuf *p_tokenbuf); |
| 46 | /** The destructor. */ |
| 47 | virtual ~Block(); |
| 48 | virtual Block* clone() const |
| 49 | {return new Block(*this);} |
| 50 | /** Returns the TokenBuf. You can modify (put tokens into/remove |
| 51 | * tokens from) it, but do not delete the buffer! */ |
| 52 | TokenBuf* get_TokenBuf() {return tokenbuf;} |
| 53 | /** Parses the block. The expected content is expressed by \a |
| 54 | * kw_token, which is a constant defined in the grammar |
| 55 | * (asn1p.y). Returns an AST-subtree. To use this function, you |
| 56 | * have to include the TokenBuf header, too. */ |
| 57 | Node* parse(int kw_token); |
| 58 | |
| 59 | virtual void dump(unsigned) const; |
| 60 | }; |
| 61 | |
| 62 | } // namespace Asn |
| 63 | |
| 64 | #endif /* _Asn_Block_HH */ |