[svn]
r6607: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel:
ExprFinder.n Project.Ty...
IT
svnadmin at nemerle.org
Sun Sep 3 06:01:04 CEST 2006
Log:
ExprFinder improvement.
Author: IT
Date: Sun Sep 3 06:01:01 2006
New Revision: 6607
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n Sun Sep 3 06:01:01 2006
@@ -18,13 +18,14 @@
mutable _curLocation : Location;
mutable _retObject : object;
mutable _retLocation : Location;
- mutable _locationToFind : Location;
+ mutable _pexprLocation : Location;
+ mutable _findLocation : bool;
#region Find PExpr
DoSyntaxElement(syntaxElement : SyntaxElement) : void
{
- when (_stop || !IsIn(_curLocation))
+ when (_stop || syntaxElement == null || !IsIn(_curLocation))
return;
match (syntaxElement)
@@ -54,9 +55,38 @@
}
}
+ DoSplicable(element : Splicable) : void
+ {
+ when (_stop || element == null || !IsIn(_curLocation))
+ return;
+
+ match (element)
+ {
+ | Expression(e) => Go(e);
+ | Name (name)
+ | HalfId(name) => CheckObject(element.Location, name);
+ }
+ }
+
+ DoFunctionDecl(func : Function_decl) : void
+ {
+ when (_stop || func == null || !IsIn(_curLocation))
+ return;
+
+ if (IsIn(func.header.Location))
+ {
+ foreach (p in func.header.parms)
+ Go(p.ty);
+
+ Go(func.header.ret_type);
+ }
+ else
+ Go(func.body);
+ }
+
Go(expression : PExpr) : void
{
- when (_stop || !IsIn(_curLocation))
+ when (_stop || expression == null || !IsIn(_curLocation))
return;
Print(expression);
@@ -64,6 +94,7 @@
match (expression)
{
+ | EmptyArray (lst) // { sizes : list [PExpr]; }
| Tuple (lst) // { args : list [PExpr]; }
| ListLiteral(lst) // { elements : list [PExpr]; }
| Sequence (lst) => // { body : list [PExpr]; }
@@ -75,91 +106,111 @@
CheckLocated(expression);
elems.Iter(DoSyntaxElement);
- | Call(func, parms) => // { func : PExpr; parms : list [PExpr]; }
+ | GenericSpecifier(e, l) // { func : PExpr; generic_parms : list [PExpr]; }
+ | Indexer (e, l) // { obj : PExpr; args : list [PExpr]; }
+ | Call (e, l) => // { func : PExpr; parms : list [PExpr]; }
- parms.Iter(Go);
- Go(func);
+ Go(e);
+ l.Iter(Go);
| Ref (obj : object) // { name : Name; }
| Literal(obj : object) => // { val : Nemerle.Compiler.Literal; }
CheckObject(expression.Location, obj);
+ | Array (e1, e2) // { rank : PExpr; args : PExpr; }
| TypeConversion (e1, e2) // { expr : PExpr; ty : PExpr; } // (expr :> ty)
| TypeEnforcement(e1, e2) // { expr : PExpr; ty : PExpr; } // (expr : ty)
| Assign (e1, e2) // { target : PExpr; source : PExpr; }
- | Define (e2, e1) => // { pattern : PExpr; val : PExpr; }
+ | Define (e1, e2) // { pattern : PExpr; val : PExpr; }
+ | TryFinally (e1, e2) // { body : PExpr; handler : PExpr; }
+ | Is (e1, e2) // { pat : PExpr; ty : PExpr; }
+ | Where (e1, e2) // { name : PExpr; fields : PExpr; }
+ | DefMutable (e1, e2) => // { name : PExpr; val : PExpr; }
- Go(e2);
Go(e1);
+ Go(e2);
+ | This
+ | Base
+ | Void // `void' used only in types
| Error => // placeholder of missing tree (where some errors occured)
();
- | Member(obj, member) => // { obj : PExpr; member : Splicable; }
-
- Go(obj);
+ | As (e, sp) // { pat : PExpr; name : Splicable; }
+ | Member(e, sp) => // { obj : PExpr; member : Splicable; }
- unless (_stop)
- match (member)
- {
- | Expression(e) => Go(e);
- | Name (name)
- | HalfId(name) => CheckObject(member.Location, name);
- }
+ Go(e);
+ DoSplicable(sp);
- | Typeof(ty) => // { ty : PExpr; }
+ | Spliced (e) // { body : PExpr; }
+ | Ellipsis (e) // { body : PExpr; }
+ | ParmByRef(e) // { parm : PExpr; }
+ | ParmOut (e) // { parm : PExpr; }
+ | Throw (e) // { exn : PExpr; }
+ | Typeof (e) => // { ty : PExpr; }
- Go(ty);
+ Go(e);
| Wildcard => // `_' used mainly in patterns, but also in `_ = ignored'
CheckLocated(expression)
- | Indexer(obj, args) => // { obj : PExpr; args : list [PExpr]; }
+ | DefFunctions(funs) => // { funs : list [Function_decl]; }
- Go(obj);
- args.Iter(Go);
+ funs.Iter(DoFunctionDecl);
- | DefFunctions(funs) => // { funs : list [Function_decl]; }
+ | Lambda(decl) => // { decl : Function_decl; }
- foreach (f when !_stop in funs)
- {
- if (IsIn(f.header.Location))
+ DoFunctionDecl(decl);
+
+ | Match(e, l) => // { expr : PExpr; cases : list [MatchCase]; }
+
+ Go(e);
+ foreach (mc in l)
{
- foreach (p in f.header.parms)
- Go(p.ty);
- Go(f.header.ret_type);
+ mc.patterns.Iter(Go);
+ Go(mc.body);
}
- else
- Go(f.body);
+
+ | Quoted(se) => // { body : SyntaxElement; }
+
+ DoSyntaxElement(se);
+
+ | Try(body, cases) => // { body : PExpr; cases : list [TryCase]; }
+
+ Go(body);
+
+ foreach (c when !_stop in cases)
+ match (c)
+ {
+ | Catch(exn, exn_ty, handler) => //{ exn : Splicable; exn_ty : PExpr; handler : PExpr; }
+
+ DoSplicable(exn);
+ Go(exn_ty);
+ Go(handler);
+
+ | Filter(exn, exn_ty, filter, handler) => // { exn : Splicable; exn_ty : PExpr; filter : PExpr; handler : PExpr; }
+
+ DoSplicable(exn);
+ Go(exn_ty);
+ Go(filter);
+ Go(handler);
+
+ | Ellipsis(body) => // { body : PExpr; }
+
+ Go(body);
+
}
- | Void // `void' used only in types
- | As // { pat : PExpr; name : Splicable; }
- | Is // { pat : PExpr; ty : PExpr; }
- | Where // { name : PExpr; fields : PExpr; }
- | Match // { expr : PExpr; cases : list [MatchCase]; }
- | GenericSpecifier // { func : PExpr; generic_parms : list [PExpr]; }
- | DefMutable // { name : PExpr; val : PExpr; }
- | Lambda // { decl : Function_decl; }
- | Throw // { exn : PExpr; }
- | Try // { body : PExpr; cases : list [TryCase]; }
- | TryFinally // { body : PExpr; handler : PExpr; }
- | This
- | Base
- | Array // { rank : PExpr; args : PExpr; }
- | EmptyArray // { sizes : list [PExpr]; }
- | ParmByRef // { parm : PExpr; }
- | ParmOut // { parm : PExpr; }
- | Quoted // { body : SyntaxElement; }
- | Spliced // { body : PExpr; }
- | ToComplete // { body : Name; }
- | Ellipsis // { body : PExpr; }
+ | ToComplete(o : object) // { body : Name; }
+ | TypedType (o : object) => // { body : TyVar; }
+
+ CheckObject(expression.Location, o);
+
| Typed // { body : Typedtree.TExpr; }
| TypedPattern // { body : Typedtree.Pattern; }
- | TypedType // { body : TyVar; }
| _ =>
PrintUnknown(expression);
@@ -188,7 +239,7 @@
DoPattern(pattern : Pattern) : void
{
- when (_stop || !IsIn(_curLocation))
+ when (_stop || pattern == null || !IsIn(_curLocation))
return;
Print(pattern);
@@ -216,8 +267,9 @@
| As(pat, decl) => // { pat : Pattern; decl : LocalValue; }
- CheckLocated(decl);
- DoPattern(pat);
+ Check(
+ pat. Location, fun() { DoPattern (pat) },
+ decl.Location, fun() { CheckLocated(decl) });
| HasType as ht => // { typ : MType; }
@@ -247,17 +299,17 @@
Go(expression : TExpr) : void
{
- when (_stop || !IsIn(_curLocation))
+ when (_stop || expression == null || !IsIn(_curLocation))
return;
Print(expression);
_counter++;
- when (_locationToFind.IsEqualExcludingFile(expression.Location))
+ when (_findLocation && _pexprLocation.IsEqualExcludingFile(expression.Location))
{
_stop = true;
_retObject = expression;
- _retLocation = _locationToFind;
+ _retLocation = _pexprLocation;
return;
}
@@ -347,10 +399,13 @@
Go(body);
walkTry_case(cases);
- | DefValIn(name, val, body) => // { name : LocalValue; val : TExpr; mutable body : TExpr; }
+ | DefValIn(nm, val, body) => // { name : LocalValue; val : TExpr; mutable body : TExpr; }
- Go(val);
- CheckLocated(name);
+ _ = expression.ToString();
+
+ Check(
+ nm. Location, fun() { CheckLocated(nm) },
+ val.Location, fun() { Go(val) });
unless (body == null)
Go(body);
@@ -387,7 +442,6 @@
Go(obj);
- //// invalid after T2
| Delayed(susp) => // { susp : Typer.DelayedTyping; }
unless (susp.IsResolved)
@@ -396,7 +450,6 @@
when (susp.IsResolved)
Go(susp.ResolutionResult);
- //// invalid after T3
| DefFunctionsIn as dfun => // { funs : list [Fun_header]; mutable body : TExpr; }
foreach (f in dfun.funs)
@@ -497,12 +550,14 @@
root : TExpr,
line : int,
col : int,
- locationToFind : Location)
+ pexprLocation : Location,
+ findLocation : bool)
: (Location * object)
{
Init(root.Location, line, col);
- _locationToFind = locationToFind;
+ _pexprLocation = pexprLocation;
+ _findLocation = findLocation;
Go(root);
@@ -561,6 +616,30 @@
CheckObject(obj.Location, obj);
}
+ Check(l1 : Location, f1 : void -> void, l2 : Location, f2 : void -> void) : void
+ {
+ if (IsIn(l1) && IsIn(l2))
+ {
+ def loc = l1.Intersect(l2);
+
+ if (loc == l1)
+ {
+ f1();
+ f2();
+ }
+ else
+ {
+ f2();
+ f1();
+ }
+ }
+ else
+ {
+ f1();
+ f2();
+ }
+ }
+
PrintUnknown[T](ex : T) : void
{
#if PRINT_AST
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n Sun Sep 3 06:01:01 2006
@@ -95,14 +95,10 @@
{
mutable bodyCode = getText(location.Line, location.Column, location.EndLine, location.EndColumn);
- // This prevents inlining during the typifying.
- //
- //bodyCode += "\n;*/; EERRRROORR";
-
def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, location);
mutable ret = null;
- mutable locationToFind;
+ mutable findLocation = false;
mutable pExpr;
mutable pLocation;
mutable pObj;
@@ -115,7 +111,7 @@
{
| PExpr.MacroCall as mc =>
- locationToFind = pLocation;
+ findLocation = true;
pExpr = mc;
| _ => ()
@@ -124,11 +120,11 @@
when (ret == null && tBody != null)
{
- def (eLocation, obj) = ExprFinder().Find(tBody.expr, line, col, locationToFind);
+ def (eLocation, obj) = ExprFinder().Find(tBody.expr, line, col, pLocation, findLocation);
def loc = if (pLocation.Contains(line, col)) pLocation else eLocation;
- if (locationToFind != Location.Default)
+ if (findLocation)
{
match (pExpr)
{
More information about the svn
mailing list