001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: // This file is taken from the RECODER library, which is protected by the LGPL,
012: // and modified.
013: /** This class is part of the AST RECODER builds when it parses and resolves Java
014: * programs with meta constructs and schema variables. It is transformed by Recoder2KeY
015: * to a subclass of ...rule.metaconstruct.ProgramMetaConstruct.
016: */package de.uka.ilkd.key.java.recoderext;
017:
018: import recoder.convenience.TreeWalker;
019: import recoder.java.*;
020: import recoder.java.expression.Literal;
021:
022: public class RKeYMetaConstructExpression extends Literal implements
023: ExpressionContainer, KeYRecoderExtension {
024:
025: /**
026: Child
027: */
028: protected Expression child = null;
029: protected String name = "";
030:
031: protected RKeYMetaConstructExpression(
032: RKeYMetaConstructExpression proto) {
033: super (proto);
034: if (proto.child != null) {
035: child = (Expression) proto.child.deepClone();
036: }
037: }
038:
039: public RKeYMetaConstructExpression() {
040: }
041:
042: /**
043: Make parent role valid.
044: */
045: public void makeParentRoleValid() {
046: if (child != null) {
047: child.setExpressionContainer(this );
048: }
049: }
050:
051: /**
052: Returns the number of children of this node.
053: @return an int giving the number of children of this node
054: */
055: public int getChildCount() {
056: int result = 0;
057: if (child != null)
058: result++;
059: return result;
060: }
061:
062: /**
063: Returns the child at the specified index in this node's "virtual"
064: child array
065: @param index an index into this node's "virtual" child array
066: @return the program element at the given position
067: @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
068: of bounds
069: */
070: public ProgramElement getChildAt(int index) {
071: if (child != null) {
072: if (index == 0)
073: return child;
074: }
075: throw new ArrayIndexOutOfBoundsException();
076: }
077:
078: public int getChildPositionCode(ProgramElement child0) {
079: // role 0: child
080: if (child0 == child) {
081: return 0;
082: }
083: return -1;
084: }
085:
086: public int getIndexOfChild(ProgramElement pe) {
087: if (pe == child) {
088: return 0;
089: }
090: return -1;
091: }
092:
093: public int getIndexOfChild(int posCode) {
094: if (posCode == getChildPositionCode(child)) {
095: return 0;
096: }
097: return -1;
098: }
099:
100: public int getRoleOfChild(int i) {
101: if (i == 0)
102: return getChildPositionCode(child);
103: return -1;
104: }
105:
106: public void makeAllParentRolesValid() {
107: TreeWalker tw = new TreeWalker(this );
108: while (tw.next(NonTerminalProgramElement.class)) {
109: ((NonTerminalProgramElement) tw.getProgramElement())
110: .makeParentRoleValid();
111: }
112: }
113:
114: public boolean replaceChild(ProgramElement p, ProgramElement q) {
115: if (child == p) {
116: Expression r = (Expression) q;
117: child = r;
118: if (r != null) {
119: r.setExpressionContainer(this );
120: }
121: return true;
122: }
123: return false;
124: }
125:
126: /**
127: * sets a String name of this meta construct like 'unwind-loop'
128: * @param s the String
129: */
130: public void setName(String s) {
131: name = s;
132: }
133:
134: /**
135: * returns a String name of this meta construct.
136: */
137: public String getName() {
138: return name;
139: }
140:
141: /**
142: Get child.
143: @return the expression.
144: */
145:
146: public Expression getChild() {
147: return child;
148: }
149:
150: /**
151: Set child.
152: @param expression a expression.
153: */
154:
155: public void setChild(Expression expression) {
156: child = expression;
157: }
158:
159: /**
160: Get the number of expression in this container.
161: @return the number of expressions.
162: */
163:
164: public int getExpressionCount() {
165: return (child != null) ? 1 : 0;
166: }
167:
168: /*
169: Return the expression at the specified index in this node's
170: "virtual" expression array.
171: @param index an index for a expression.
172: @return the expression with the given index.
173: @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
174: of bounds.
175: */
176:
177: public Expression getExpressionAt(int index) {
178: if (child != null && index == 0) {
179: return child;
180: }
181: throw new ArrayIndexOutOfBoundsException();
182: }
183:
184: //don't think we need it
185: public void accept(SourceVisitor v) {
186: }
187:
188: //???
189: public Object deepClone() {
190: return null;
191: }
192:
193: }
|