Commit | Line | Data |
---|---|---|
d44e3c4f | 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 | * | |
12 | ******************************************************************************/ | |
970ed795 EL |
13 | #include "Rule.hh" |
14 | #include "Grammar.hh" | |
15 | #include "Symbol.hh" | |
16 | ||
17 | // ================================= | |
18 | // ===== Rule | |
19 | // ================================= | |
20 | ||
21 | Rule::Rule(const Rule& p) | |
22 | : Node(p) | |
23 | { | |
24 | rhs=p.rhs->clone(); | |
25 | } | |
26 | ||
27 | Rule::Rule(Symbols *p_rhs) | |
28 | : rhs(p_rhs) | |
29 | { | |
30 | if(!p_rhs) | |
31 | FATAL_ERROR("Rule::Rule()"); | |
32 | } | |
33 | ||
34 | Rule::~Rule() | |
35 | { | |
36 | delete rhs; | |
37 | } | |
38 | ||
39 | void Rule::replace_aliases(Grammar *grammar) | |
40 | { | |
41 | rhs->replace_aliases(grammar); | |
42 | } | |
43 | ||
44 | // ================================= | |
45 | // ===== Rules | |
46 | // ================================= | |
47 | ||
48 | Rules::Rules(const Rules& p) | |
49 | : Node(p) | |
50 | { | |
51 | for(size_t i=0; i<p.rs.size(); i++) | |
52 | add_r(p.rs[i]->clone()); | |
53 | } | |
54 | ||
55 | Rules::~Rules() | |
56 | { | |
57 | for(size_t i=0; i<rs.size(); i++) | |
58 | delete rs[i]; | |
59 | rs.clear(); | |
60 | } | |
61 | ||
62 | void Rules::add_r(Rule *p_r) | |
63 | { | |
64 | if(!p_r) | |
65 | FATAL_ERROR("NULL parameter: Rules::add_r()"); | |
66 | rs.add(p_r); | |
67 | } | |
68 | ||
69 | void Rules::steal_rules(Rules *p_other) | |
70 | { | |
71 | for(size_t i=0; i<p_other->rs.size(); i++) | |
72 | rs.add(p_other->rs[i]); | |
73 | p_other->rs.clear(); | |
74 | } | |
75 | ||
76 | void Rules::replace_aliases(Grammar *grammar) | |
77 | { | |
78 | for(size_t i=0; i<rs.size(); i++) | |
79 | rs[i]->replace_aliases(grammar); | |
80 | } | |
81 | ||
82 | // ================================= | |
83 | // ===== Grouping | |
84 | // ================================= | |
85 | ||
86 | Grouping::Grouping(const Grouping& p) | |
87 | : Node(p) | |
88 | { | |
89 | lhs=p.lhs; | |
90 | rhss=p.rhss->clone(); | |
91 | } | |
92 | ||
93 | Grouping::Grouping(Symbol *p_lhs, Rules *p_rhss) | |
94 | : lhs(p_lhs), rhss(p_rhss) | |
95 | { | |
96 | if(!p_lhs || !p_rhss) | |
97 | FATAL_ERROR("Grouping::Grouping()"); | |
98 | } | |
99 | ||
100 | Grouping::~Grouping() | |
101 | { | |
102 | delete rhss; | |
103 | } | |
104 | ||
105 | void Grouping::steal_rules(Grouping *p_other) | |
106 | { | |
107 | rhss->steal_rules(p_other->rhss); | |
108 | } | |
109 | ||
110 | void Grouping::replace_aliases(Grammar *grammar) | |
111 | { | |
112 | lhs=grammar->get_alias(lhs); | |
113 | rhss->replace_aliases(grammar); | |
114 | } |