Skip to content

Commit f22d0a1

Browse files
author
jon-lugo
committed
Added a notion of a revert point in the contexts used in Dynamicjava so that the user is able to set a revert point in the context and undo up to that point in the future. This undo causes any bindings made since the last revert point to be unbound.
git-svn-id: file:///tmp/test-svn/trunk@2966 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 8a844a8 commit f22d0a1

File tree

12 files changed

+286
-281
lines changed

12 files changed

+286
-281
lines changed

dynamicjava/src/koala/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* This file is copied to Version.java by the build process, which also
5454
* fills in the right values of the date and time.
5555
*
56-
* This javadoc corresponds to build drjava-20050318-2057;
56+
* This javadoc corresponds to build drjava-20050328-1824;
5757
*
5858
* @version $Id$
5959
*/
@@ -62,7 +62,7 @@ public abstract class Version {
6262
* This string will be automatically expanded upon "ant commit".
6363
* Do not edit it by hand!
6464
*/
65-
private static final String BUILD_TIME_STRING = "20050318-2057";
65+
private static final String BUILD_TIME_STRING = "20050328-1824";
6666

6767
/** A {@link Date} version of the build time. */
6868
private static final Date BUILD_TIME = _getBuildDate();

dynamicjava/src/koala/dynamicjava/classfile/MethodInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ public MethodInfo(ConstantPool cp, String rt, String nm, String[] pt) {
112112
constantPool = cp;
113113
nameIndex = constantPool.putUTF8(nm);
114114
setSignature(rt, pt);
115+
_nm = nm;
115116
}
116-
117+
String _nm;
117118
/**
118119
* Writes the method info to the given output stream
119120
*/

dynamicjava/src/koala/dynamicjava/interpreter/AbstractTypeChecker.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -554,28 +554,28 @@ public Class<?> visit(VariableDeclaration node) {
554554
return null;
555555
}
556556

557-
/**
558-
* This method visits a variable declaration without actually defining
559-
* anything in the context. This method was added to allow other objects
560-
* to type check a variable declaration without actually creating a new
561-
* binding in the context. This behavior was added so that when a
562-
* variable declaration has some error in it, the declaration would not
563-
* make it into the context. (this method should be run on an individual
564-
* variable declaration before the type checker visitor is formally
565-
* executed on the entire AST)
566-
* @param node the variable declaration to check
567-
*/
568-
public void preCheckVariableDeclaration(VariableDeclaration node) {
569-
Class<?> lc = node.getType().acceptVisitor(this);
570-
Expression init = node.getInitializer();
571-
if (init != null) {
572-
Class<?> rc = init.acceptVisitor(this);
573-
// this call to checkAssignmentStaticRules is not
574-
// intended to mutate the AST for autoboxing/unboxing
575-
checkAssignmentStaticRules(lc, rc, node, init);
576-
}
577-
}
578-
557+
// /**
558+
// * This method visits a variable declaration without actually defining
559+
// * anything in the context. This method was added to allow other objects
560+
// * to type check a variable declaration without actually creating a new
561+
// * binding in the context. This behavior was added so that when a
562+
// * variable declaration has some error in it, the declaration would not
563+
// * make it into the context. (this method should be run on an individual
564+
// * variable declaration before the type checker visitor is formally
565+
// * executed on the entire AST)
566+
// * @param node the variable declaration to check
567+
// */
568+
// public void preCheckVariableDeclaration(VariableDeclaration node) {
569+
// Class<?> lc = node.getType().acceptVisitor(this);
570+
// Expression init = node.getInitializer();
571+
// if (init != null) {
572+
// Class<?> rc = init.acceptVisitor(this);
573+
// // this call to checkAssignmentStaticRules is not
574+
// // intended to mutate the AST for autoboxing/unboxing
575+
// checkAssignmentStaticRules(lc, rc, node, init);
576+
// }
577+
// }
578+
579579
/**
580580
* Visits a BlockStatement
581581
* @param node the node to visit

dynamicjava/src/koala/dynamicjava/interpreter/ClassInfoCompiler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ public Class<?> compile() {
199199

200200
// Define the class
201201
TreeClassLoader classLoader = (TreeClassLoader)interpreter.getClassLoader();
202-
return classLoader.defineClass(name, classFactory.getByteCode());
202+
Class<?> result = classLoader.defineClass(name, classFactory.getByteCode());
203+
204+
return result;
203205
}
204206

205207
/**

dynamicjava/src/koala/dynamicjava/interpreter/EvaluationVisitor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,9 @@ else if (last != null && typs[i].isAssignableFrom(last.getClass())){
928928
args = new Object[]{Array.newInstance(compType, 0)};
929929
}
930930
}
931-
932931
// Invoke the method
933932
try {
934-
Object res = m.invoke(obj, args);
935-
return res;
933+
return m.invoke(obj, args);
936934
}
937935
catch (InvocationTargetException e) {
938936
if (e.getTargetException() instanceof Error) {

dynamicjava/src/koala/dynamicjava/interpreter/context/SimpleContext.java

Lines changed: 110 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -40,100 +40,113 @@
4040
*/
4141

4242
public interface SimpleContext {
43-
/**
44-
* Enters a scope
45-
*/
46-
void enterScope();
47-
48-
/**
49-
* Enters a scope and defines the given entries to null.
50-
* @param entries a set of string
51-
*/
52-
void enterScope(Set<AbstractVariable> entries);
53-
54-
/**
55-
* Defines the given variables
56-
*/
57-
void defineVariables(Set<AbstractVariable> vars);
58-
59-
/**
60-
* Returns the current scope variables (AbstractVariables) in a set
61-
*/
62-
Set<AbstractVariable> getCurrentScopeVariables();
63-
64-
/**
65-
* Returns the current scope variable names in a set
66-
*/
67-
Set<String> getCurrentScopeVariableNames();
68-
69-
/**
70-
* Leaves the current scope
71-
* @return the set of the variables (strings) defined in the current scope
72-
*/
73-
Set leaveScope();
74-
75-
/**
76-
* Tests whether a variable is defined in this context
77-
* @param name the name of the entry
78-
* @return false if the variable is undefined
79-
*/
80-
boolean isDefinedVariable(String name);
81-
82-
/**
83-
* Tests whether a variable is final in this context
84-
* @param name the name of the entry
85-
* @return false if the variable is not final
86-
* @exception IllegalStateException if the variable is not defined
87-
*/
88-
boolean isFinal(String name);
89-
90-
/**
91-
* Defines a new variable in the current scope
92-
* @param name the name of the new entry
93-
* @param value the value of the entry
94-
* @exception IllegalStateException if the variable is already defined
95-
*/
96-
void define(String name, Object value);
97-
98-
/**
99-
* Defines a new constant variable in the current scope
100-
* @param name the name of the new entry
101-
* @param value the value of the entry
102-
* @exception IllegalStateException if the variable is already defined
103-
*/
104-
void defineConstant(String name, Object value);
105-
106-
/**
107-
* Returns the value of a variable with the given name
108-
* @param name the name of the value to get
109-
* @exception IllegalStateException if the variable is not defined
110-
*/
111-
Object get(String name);
112-
113-
/**
114-
* Sets the value of a defined variable
115-
* @param name the name of the new entry
116-
* @param value the value of the entry
117-
* @exception IllegalStateException if the variable is not defined
118-
*/
119-
void set(String name, Object value);
120-
121-
/**
122-
* Defines a new constant variable in the current scope
123-
* @param name the name of the new entry
124-
* @param value the value of the entry
125-
*/
126-
void setConstant(String name, Object value);
127-
128-
/**
129-
* Defines a new variable in the current scope
130-
* @param name the name of the new entry
131-
* @param value the value of the entry
132-
*/
133-
void setVariable(String name, Object value);
134-
135-
/**
136-
* Creates a map that contains the constants in this context
137-
*/
138-
Map getConstants();
139-
}
43+
/**
44+
* Enters a scope
45+
*/
46+
void enterScope();
47+
48+
/**
49+
* Enters a scope and defines the given entries to null.
50+
* @param entries a set of string
51+
*/
52+
void enterScope(Set<AbstractVariable> entries);
53+
54+
/**
55+
* Defines the given variables
56+
*/
57+
void defineVariables(Set<AbstractVariable> vars);
58+
59+
/**
60+
* Returns the current scope variables (AbstractVariables) in a set
61+
*/
62+
Set<AbstractVariable> getCurrentScopeVariables();
63+
64+
/**
65+
* Returns the current scope variable names in a set
66+
*/
67+
Set<String> getCurrentScopeVariableNames();
68+
69+
/**
70+
* Leaves the current scope
71+
* @return the set of the variables (strings) defined in the current scope
72+
*/
73+
Set leaveScope();
74+
75+
/**
76+
* Tests whether a variable is defined in this context
77+
* @param name the name of the entry
78+
* @return false if the variable is undefined
79+
*/
80+
boolean isDefinedVariable(String name);
81+
82+
/**
83+
* Tests whether a variable is final in this context
84+
* @param name the name of the entry
85+
* @return false if the variable is not final
86+
* @exception IllegalStateException if the variable is not defined
87+
*/
88+
boolean isFinal(String name);
89+
90+
/**
91+
* Defines a new variable in the current scope
92+
* @param name the name of the new entry
93+
* @param value the value of the entry
94+
* @exception IllegalStateException if the variable is already defined
95+
*/
96+
void define(String name, Object value);
97+
98+
/**
99+
* Defines a new constant variable in the current scope
100+
* @param name the name of the new entry
101+
* @param value the value of the entry
102+
* @exception IllegalStateException if the variable is already defined
103+
*/
104+
void defineConstant(String name, Object value);
105+
106+
/**
107+
* Returns the value of a variable with the given name
108+
* @param name the name of the value to get
109+
* @exception IllegalStateException if the variable is not defined
110+
*/
111+
Object get(String name);
112+
113+
/**
114+
* Sets the value of a defined variable
115+
* @param name the name of the new entry
116+
* @param value the value of the entry
117+
* @exception IllegalStateException if the variable is not defined
118+
*/
119+
void set(String name, Object value);
120+
121+
/**
122+
* Defines a new constant variable in the current scope
123+
* @param name the name of the new entry
124+
* @param value the value of the entry
125+
*/
126+
void setConstant(String name, Object value);
127+
128+
/**
129+
* Defines a new variable in the current scope
130+
* @param name the name of the new entry
131+
* @param value the value of the entry
132+
*/
133+
void setVariable(String name, Object value);
134+
135+
/**
136+
* Creates a map that contains the constants in this context
137+
*/
138+
Map getConstants();
139+
140+
141+
/**
142+
* Sets a revert point such that calling revert will remove
143+
* any variable or constant bindings set after this point.
144+
*/
145+
void setRevertPoint();
146+
147+
/**
148+
* Removes any bindings set after the last call to setRevertPoint
149+
*/
150+
void revert();
151+
152+
}

0 commit comments

Comments
 (0)