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 #if defined (WNT) || !defined (DEB)
78 return *( ( Handle_Expr_GeneralExpression* )NULL );
82 Standard_Boolean Expr_BinaryExpression::ContainsUnknowns () const
84 if (myFirstOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
87 if (mySecondOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
90 if (myFirstOperand->ContainsUnknowns()) {
93 if (mySecondOperand->ContainsUnknowns()) {
96 return Standard_False;
99 Standard_Boolean Expr_BinaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
101 if (myFirstOperand == exp) {
102 return Standard_True;
104 if (mySecondOperand == exp) {
105 return Standard_True;
107 if (myFirstOperand->Contains(exp)) {
108 return Standard_True;
110 if (mySecondOperand->Contains(exp)) {
111 return Standard_True;
113 return Standard_False;
116 void Expr_BinaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
118 if (myFirstOperand == var) {
119 SetFirstOperand(with);
122 if (myFirstOperand->Contains(var)) {
123 myFirstOperand->Replace(var,with);
126 if (mySecondOperand == var) {
127 SetSecondOperand(with);
130 if (mySecondOperand->Contains(var)) {
131 mySecondOperand->Replace(var,with);
137 Handle(Expr_GeneralExpression) Expr_BinaryExpression::Simplified() const
139 Handle(Expr_BinaryExpression) cop = Handle(Expr_BinaryExpression)::DownCast(Copy());
140 Handle(Expr_GeneralExpression) op1 = cop->FirstOperand();
141 Handle(Expr_GeneralExpression) op2 = cop->SecondOperand();
142 cop->SetFirstOperand(op1->Simplified());
143 cop->SetSecondOperand(op2->Simplified());
144 return cop->ShallowSimplified();