1 // Created on: 1991-04-12
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Expr_BinaryExpression.hxx>
19 #include <Expr_GeneralExpression.hxx>
20 #include <Expr_InvalidOperand.hxx>
21 #include <Expr_NamedUnknown.hxx>
22 #include <Standard_NumericError.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <Standard_Type.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(Expr_BinaryExpression,Expr_GeneralExpression)
28 void Expr_BinaryExpression::SetFirstOperand (const Handle(Expr_GeneralExpression)& exp)
30 Handle(Expr_BinaryExpression) me;
33 throw Expr_InvalidOperand();
35 if (exp->Contains(me)) {
36 throw Expr_InvalidOperand();
41 void Expr_BinaryExpression::SetSecondOperand (const Handle(Expr_GeneralExpression)& exp)
43 Handle(Expr_BinaryExpression) me;
46 throw Expr_InvalidOperand();
48 if (exp->Contains(me)) {
49 throw Expr_InvalidOperand();
51 mySecondOperand = exp;
54 void Expr_BinaryExpression::CreateFirstOperand (const Handle(Expr_GeneralExpression)& exp)
59 void Expr_BinaryExpression::CreateSecondOperand (const Handle(Expr_GeneralExpression)& exp)
61 mySecondOperand = exp;
64 Standard_Integer Expr_BinaryExpression::NbSubExpressions () const
69 const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::SubExpression (const Standard_Integer I) const
72 return myFirstOperand;
76 return mySecondOperand;
79 throw Standard_OutOfRange();
84 Standard_Boolean Expr_BinaryExpression::ContainsUnknowns () const
86 if (myFirstOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
89 if (mySecondOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
92 if (myFirstOperand->ContainsUnknowns()) {
95 if (mySecondOperand->ContainsUnknowns()) {
98 return Standard_False;
101 Standard_Boolean Expr_BinaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
103 if (myFirstOperand == exp) {
104 return Standard_True;
106 if (mySecondOperand == exp) {
107 return Standard_True;
109 if (myFirstOperand->Contains(exp)) {
110 return Standard_True;
112 if (mySecondOperand->Contains(exp)) {
113 return Standard_True;
115 return Standard_False;
118 void Expr_BinaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
120 if (myFirstOperand == var) {
121 SetFirstOperand(with);
124 if (myFirstOperand->Contains(var)) {
125 myFirstOperand->Replace(var,with);
128 if (mySecondOperand == var) {
129 SetSecondOperand(with);
132 if (mySecondOperand->Contains(var)) {
133 mySecondOperand->Replace(var,with);
139 Handle(Expr_GeneralExpression) Expr_BinaryExpression::Simplified() const
141 Handle(Expr_BinaryExpression) cop = Handle(Expr_BinaryExpression)::DownCast(Copy());
142 Handle(Expr_GeneralExpression) op1 = cop->FirstOperand();
143 Handle(Expr_GeneralExpression) op2 = cop->SecondOperand();
144 cop->SetFirstOperand(op1->Simplified());
145 cop->SetSecondOperand(op2->Simplified());
146 return cop->ShallowSimplified();