-
Notifications
You must be signed in to change notification settings - Fork 8
/
BExpression.java
93 lines (72 loc) · 2.43 KB
/
BExpression.java
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
import java.util.Vector;
/* Package: B */
/******************************
* Copyright (c) 2003,2019 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
public abstract class BExpression
{ protected boolean needsBracket = false;
protected int multiplicity = ModelElement.ONE;
protected int kind = Expression.UNKNOWN;
public final static int ROOT = 0;
public final static int SUBCLASS = 1;
public final static int FEATURE = 2;
public final static int LOGICAL = 3;
protected int category = LOGICAL;
public void setKind(int k)
{ kind = k; }
public int getKind()
{ return kind; }
public void setCategory(int c)
{ category = c; }
public int getCategory()
{ return category; }
public abstract boolean setValued();
public abstract BExpression simplify();
public BExpression substituteEq(String oldE, BExpression newE)
{ return this; } // default
public void setMultiplicity(int m)
{ multiplicity = m; }
public static BExpression makeSet(BExpression e)
{ if (e.setValued()) { return e; }
Vector elems = new Vector();
elems.add(e);
return new BSetExpression(elems);
}
public static BExpression unmakeSet(BExpression e)
{ if (e == null) { return e; } // should not occur
if (e instanceof BSetExpression)
{ BSetExpression bset = (BSetExpression) e;
if (bset.isSingleton())
{ BExpression res = bset.getElement(0);
return res;
}
}
return e;
}
public static BExpression unSet(BExpression e)
{ if (e == null) { return e; }
if (e instanceof BSetExpression)
{ BSetExpression se = (BSetExpression) e;
if (se.isSingleton())
{ BExpression res = se.getElement(0);
System.out.println(res + " IS SET-VALUED: " + res.setValued());
if (res.setValued())
{ return res; }
}
}
return e;
}
public void setBrackets(boolean brack)
{ needsBracket = brack; }
public boolean conflictsWith(final BExpression e)
{ return false; } // default
public boolean conflictsWith(String op, BExpression el,
BExpression er)
{ return false; }
public abstract Vector rd();
}