Posted by Andrey Tarantsov Sat 24th Feb 2007 19:56 - Syntax is Diff - 55 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
### Eclipse Workspace Patch 1.0
-
#P org.eclipse.dltk.core
-
Index: typeinference/org/eclipse/dltk/ddp/BasicContext.java
-
===================================================================
-
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/typeinference/org/eclipse/dltk/ddp/BasicContext.java,v
-
retrieving revision 1.1
-
diff -u -r1.1 BasicContext.java
-
--- typeinference/org/eclipse/dltk/ddp/BasicContext.java 23 Feb 2007 14:22:15 -0000 1.1
-
+++ typeinference/org/eclipse/dltk/ddp/BasicContext.java 24 Feb 2007 19:52:24 -0000
-
@@ -13,6 +13,11 @@
-
this.rootNode = rootNode;
-
}
-
-
+ public BasicContext(BasicContext parent) {
-
+ sourceModule = parent.sourceModule;
-
+ rootNode = parent.rootNode;
-
+ }
-
+
-
public ModuleDeclaration getRootNode() {
-
return rootNode;
-
}
-
#P org.eclipse.dltk.ruby.core.tests
-
Index: workspace/typeinference/variables/self_singletons.rb
-
===================================================================
-
RCS file: workspace/typeinference/variables/self_singletons.rb
-
diff -N workspace/typeinference/variables/self_singletons.rb
-
--- /dev/null 1 Jan 1970 00:00:00 -0000
-
+++ workspace/typeinference/variables/self_singletons.rb 1 Jan 1970 00:00:00 -0000
-
@@ -0,0 +1,18 @@
-
+
-
+class BozSelfSingletons
-
+ class Bar
-
+ self ## expr self => BozSelfSingletons::Bar
-
+
-
+ def foo
-
+ self ## expr self => BozSelfSingletons::Bar.new
-
+ end
-
+
-
+ def self.foo
-
+ self ## expr self => BozSelfSingletons::Bar
-
+ end
-
+
-
+ def Bar.foo
-
+ self ## expr self => BozSelfSingletons::Bar
-
+ end
-
+ end
-
+end
-
#P org.eclipse.dltk.ruby.core
-
Index: src/org/eclipse/dltk/ruby/typeinference/RubyTypeInferencingUtils.java
-
===================================================================
-
RCS file: /cvsroot/technology/org.eclipse.dltk/ruby/plugins/org.eclipse.dltk.ruby.core/src/org/eclipse/dltk/ruby/typeinference/RubyTypeInferencingUtils.java,v
-
retrieving revision 1.3
-
diff -u -r1.3 RubyTypeInferencingUtils.java
-
--- src/org/eclipse/dltk/ruby/typeinference/RubyTypeInferencingUtils.java 24 Feb 2007 18:56:59 -0000 1.3
-
+++ src/org/eclipse/dltk/ruby/typeinference/RubyTypeInferencingUtils.java 24 Feb 2007 19:52:27 -0000
-
@@ -32,6 +32,8 @@
-
import org.eclipse.dltk.core.search.SearchEngine;
-
import org.eclipse.dltk.core.search.SearchParticipant;
-
import org.eclipse.dltk.core.search.SearchPattern;
-
+import org.eclipse.dltk.ddp.BasicContext;
-
+import org.eclipse.dltk.ddp.IContext;
-
import org.eclipse.dltk.evaluation.types.AmbiguousType;
-
import org.eclipse.dltk.evaluation.types.IClassType;
-
import org.eclipse.dltk.evaluation.types.IEvaluatedType;
-
@@ -265,6 +267,17 @@
-
return null;
-
}
-
-
+ public static IEvaluatedType determineSelfClass(IContext context, int keyOffset) {
-
+ if (context instanceof InstanceContext) {
-
+ InstanceContext instanceContext = (InstanceContext) context;
-
+ return instanceContext.getInstanceType();
-
+ } else {
-
+ BasicContext basicContext = (BasicContext) context;
-
+ return determineSelfClass(basicContext.getSourceModule(), basicContext.getRootNode(),
-
+ keyOffset);
-
+ }
-
+ }
-
+
-
/**
-
* Determines a fully-qualified names of the class scope that the given
-
* offset is statically enclosed in.
-
Index: src/org/eclipse/dltk/ruby/typeinference/InstanceContext.java
-
===================================================================
-
RCS file: /cvsroot/technology/org.eclipse.dltk/ruby/plugins/org.eclipse.dltk.ruby.core/src/org/eclipse/dltk/ruby/typeinference/InstanceContext.java,v
-
retrieving revision 1.1
-
diff -u -r1.1 InstanceContext.java
-
--- src/org/eclipse/dltk/ruby/typeinference/InstanceContext.java 24 Feb 2007 18:56:59 -0000 1.1
-
+++ src/org/eclipse/dltk/ruby/typeinference/InstanceContext.java 24 Feb 2007 19:52:27 -0000
-
@@ -13,6 +13,11 @@
-
super(sourceModule, rootNode);
-
this.instanceType = instanceType;
-
}
-
+
-
+ public InstanceContext(BasicContext parent, IEvaluatedType instanceType) {
-
+ super(parent);
-
+ this.instanceType = instanceType;
-
+ }
-
-
public IEvaluatedType getInstanceType() {
-
return instanceType;
-
Index: src/org/eclipse/dltk/ruby/typeinference/RubyEvaluatorFactory.java
-
===================================================================
-
RCS file: /cvsroot/technology/org.eclipse.dltk/ruby/plugins/org.eclipse.dltk.ruby.core/src/org/eclipse/dltk/ruby/typeinference/RubyEvaluatorFactory.java,v
-
retrieving revision 1.3
-
diff -u -r1.3 RubyEvaluatorFactory.java
-
--- src/org/eclipse/dltk/ruby/typeinference/RubyEvaluatorFactory.java 24 Feb 2007 18:56:59 -0000 1.3
-
+++ src/org/eclipse/dltk/ruby/typeinference/RubyEvaluatorFactory.java 24 Feb 2007 19:52:27 -0000
-
@@ -1,6 +1,7 @@
-
package org.eclipse.dltk.ruby.typeinference;
-
-
import org.eclipse.dltk.ast.expressions.Assignment;
-
+import org.eclipse.dltk.ast.expressions.CallExpression;
-
import org.eclipse.dltk.ast.expressions.NumericLiteral;
-
import org.eclipse.dltk.ast.expressions.StringLiteral;
-
import org.eclipse.dltk.ast.references.ConstantReference;
-
@@ -32,8 +33,12 @@
-
return new AssignmentEvaluator(goal);
-
else if (expr instanceof SelfReference)
-
return new SelfReferenceEvaluator(goal);
-
+ else if (expr instanceof CallExpression)
-
+ return new MethodCallTypeEvaluator((ExpressionGoal) goal);
-
} else if (goal instanceof ConstantTypeGoal)
-
return new ConstantReferenceEvaluator((ConstantTypeGoal) goal);
-
+ else if (goal instanceof MethodReturnTypeGoal)
-
+ return new StringLiteralEvaluator(goal);
-
return null;
-
}
-
-
Index: src/org/eclipse/dltk/ruby/typeinference/MethodCallTypeEvaluator.java
-
===================================================================
-
RCS file: /cvsroot/technology/org.eclipse.dltk/ruby/plugins/org.eclipse.dltk.ruby.core/src/org/eclipse/dltk/ruby/typeinference/MethodCallTypeEvaluator.java,v
-
retrieving revision 1.1
-
diff -u -r1.1 MethodCallTypeEvaluator.java
-
--- src/org/eclipse/dltk/ruby/typeinference/MethodCallTypeEvaluator.java 24 Feb 2007 18:56:59 -0000 1.1
-
+++ src/org/eclipse/dltk/ruby/typeinference/MethodCallTypeEvaluator.java 24 Feb 2007 19:52:27 -0000
-
@@ -1,22 +1,110 @@
-
package org.eclipse.dltk.ruby.typeinference;
-
-
+import java.util.List;
-
+
-
+import org.eclipse.dltk.ast.expressions.CallExpression;
-
+import org.eclipse.dltk.ast.statements.Statement;
-
+import org.eclipse.dltk.ddp.BasicContext;
-
import org.eclipse.dltk.ddp.ExpressionGoal;
-
import org.eclipse.dltk.ddp.GoalEvaluator;
-
import org.eclipse.dltk.ddp.IGoal;
-
import org.eclipse.dltk.evaluation.types.IEvaluatedType;
-
+import org.eclipse.dltk.ruby.ast.SelfReference;
-
-
public class MethodCallTypeEvaluator extends GoalEvaluator {
-
-
+ private final static int STATE_INIT = 0;
-
+
-
+ private final static int STATE_WAITING_RECEIVER = 1;
-
+
-
+ private final static int STATE_GOT_RECEIVER = 1;
-
+
-
+ private final static int STATE_WAITING_ARGUMENT_0 = 3;
-
+
-
+ private final static int STATE_ARGS_DONE = 10000;
-
+
-
+ private final static int STATE_WAITING_METHOD = 10001;
-
+
-
+ private final static int STATE_UNKNOWN = -1;
-
+
-
+ private final static int STATE_DONE = -2;
-
+
-
+ private int state = STATE_INIT;
-
+
-
+ private IEvaluatedType receiverType;
-
+
-
+ private IEvaluatedType[] arguments;
-
+
-
+ private IEvaluatedType result;
-
+
-
public MethodCallTypeEvaluator(ExpressionGoal goal) {
-
super(goal);
-
}
-
-
public IGoal produceNextSubgoal(IGoal previousGoal, IEvaluatedType previousResult) {
-
+ if (state == STATE_INIT) {
-
+ ExpressionGoal typedGoal = (ExpressionGoal) goal;
-
+ CallExpression expression = (CallExpression) typedGoal.getExpression();
-
+ Statement receiver = expression.getReceiver();
-
+ if (receiver == null || receiver instanceof SelfReference) {
-
+ // handling SelfReference here just for simplicity, could be
-
+ // left to the TI engine as well
-
+ receiverType = RubyTypeInferencingUtils.determineSelfClass(goal.getContext(),
-
+ expression.sourceStart());
-
+ state = STATE_GOT_RECEIVER;
-
+ } else {
-
+ state = STATE_WAITING_RECEIVER;
-
+ return new ExpressionGoal(goal.getContext(), receiver);
-
+ }
-
+ }
-
+ if (state == STATE_WAITING_RECEIVER) {
-
+ receiverType = previousResult;
-
+ if (receiverType == null) {
-
+ state = STATE_UNKNOWN;
-
+ return null;
-
+ }
-
+ state = STATE_GOT_RECEIVER;
-
+ }
-
+ if (state == STATE_GOT_RECEIVER) {
-
+ ExpressionGoal typedGoal = (ExpressionGoal) goal;
-
+ CallExpression expression = (CallExpression) typedGoal.getExpression();
-
+ List arguments = expression.getArgs().getExpressions();
-
+ this.arguments = new IEvaluatedType[arguments.size()];
-
+ }
-
+ if (state >= STATE_WAITING_ARGUMENT_0) {
-
+ arguments[state - STATE_WAITING_ARGUMENT_0] = previousResult;
-
+ }
-
+ if (state == STATE_GOT_RECEIVER || state >= STATE_WAITING_ARGUMENT_0) {
-
+ int nextArg = (state == STATE_GOT_RECEIVER ? 0 : state - STATE_WAITING_ARGUMENT_0 + 1);
-
+ ExpressionGoal typedGoal = (ExpressionGoal) goal;
-
+ CallExpression expression = (CallExpression) typedGoal.getExpression();
-
+ List arguments = expression.getArgs().getExpressions();
-
+ if (nextArg < arguments.size()) {
-
+ state = STATE_WAITING_ARGUMENT_0 + nextArg;
-
+ return new ExpressionGoal(goal.getContext(), (Statement) arguments.get(nextArg));
-
+ } else {
-
+ state = STATE_ARGS_DONE;
-
+ }
-
+ }
-
+ if (state == STATE_ARGS_DONE) {
-
+ ExpressionGoal typedGoal = (ExpressionGoal) goal;
-
+ CallExpression expression = (CallExpression) typedGoal.getExpression();
-
+ state = STATE_WAITING_METHOD;
-
+ return new MethodReturnTypeGoal(new InstanceContext((BasicContext) goal.getContext(),
-
+ receiverType), expression.getName(), arguments);
-
+ }
-
+ if (state == STATE_WAITING_METHOD) {
-
+ result = previousResult;
-
+ state = STATE_DONE;
-
+ }
-
return null;
-
}
-
-
public IEvaluatedType produceType() {
-
- return null;
-
+ if (state == STATE_UNKNOWN)
-
+ return null;
-
+ else
-
+ return result;
-
}
-
-
}
-
PermaLink to this entry https://pastebin.co.uk/10887
Posted by Andrey Tarantsov Sat 24th Feb 2007 19:56 - Syntax is Diff - 55 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0