Merge branch 'master' of https://github.com/alovassy/titan.core
[deliverable/titan.core.git] / langviz / Rule.cc
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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#include "Rule.hh"
9#include "Grammar.hh"
10#include "Symbol.hh"
11
12// =================================
13// ===== Rule
14// =================================
15
16Rule::Rule(const Rule& p)
17 : Node(p)
18{
19 rhs=p.rhs->clone();
20}
21
22Rule::Rule(Symbols *p_rhs)
23 : rhs(p_rhs)
24{
25 if(!p_rhs)
26 FATAL_ERROR("Rule::Rule()");
27}
28
29Rule::~Rule()
30{
31 delete rhs;
32}
33
34void Rule::replace_aliases(Grammar *grammar)
35{
36 rhs->replace_aliases(grammar);
37}
38
39// =================================
40// ===== Rules
41// =================================
42
43Rules::Rules(const Rules& p)
44 : Node(p)
45{
46 for(size_t i=0; i<p.rs.size(); i++)
47 add_r(p.rs[i]->clone());
48}
49
50Rules::~Rules()
51{
52 for(size_t i=0; i<rs.size(); i++)
53 delete rs[i];
54 rs.clear();
55}
56
57void Rules::add_r(Rule *p_r)
58{
59 if(!p_r)
60 FATAL_ERROR("NULL parameter: Rules::add_r()");
61 rs.add(p_r);
62}
63
64void Rules::steal_rules(Rules *p_other)
65{
66 for(size_t i=0; i<p_other->rs.size(); i++)
67 rs.add(p_other->rs[i]);
68 p_other->rs.clear();
69}
70
71void Rules::replace_aliases(Grammar *grammar)
72{
73 for(size_t i=0; i<rs.size(); i++)
74 rs[i]->replace_aliases(grammar);
75}
76
77// =================================
78// ===== Grouping
79// =================================
80
81Grouping::Grouping(const Grouping& p)
82 : Node(p)
83{
84 lhs=p.lhs;
85 rhss=p.rhss->clone();
86}
87
88Grouping::Grouping(Symbol *p_lhs, Rules *p_rhss)
89 : lhs(p_lhs), rhss(p_rhss)
90{
91 if(!p_lhs || !p_rhss)
92 FATAL_ERROR("Grouping::Grouping()");
93}
94
95Grouping::~Grouping()
96{
97 delete rhss;
98}
99
100void Grouping::steal_rules(Grouping *p_other)
101{
102 rhss->steal_rules(p_other->rhss);
103}
104
105void Grouping::replace_aliases(Grammar *grammar)
106{
107 lhs=grammar->get_alias(lhs);
108 rhss->replace_aliases(grammar);
109}
This page took 0.026441 seconds and 5 git commands to generate.