1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
8 #include "antlr4-common.h"
14 /// Associate a property with a parse tree node. Useful with parse tree listeners
15 /// that need to associate values with particular tree nodes, kind of like
16 /// specifying a return value for the listener event method that visited a
17 /// particular node. Example:
20 /// ParseTreeProperty<Integer> values = new ParseTreeProperty<Integer>();
21 /// values.put(tree, 36);
22 /// int x = values.get(tree);
23 /// values.removeFrom(tree);
26 /// You would make one decl (values here) in the listener and use lots of times
27 /// in your event methods.
30 class ANTLR4CPP_PUBLIC ParseTreeProperty {
32 virtual ~ParseTreeProperty() {}
33 virtual V get(ParseTree *node) {
34 return _annotations[node];
36 virtual void put(ParseTree *node, V value) {
37 _annotations[node] = value;
39 virtual V removeFrom(ParseTree *node) {
40 auto value = _annotations[node];
41 _annotations.erase(node);
46 std::map<ParseTree*, V> _annotations;