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.
17 #include <Expr_BinaryExpression.ixx>
18 #include <Expr_NamedUnknown.hxx>
19 #include <Expr_InvalidOperand.hxx>
20 #include <Standard_OutOfRange.hxx>
23 void Expr_BinaryExpression::SetFirstOperand (const Handle(Expr_GeneralExpression)& exp)
25 Handle(Expr_BinaryExpression) me;
28 Expr_InvalidOperand::Raise();
30 if (exp->Contains(me)) {
31 Expr_InvalidOperand::Raise();
36 void Expr_BinaryExpression::SetSecondOperand (const Handle(Expr_GeneralExpression)& exp)
38 Handle(Expr_BinaryExpression) me;
41 Expr_InvalidOperand::Raise();
43 if (exp->Contains(me)) {
44 Expr_InvalidOperand::Raise();
46 mySecondOperand = exp;
49 void Expr_BinaryExpression::CreateFirstOperand (const Handle(Expr_GeneralExpression)& exp)
54 void Expr_BinaryExpression::CreateSecondOperand (const Handle(Expr_GeneralExpression)& exp)
56 mySecondOperand = exp;
59 Standard_Integer Expr_BinaryExpression::NbSubExpressions () const
64 const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::SubExpression (const Standard_Integer I) const
67 return myFirstOperand;
71 return mySecondOperand;
74 Standard_OutOfRange::Raise();
77 return *( ( Handle_Expr_GeneralExpression* )NULL );
80 Standard_Boolean Expr_BinaryExpression::ContainsUnknowns () const
82 if (myFirstOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
85 if (mySecondOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
88 if (myFirstOperand->ContainsUnknowns()) {
91 if (mySecondOperand->ContainsUnknowns()) {
94 return Standard_False;
97 Standard_Boolean Expr_BinaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
99 if (myFirstOperand == exp) {
100 return Standard_True;
102 if (mySecondOperand == exp) {
103 return Standard_True;
105 if (myFirstOperand->Contains(exp)) {
106 return Standard_True;
108 if (mySecondOperand->Contains(exp)) {
109 return Standard_True;
111 return Standard_False;
114 void Expr_BinaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
116 if (myFirstOperand == var) {
117 SetFirstOperand(with);
120 if (myFirstOperand->Contains(var)) {
121 myFirstOperand->Replace(var,with);
124 if (mySecondOperand == var) {
125 SetSecondOperand(with);
128 if (mySecondOperand->Contains(var)) {
129 mySecondOperand->Replace(var,with);
135 Handle(Expr_GeneralExpression) Expr_BinaryExpression::Simplified() const
137 Handle(Expr_BinaryExpression) cop = Handle(Expr_BinaryExpression)::DownCast(Copy());
138 Handle(Expr_GeneralExpression) op1 = cop->FirstOperand();
139 Handle(Expr_GeneralExpression) op2 = cop->SecondOperand();
140 cop->SetFirstOperand(op1->Simplified());
141 cop->SetSecondOperand(op2->Simplified());
142 return cop->ShallowSimplified();