b311480e |
1 | // Created on: 1992-02-25 |
2 | // Created by: Arnaud BOUZY |
3 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #define _ExprIntrp_Analysis_SourceFile |
18 | |
42cf5bc1 |
19 | |
20 | #include <Expr_GeneralExpression.hxx> |
21 | #include <Expr_GeneralFunction.hxx> |
22 | #include <Expr_GeneralRelation.hxx> |
23 | #include <Expr_NamedExpression.hxx> |
24 | #include <Expr_NamedFunction.hxx> |
7fd59977 |
25 | #include <Expr_NamedUnknown.hxx> |
42cf5bc1 |
26 | #include <ExprIntrp_Analysis.hxx> |
27 | #include <ExprIntrp_Generator.hxx> |
28 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
29 | |
30 | ExprIntrp_Analysis::ExprIntrp_Analysis() {} |
31 | |
32 | |
33 | void ExprIntrp_Analysis::Push(const Handle(Expr_GeneralExpression)& exp) |
34 | { |
6af4fe1c |
35 | myGEStack.Prepend(exp); |
7fd59977 |
36 | } |
37 | |
38 | void ExprIntrp_Analysis::PushRelation(const Handle(Expr_GeneralRelation)& rel) |
39 | { |
6af4fe1c |
40 | myGRStack.Prepend(rel); |
7fd59977 |
41 | } |
42 | |
43 | void ExprIntrp_Analysis::PushFunction(const Handle(Expr_GeneralFunction)& func) |
44 | { |
6af4fe1c |
45 | myGFStack.Prepend(func); |
7fd59977 |
46 | } |
47 | |
48 | void ExprIntrp_Analysis::PushName(const TCollection_AsciiString& name) |
49 | { |
6af4fe1c |
50 | myNameStack.Prepend(name); |
7fd59977 |
51 | } |
52 | |
53 | void ExprIntrp_Analysis::PushValue(const Standard_Integer val) |
54 | { |
6af4fe1c |
55 | myValueStack.Prepend(val); |
7fd59977 |
56 | } |
57 | |
58 | Handle(Expr_GeneralExpression) ExprIntrp_Analysis::Pop() |
59 | { |
60 | Handle(Expr_GeneralExpression) res; |
61 | if (!myGEStack.IsEmpty()) { |
6af4fe1c |
62 | res = myGEStack.First(); |
63 | myGEStack.RemoveFirst(); |
7fd59977 |
64 | } |
65 | return res; |
66 | } |
67 | |
68 | Handle(Expr_GeneralRelation) ExprIntrp_Analysis::PopRelation() |
69 | { |
70 | Handle(Expr_GeneralRelation) res; |
71 | if (!myGRStack.IsEmpty()) { |
6af4fe1c |
72 | res = myGRStack.First(); |
73 | myGRStack.RemoveFirst(); |
7fd59977 |
74 | } |
75 | return res; |
76 | } |
77 | |
78 | Handle(Expr_GeneralFunction) ExprIntrp_Analysis::PopFunction() |
79 | { |
80 | Handle(Expr_GeneralFunction) res; |
81 | if (!myGFStack.IsEmpty()) { |
6af4fe1c |
82 | res = myGFStack.First(); |
83 | myGFStack.RemoveFirst(); |
7fd59977 |
84 | } |
85 | return res; |
86 | } |
87 | |
88 | TCollection_AsciiString ExprIntrp_Analysis::PopName() |
89 | { |
90 | TCollection_AsciiString res; |
91 | if (!myNameStack.IsEmpty()) { |
6af4fe1c |
92 | res = myNameStack.First(); |
93 | myNameStack.RemoveFirst(); |
7fd59977 |
94 | } |
95 | return res; |
96 | } |
97 | |
98 | Standard_Integer ExprIntrp_Analysis::PopValue() |
99 | { |
100 | Standard_Integer res =0; |
101 | if (!myValueStack.IsEmpty()) { |
6af4fe1c |
102 | res = myValueStack.First(); |
103 | myValueStack.RemoveFirst(); |
7fd59977 |
104 | } |
105 | return res; |
106 | } |
107 | |
108 | Standard_Boolean ExprIntrp_Analysis::IsExpStackEmpty() const |
109 | { |
110 | return myGEStack.IsEmpty(); |
111 | } |
112 | |
113 | Standard_Boolean ExprIntrp_Analysis::IsRelStackEmpty() const |
114 | { |
115 | return myGRStack.IsEmpty(); |
116 | } |
117 | |
118 | void ExprIntrp_Analysis::ResetAll() |
119 | { |
120 | myGEStack.Clear(); |
121 | myGRStack.Clear(); |
122 | myGFStack.Clear(); |
123 | myNameStack.Clear(); |
124 | myValueStack.Clear(); |
125 | myFunctions.Clear(); |
126 | myNamed.Clear(); |
127 | } |
128 | |
129 | void ExprIntrp_Analysis::SetMaster(const Handle(ExprIntrp_Generator)& agen) |
130 | { |
131 | ResetAll(); |
132 | myMaster = agen; |
133 | myFunctions = myMaster->GetFunctions(); |
134 | myNamed = myMaster->GetNamed(); |
135 | } |
136 | |
137 | void ExprIntrp_Analysis::Use(const Handle(Expr_NamedFunction)& func) |
138 | { |
139 | myFunctions.Append(func); |
140 | myMaster->Use(func); |
141 | } |
142 | |
143 | void ExprIntrp_Analysis::Use(const Handle(Expr_NamedExpression)& named) |
144 | { |
145 | myNamed.Append(named); |
146 | myMaster->Use(named); |
147 | } |
148 | |
149 | Handle(Expr_NamedExpression) ExprIntrp_Analysis::GetNamed(const TCollection_AsciiString& name) |
150 | { |
151 | for (Standard_Integer i=1; i<= myNamed.Length();i++) { |
152 | if (name == myNamed(i)->GetName()) { |
153 | return myNamed(i); |
154 | } |
155 | } |
156 | Handle(Expr_NamedExpression) curnamed; |
157 | return curnamed; |
158 | } |
159 | |
160 | Handle(Expr_NamedFunction) ExprIntrp_Analysis::GetFunction(const TCollection_AsciiString& name) |
161 | { |
162 | for (Standard_Integer i=1; i<= myFunctions.Length();i++) { |
163 | if (name == myFunctions(i)->GetName()) { |
164 | return myFunctions(i); |
165 | } |
166 | } |
167 | Handle(Expr_NamedFunction) curfunc; |
168 | return curfunc; |
169 | } |