summaryrefslogtreecommitdiff
path: root/src/Expr/Expr_BinaryExpression.cxx
blob: 0415d61669a095e32b175c210138681642e541a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//static const char* sccsid = "@(#)Expr_BinaryExpression.cxx	3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: 	Matra-Datavision 1991
// File:	Expr_BinaryExpression.cxx
// Created:	Fri Apr 12 10:41:21 1991
// Author:	Arnaud BOUZY
//		<adn>

#include <Expr_BinaryExpression.ixx>
#include <Expr_NamedUnknown.hxx>
#include <Expr_InvalidOperand.hxx>
#include <Standard_OutOfRange.hxx>


void Expr_BinaryExpression::SetFirstOperand (const Handle(Expr_GeneralExpression)& exp)
{
  Handle(Expr_BinaryExpression) me;
  me = this;
  if (exp == me) {
    Expr_InvalidOperand::Raise();
  }
  if (exp->Contains(me)) {
    Expr_InvalidOperand::Raise();
  }
  myFirstOperand = exp;
}

void Expr_BinaryExpression::SetSecondOperand (const Handle(Expr_GeneralExpression)& exp)
{
  Handle(Expr_BinaryExpression) me;
  me = this;
  if (exp == me) {
    Expr_InvalidOperand::Raise();
  }
  if (exp->Contains(me)) {
    Expr_InvalidOperand::Raise();
  }
  mySecondOperand = exp;
}

void Expr_BinaryExpression::CreateFirstOperand (const Handle(Expr_GeneralExpression)& exp)
{
  myFirstOperand = exp;
}

void Expr_BinaryExpression::CreateSecondOperand (const Handle(Expr_GeneralExpression)& exp)
{
  mySecondOperand = exp;
}

Standard_Integer Expr_BinaryExpression::NbSubExpressions () const
{
  return 2;
}

const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::SubExpression (const Standard_Integer I) const
{
  if (I == 1) {
    return myFirstOperand;
  }
  else {
    if (I == 2) {
      return mySecondOperand;
    }
    else {
      Standard_OutOfRange::Raise();
    }
  }
#if defined (WNT) || !defined (DEB)
 return *(  ( Handle_Expr_GeneralExpression* )NULL  );
#endif  // WNT || !DEB
}

Standard_Boolean Expr_BinaryExpression::ContainsUnknowns () const
{
  if (myFirstOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
    return Standard_True;
  }
  if (mySecondOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
    return Standard_True;
  }
  if (myFirstOperand->ContainsUnknowns()) {
    return Standard_True;
  }
  if (mySecondOperand->ContainsUnknowns()) {
    return Standard_True;
  }
  return Standard_False;
}

Standard_Boolean Expr_BinaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
{
  if (myFirstOperand == exp) {
    return Standard_True;
  }
  if (mySecondOperand == exp) {
    return Standard_True;
  }
  if (myFirstOperand->Contains(exp)) {
    return Standard_True;
  }
  if (mySecondOperand->Contains(exp)) {
    return Standard_True;
  }
  return Standard_False;
}

void Expr_BinaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
  if (myFirstOperand == var) {
    SetFirstOperand(with);
  }
  else {
    if (myFirstOperand->Contains(var)) {
      myFirstOperand->Replace(var,with);
    }
  }
  if (mySecondOperand == var) {
    SetSecondOperand(with);
  }
  else {
    if (mySecondOperand->Contains(var)) {
      mySecondOperand->Replace(var,with);
    }
  }
}


Handle(Expr_GeneralExpression) Expr_BinaryExpression::Simplified() const
{
  Handle(Expr_BinaryExpression) cop = Handle(Expr_BinaryExpression)::DownCast(Copy());
  Handle(Expr_GeneralExpression) op1 = cop->FirstOperand();
  Handle(Expr_GeneralExpression) op2 = cop->SecondOperand();
  cop->SetFirstOperand(op1->Simplified());
  cop->SetSecondOperand(op2->Simplified());
  return cop->ShallowSimplified();
}