[svn] r6603: vs-plugin/trunk/Nemerle.Compiler.Utils:
Nemerle.Compiler.Utils.csproj Nemerle.Completion2/Cod...
IT
svnadmin at nemerle.org
Sun Sep 3 01:17:56 CEST 2006
Log:
Moved Find Location logic into separate class ExprFinder.
Author: IT
Date: Sun Sep 3 01:17:51 2006
New Revision: 6603
Added:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj Sun Sep 3 01:17:51 2006
@@ -103,6 +103,9 @@
<ItemGroup>
<Compile Include="Nemerle.Completion2\Engine\Engine.CompilerMessages.n" />
</ItemGroup>
+ <ItemGroup>
+ <Compile Include="Nemerle.Completion2\CodeModel\ExprFinder.n" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n Sun Sep 3 01:17:51 2006
@@ -0,0 +1,593 @@
+using System;
+using System.Diagnostics;
+
+using Nemerle.Compiler;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Compiler.Typedtree;
+using Nemerle.Compiler.Utils;
+using Nemerle.Imperative;
+
+namespace Nemerle.Completion2
+{
+ class ExprFinder
+ {
+ mutable _line : int;
+ mutable _col : int;
+ mutable _stop : bool;
+ mutable _counter : int;
+ mutable _curLocation : Location;
+ mutable _retObject : object;
+ mutable _retLocation : Location;
+ mutable _locationToFind : Location;
+
+ #region Find PExpr
+
+ DoSyntaxElement(syntaxElement : SyntaxElement) : void
+ {
+ when (_stop || !IsIn(_curLocation))
+ return;
+
+ match (syntaxElement)
+ {
+ | Expression(expr) // { body : PExpr; }
+ | TType (expr) => // { body : PExpr; }
+
+ Go(expr)
+
+ | MatchCase(mc) => // { body : Parsetree.MatchCase; }
+
+ mc.patterns.Iter(Go);
+ Go(mc.body);
+
+ | Function // { body : Function_decl; }
+ | Parameter // { body : Fun_parm; }
+ | RawToken // { body : Token; }
+ | ClassMember // { body : Parsetree.ClassMember; }
+ | TypeBuilder // { body : Compiler.TypeBuilder; }
+ | FieldBuilder // { body : Compiler.FieldBuilder; }
+ | MethodBuilder // { body : Compiler.MethodBuilder; }
+ | PropertyBuilder // { body : Compiler.PropertyBuilder; }
+ | EventBuilder // { body : Compiler.EventBuilder; }
+ | ParameterBuilder => // { body : Typedtree.Fun_parm; }
+
+ PrintUnknown(syntaxElement);
+ }
+ }
+
+ Go(expression : PExpr) : void
+ {
+ when (_stop || !IsIn(_curLocation))
+ return;
+
+ Print(expression);
+ _counter++;
+
+ match (expression)
+ {
+ | Tuple (lst) // { args : list [PExpr]; }
+ | ListLiteral(lst) // { elements : list [PExpr]; }
+ | Sequence (lst) => // { body : list [PExpr]; }
+
+ lst.Iter(Go);
+
+ | MacroCall(_, _, elems) => // { name : Name; ns : NamespaceTree.Node; parms : list [SyntaxElement]; }
+
+ CheckLocated(expression);
+ elems.Iter(DoSyntaxElement);
+
+ | Call(func, parms) => // { func : PExpr; parms : list [PExpr]; }
+
+ parms.Iter(Go);
+ Go(func);
+
+ | Ref (obj : object) // { name : Name; }
+ | Literal(obj : object) => // { val : Nemerle.Compiler.Literal; }
+
+ CheckObject(expression.Location, obj);
+
+ | 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; }
+
+ Go(e2);
+ Go(e1);
+
+ | Error => // placeholder of missing tree (where some errors occured)
+
+ ();
+
+ | Member(obj, member) => // { obj : PExpr; member : Splicable; }
+
+ Go(obj);
+
+ unless (_stop)
+ match (member)
+ {
+ | Expression(e) => Go(e);
+ | Name (name)
+ | HalfId(name) => CheckObject(member.Location, name);
+ }
+
+ | Typeof(ty) => // { ty : PExpr; }
+
+ Go(ty);
+
+ | Wildcard => // `_' used mainly in patterns, but also in `_ = ignored'
+
+ CheckLocated(expression)
+
+ | Indexer(obj, args) => // { obj : PExpr; args : list [PExpr]; }
+
+ Go(obj);
+ args.Iter(Go);
+
+ | DefFunctions(funs) => // { funs : list [Function_decl]; }
+
+ foreach (f when !_stop in funs)
+ {
+ if (IsIn(f.header.Location))
+ {
+ foreach (p in f.header.parms)
+ Go(p.ty);
+ Go(f.header.ret_type);
+ }
+ else
+ Go(f.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; }
+ | Typed // { body : Typedtree.TExpr; }
+ | TypedPattern // { body : Typedtree.Pattern; }
+ | TypedType // { body : TyVar; }
+ | _ =>
+
+ PrintUnknown(expression);
+
+ }
+
+ _counter--;
+ }
+
+ public Find(
+ root : PExpr,
+ line : int,
+ col : int)
+ : (Location * object)
+ {
+ Init(root.Location, line, col);
+
+ Go(root);
+
+ (_retLocation, _retObject)
+ }
+
+ #endregion
+
+ #region Find TExpr
+
+ DoPattern(pattern : Pattern) : void
+ {
+ when (_stop || !IsIn(_curLocation))
+ return;
+
+ Print(pattern);
+ _counter++;
+
+ match (pattern)
+ {
+ | Wildcard =>
+
+ ()
+
+ | Error =>
+
+ _stop = _stop || IsIn(pattern.Location);
+
+ | Application as app => // { name : TypeInfo; arg : Pattern; }
+
+ DoPattern(app.arg);
+ CheckObject(pattern.Location, app.name);
+
+ | Record(args) => // { args : list [IMember * Pattern]; }
+
+ foreach ((_member, pattern) in args)
+ DoPattern(pattern);
+
+ | As(pat, decl) => // { pat : Pattern; decl : LocalValue; }
+
+ CheckLocated(decl);
+ DoPattern(pat);
+
+ | HasType as ht => // { typ : MType; }
+
+ CheckObject(pattern.Location, ht.typ);
+
+ | Literal(Literal.Enum(_, ty)) => // { lit : Nemerle.Compiler.Literal; }
+
+ CheckObject(pattern.Location, ty);
+
+ | Literal => // { val : Nemerle.Compiler.Literal; }
+
+ when (!typeof(void).Equals(pattern.SystemType))
+ CheckLocated(pattern);
+
+ | Tuple(args) => // { args : list [Pattern]; }
+
+ args.Iter(DoPattern);
+
+ | Enum => // { fld : IField; val : Nemerle.Compiler.Literal; }
+
+ Print(pattern);
+
+ }
+
+ _counter--;
+ }
+
+ Go(expression : TExpr) : void
+ {
+ when (_stop || !IsIn(_curLocation))
+ return;
+
+ Print(expression);
+ _counter++;
+
+ when (_locationToFind.IsEqualExcludingFile(expression.Location))
+ {
+ _stop = true;
+ _retObject = expression;
+ _retLocation = _locationToFind;
+
+ return;
+ }
+
+ match (expression)
+ {
+ | StaticRef (_, mem : IMember, _) // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
+ | ConstantObjectRef(_, mem : IMember) // { from : MType.Class; mem : IField; }
+ | StaticPropertyRef(_, mem : IMember) // { from : MType.Class; prop : IProperty; }
+ | StaticEventRef (_, mem : IMember) // { from : MType.Class; ev : IEvent; }
+ | Base (mem : IMember) => // { base_ctor : IMethod; }
+
+ CheckObject(expression.Location, mem);
+
+ | LocalFunRef(lv, _) // { decl : LocalValue; type_parms : list [TyVar]; }
+ | LocalRef (lv) => // { decl : LocalValue; }
+
+ CheckObject(expression.Location, lv)
+
+ | Literal(Literal.Enum(_, ty)) =>
+
+ CheckObject(expression.Location, ty);
+
+ | Literal => // { val : Nemerle.Compiler.Literal; }
+
+ when (!typeof(void).Equals(expression.SystemType))
+ CheckLocated(expression);
+
+ | Error
+ | ImplicitValueTypeCtor
+ | DefaultValue
+ | Goto // { target : int; mutable try_block : int; }
+ | This
+ | OpCode => // { name : string; }
+
+ _stop = _stop || IsIn(expression.Location);
+
+ | MethodRef (obj, mem : IMember, _, _) // { obj : TExpr; meth : IMethod; type_parms : list [TyVar]; notvirtual : bool; }
+ | EventMember (obj, mem : IMember) // { obj : TExpr; ev : IEvent; }
+ | FieldMember (obj, mem : IMember) // { obj : TExpr; fld : IField; }
+ | PropertyMember(obj, mem : IMember) => // { obj : TExpr; prop : IProperty; }
+
+ def isThis = obj is TExpr.This;
+
+ unless (isThis)
+ Go(obj);
+
+ when (!_stop && IsIn(expression.Location))
+ CheckObject(expression.Location, mem);
+
+ when (isThis)
+ Go(obj);
+
+ | Block (_, e) // { jump_out : LocalValue; body : TExpr; }
+ | Throw (e) // { exn : TExpr; }
+ | TypeConversion(e, _, _) // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
+ | Label (_, e) => // { id : int; body : TExpr; }
+
+ Go(e);
+
+ | Call as call => // { mutable func : TExpr; mutable parms : list [Parm]; mutable is_tail : bool; }
+
+ foreach (parm in call.parms)
+ Go(parm.expr);
+
+ Go(call.func);
+
+ | Try(body, cases) => // { body : TExpr; mutable cases : list [Try_case]; }
+
+ def walkTry_case(cases)
+ {
+ | Try_case.Fault(handler) :: tail // { handler : TExpr; }
+ | Catch(_, handler) :: tail => // { exn : LocalValue; handler : TExpr; }
+
+ Go(handler);
+ walkTry_case(tail)
+
+ | Filter(_, filter, handler) :: tail => // { exn : LocalValue; filter : TExpr; handler : TExpr; }
+
+ Go(filter);
+ Go(handler);
+ walkTry_case(tail)
+
+ | [] => ()
+ }
+
+ Go(body);
+ walkTry_case(cases);
+
+ | DefValIn(name, val, body) => // { name : LocalValue; val : TExpr; mutable body : TExpr; }
+
+ Go(val);
+ CheckLocated(name);
+
+ unless (body == null)
+ Go(body);
+
+ | Sequence(TExpr.Call(TExpr.Base as b, _, _), e2) as seq =>
+
+ when (seq.Location != b.Location)
+ Go(b);
+
+ Go(e2);
+
+ | Assign (e1, e2) // { target : TExpr; source : TExpr; }
+ | TryFinally(e1, e2) // { body : TExpr; handler : TExpr; }
+ | Sequence (e1, e2) => // { mutable e1 : TExpr; mutable e2 : TExpr; }
+
+ Go(e1);
+ Go(e2);
+
+ | Tuple(args) => // { args : list [TExpr]; }
+
+ args.Iter(Go);
+
+ | Array(args, dim) => // { args : list [TExpr]; dimensions : list [TExpr]; }
+
+ args.Iter(Go);
+ dim. Iter(Go);
+
+ | ArrayIndexer(obj, args) => // { obj : TExpr; args : list [TExpr]; }
+
+ Go(obj);
+ args.Iter(Go);
+
+ | TupleIndexer(obj, _, _) => // { obj : TExpr; pos : int; len : int; } // 0-based
+
+ Go(obj);
+
+ //// invalid after T2
+ | Delayed(susp) => // { susp : Typer.DelayedTyping; }
+
+ unless (susp.IsResolved)
+ susp.Resolve();
+
+ when (susp.IsResolved)
+ Go(susp.ResolutionResult);
+
+ //// invalid after T3
+ | DefFunctionsIn as dfun => // { funs : list [Fun_header]; mutable body : TExpr; }
+
+ foreach (f in dfun.funs)
+ {
+ if (IsIn(f.Location))
+ {
+ foreach (p in f.parms)
+ CheckObject(p.Location, p.decl);
+
+ CheckLocated(f);
+ }
+ else
+ {
+ match (f.body)
+ {
+ | Typed(expr) => Go(expr);
+ | _ => ();
+ }
+ }
+
+ when (_stop)
+ break;
+ }
+
+ unless (_stop)
+ Go(dfun.body);
+
+ | Match as m => // { expr : TExpr; cases : list [Match_case]; }
+
+ Go(m.expr);
+
+ unless (_stop) foreach (c in m.cases)
+ {
+ foreach ((pattern, pexpr, assigns) in c.patterns)
+ {
+ DoPattern(pattern);
+
+ unless (_stop)
+ {
+ unless (pexpr is TExpr.Literal)
+ Go(pexpr);
+
+ foreach ((_localValue, aexpr) in assigns)
+ Go(aexpr);
+ }
+
+ when (_stop)
+ break;
+ }
+
+ Go(c.body);
+
+ when (_stop)
+ break;
+ }
+
+ | If as eif => // { cond : TExpr; e_then : TExpr; e_else : TExpr; }
+
+ Go(eif.cond);
+ Go(eif.e_then);
+ Go(eif.e_else);
+
+ | Switch as e_switch => // { indexing_expr : TExpr; default : option [TExpr]; cases : list [int * TExpr]; }
+
+ Go(e_switch.indexing_expr);
+
+ match (e_switch.default)
+ {
+ | Some(expr) => Go(expr)
+ | _ => ()
+ }
+
+ foreach ((_, expr) in e_switch.cases)
+ Go(expr);
+
+ | HasType as ht => // { expr : TExpr; test_ty : MType; }
+
+ Go(ht.expr);
+ CheckObject(ht.Location, ht.test_ty);
+
+ | TypeOf as to => // { target_type : TyVar; }
+
+ CheckObject(to.Location, to.target_type);
+
+ | SelfTailCall // { parms : list [Parm]; }
+ | MethodAddress // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
+ | MultipleAssign // { assigns : list [LocalValue * TExpr]; }
+ | _ =>
+
+ PrintUnknown(expression);
+
+ }
+
+ _counter--;
+ }
+
+ public Find(
+ root : TExpr,
+ line : int,
+ col : int,
+ locationToFind : Location)
+ : (Location * object)
+ {
+ Init(root.Location, line, col);
+
+ _locationToFind = locationToFind;
+
+ Go(root);
+
+ (_retLocation, _retObject)
+ }
+
+ #endregion
+
+ #region Helpers
+
+ Init(rootLocation : Location, line : int, col : int) : void
+ {
+#if PRINT_AST
+ Trace.WriteLine($"\nStart at: $line:$col.");
+#endif
+
+ _curLocation = Location(
+ rootLocation.FileIndex,
+ rootLocation.Line,
+ rootLocation.Column,
+ line + 100,
+ 1);
+
+ _line = line;
+ _col = col;
+ _counter = 0;
+ _stop = false;
+ _retObject = null;
+ _retLocation = Location();
+ }
+
+ IsIn(location : Location) : bool
+ {
+ location.Contains(_line, _col);
+ }
+
+ CheckObject(location : Location, obj : object) : void
+ {
+ unless (_stop)
+ {
+ if (IsIn(location))
+ {
+ _stop = true;
+ _retObject = obj;
+ _retLocation = _curLocation.Intersect(location);
+ }
+ else
+ {
+ _curLocation = _curLocation.Trim(location, _line, _col);
+ }
+ }
+ }
+
+ CheckLocated(obj : Located) : void
+ {
+ CheckObject(obj.Location, obj);
+ }
+
+ PrintUnknown[T](ex : T) : void
+ {
+#if PRINT_AST
+ Trace.WriteLine($"Unknown expression $(ex.GetType().FullName) : $ex.");
+#endif
+ }
+
+ Print(ex : Located) : void
+ {
+#if PRINT_AST
+ mutable s = "";
+
+ for (mutable i = 0; i < _counter; i++)
+ s += " ";
+
+ Trace.WriteLine(s + $"$(ex.GetType().FullName) $(ex.loc.Line):$(ex.loc.Column):"
+ "$(ex.loc.EndLine):$(ex.loc.EndColumn) "
+ "cur:$(_curLocation.Line):$(_curLocation.Column):"
+ "$(_curLocation.EndLine):$(_curLocation.EndColumn) "
+ "$_line:$_col.");
+ Trace.WriteLine(s + ex.ToString().Replace("\n", "\n" + s));
+ Trace.WriteLine("");
+#endif
+
+ ignore(ex);
+ }
+
+ #endregion
+ }
+}
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 01:17:51 2006
@@ -97,23 +97,25 @@
// This prevents inlining during the typifying.
//
- bodyCode += "\n;*/; EERRRROORR";
+ //bodyCode += "\n;*/; EERRRROORR";
def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, location);
mutable ret = null;
mutable locationToFind;
mutable pExpr;
+ mutable pLocation;
+ mutable pObj;
when (pBody != null)
{
- def (loc, obj) = FindLocatedExpr(pBody.expr, line, col);
+ (pLocation, pObj) = ExprFinder().Find(pBody.expr, line, col);
- match (obj)
+ match (pObj)
{
| PExpr.MacroCall as mc =>
- locationToFind = loc;
+ locationToFind = pLocation;
pExpr = mc;
| _ => ()
@@ -122,7 +124,9 @@
when (ret == null && tBody != null)
{
- def (loc, obj) = FindLocatedExpr(tBody.expr, line, col, locationToFind);
+ def (eLocation, obj) = ExprFinder().Find(tBody.expr, line, col, locationToFind);
+
+ def loc = if (pLocation.Contains(line, col)) pLocation else eLocation;
if (locationToFind != Location.Default)
{
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n Sun Sep 3 01:17:51 2006
@@ -126,601 +126,5 @@
| _ => null
}
}
-
- private FindLocatedExpr(
- root : PExpr,
- line : int,
- col : int)
- : (Location * object)
- {
-#if PRINT_AST
- Trace.WriteLine($"\nStart looking at: $line:$col.");
-#endif
-
- def Print[T](ex : T) : void
- {
- Trace.WriteLine($"Unknown expression $(ex.GetType().FullName) : $ex.");
- }
-
- def IsIn(location)
- {
- location.Contains(line, col);
- }
-
- mutable counter = 0;
- mutable curLocation = root.Location;
- mutable stop = false;
- mutable retObject;
- mutable retLocation;
-
- def Print2(ex)
- {
-#if PRINT_AST
- mutable s = "";
-
- for (mutable i = 0; i < counter; i++)
- s += " ";
-
- Trace.WriteLine(s + $"$(ex.GetType().FullName) $(ex.loc.Line):$(ex.loc.Column):"
- "$(ex.loc.EndLine):$(ex.loc.EndColumn) "
- "cur:$(curLocation.Line):$(curLocation.Column):"
- "$(curLocation.EndLine):$(curLocation.EndColumn) "
- "$line:$col.");
- Trace.WriteLine(s + ex.ToString().Replace("\n", "\n" + s));
- Trace.WriteLine("");
-#endif
-
- ignore(ex);
- }
-
- def Go(expression : PExpr)
- {
- def not_impl() { Print(expression) }
-
- def checkObject(location : Location, obj : object)
- {
- unless (stop)
- {
- if (IsIn(location))
- {
- stop = true;
- retObject = obj;
- retLocation = curLocation.Intersect(location);
- }
- else
- {
- curLocation = curLocation.Trim(location, line, col);
- }
- }
- }
-
- def checkLocated(obj : Located)
- {
- checkObject(obj.Location, obj);
- }
-
- def DoSyntaxElement(syntaxElement : SyntaxElement)
- {
- when (stop || !IsIn(curLocation))
- return;
-
- match (syntaxElement)
- {
- | Expression(expr) // { body : PExpr; }
- | TType (expr) => // { body : PExpr; }
-
- Go(expr)
-
- | MatchCase(mc) => // { body : Parsetree.MatchCase; }
-
- mc.patterns.Iter(Go);
- Go(mc.body);
-
- | Function // { body : Function_decl; }
- | Parameter // { body : Fun_parm; }
- | RawToken // { body : Token; }
- | ClassMember // { body : Parsetree.ClassMember; }
- | TypeBuilder // { body : Compiler.TypeBuilder; }
- | FieldBuilder // { body : Compiler.FieldBuilder; }
- | MethodBuilder // { body : Compiler.MethodBuilder; }
- | PropertyBuilder // { body : Compiler.PropertyBuilder; }
- | EventBuilder // { body : Compiler.EventBuilder; }
- | ParameterBuilder => // { body : Typedtree.Fun_parm; }
-
- Print(syntaxElement);
-
- }
- }
-
- when (stop || !IsIn(curLocation))
- return;
-
- Print2(expression);
- counter++;
-
- match (expression)
- {
- | Tuple (lst) // { args : list [PExpr]; }
- | ListLiteral(lst) // { elements : list [PExpr]; }
- | Sequence (lst) => // { body : list [PExpr]; }
-
- lst.Iter(Go);
-
- | MacroCall(_, _, elems) => // { name : Name; ns : NamespaceTree.Node; parms : list [SyntaxElement]; }
-
- checkLocated(expression);
- elems.Iter(DoSyntaxElement);
-
- | Call(func, parms) => // { func : PExpr; parms : list [PExpr]; }
-
- parms.Iter(Go);
- Go(func);
-
- | Ref (obj : object) // { name : Name; }
- | Literal(obj : object) => // { val : Nemerle.Compiler.Literal; }
-
- checkObject(expression.Location, obj);
-
- | 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; }
-
- Go(e2);
- Go(e1);
-
- | Error => // placeholder of missing tree (where some errors occured)
-
- ();
-
- | Typeof(obj) // { ty : PExpr; }
- | Member(obj, _mem) => // { obj : PExpr; member : Splicable; }
-
- Go(obj);
- //checkObject(expression.Location, mem);
-
- | Wildcard => // `_' used mainly in patterns, but also in `_ = ignored'
-
- checkLocated(expression)
-
- | Indexer(obj, args) => // { obj : PExpr; args : list [PExpr]; }
-
- Go(obj);
- args.Iter(Go);
-
- | DefFunctions(funs) => // { funs : list [Function_decl]; }
-
- foreach (f when !stop in funs)
- {
- if (IsIn(f.header.Location))
- {
- foreach (p in f.header.parms)
- Go(p.ty);
- Go(f.header.ret_type);
- }
- else
- Go(f.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; }
- | Typed // { body : Typedtree.TExpr; }
- | TypedPattern // { body : Typedtree.Pattern; }
- | TypedType // { body : TyVar; }
- | _ =>
-
- not_impl();
-
- }
-
- counter--;
- }
-
- Go(root);
-
- (retLocation, retObject)
- }
-
- private FindLocatedExpr(
- root : TExpr,
- line : int,
- col : int,
- locationToFind : Location)
- : (Location * object)
- {
-#if PRINT_AST
- Trace.WriteLine($"\nStart looking at: $line:$col, $locationToFind.");
-#endif
-
- def Print[T](ex : T) : void
- {
- Trace.WriteLine($"Unknown expression $(ex.GetType().FullName) : $ex.");
- }
-
- def IsIn(location)
- {
- location.Contains(line, col);
- }
-
- mutable counter = 0;
- mutable curLocation = root.Location;
- mutable stop = false;
- mutable retObject;
- mutable retLocation;
-
- def Print2(ex : Located)
- {
-#if PRINT_AST
- mutable s = "";
-
- for (mutable i = 0; i < counter; i++)
- s += " ";
-
- Trace.WriteLine(s + $"$(ex.GetType().FullName) $(ex.loc.Line):$(ex.loc.Column):"
- "$(ex.loc.EndLine):$(ex.loc.EndColumn) "
- "cur:$(curLocation.Line):$(curLocation.Column):"
- "$(curLocation.EndLine):$(curLocation.EndColumn) "
- "$line:$col.");
- Trace.WriteLine(s + ex.ToString().Replace("\n", "\n" + s));
- Trace.WriteLine("");
-#endif
-
- ignore(ex);
- }
-
- def Go(expression : TExpr)
- {
- def not_impl() { Print(expression) }
-
- def checkObject(location : Location, obj : object)
- {
- unless (stop)
- {
- if (IsIn(location))
- {
- stop = true;
- retObject = obj;
- retLocation = curLocation.Intersect(location);
- }
- else
- {
- curLocation = curLocation.Trim(location, line, col);
- }
- }
- }
-
- def checkLocated(obj : Located)
- {
- checkObject(obj.Location, obj);
- }
-
- def DoPattern(pattern : Pattern)
- {
- when (stop || !IsIn(curLocation))
- return;
-
- Print2(pattern);
- counter++;
-
- match (pattern)
- {
- | Wildcard =>
-
- ()
-
- | Error =>
-
- stop = stop || IsIn(expression.Location);
-
- | Application as app => // { name : TypeInfo; arg : Pattern; }
-
- DoPattern(app.arg);
- checkObject(pattern.Location, app.name);
-
- | Record(args) => // { args : list [IMember * Pattern]; }
-
- foreach ((_member, pattern) in args)
- DoPattern(pattern);
-
- | As(pat, decl) => // { pat : Pattern; decl : LocalValue; }
-
- checkLocated(decl);
- DoPattern(pat);
-
- | HasType as ht => // { typ : MType; }
-
- checkObject(pattern.Location, ht.typ);
-
- | Literal(Literal.Enum(_, ty)) => // { lit : Nemerle.Compiler.Literal; }
-
- checkObject(pattern.Location, ty);
-
- | Literal => // { val : Nemerle.Compiler.Literal; }
-
- when (!typeof(void).Equals(pattern.SystemType))
- checkLocated(pattern);
-
- | Tuple(args) => // { args : list [Pattern]; }
-
- args.Iter(DoPattern);
-
- | Enum => // { fld : IField; val : Nemerle.Compiler.Literal; }
-
- Print(pattern);
-
- }
-
- counter--;
- }
-
- when (stop || !IsIn(curLocation))
- return;
-
- Print2(expression);
- counter++;
-
- when (locationToFind.IsEqualExcludingFile(expression.Location))
- {
- stop = true;
- retObject = expression;
- retLocation = locationToFind;
-
- return;
- }
-
- match (expression)
- {
- | StaticRef (_, mem : IMember, _) // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
- | ConstantObjectRef(_, mem : IMember) // { from : MType.Class; mem : IField; }
- | StaticPropertyRef(_, mem : IMember) // { from : MType.Class; prop : IProperty; }
- | StaticEventRef (_, mem : IMember) // { from : MType.Class; ev : IEvent; }
- | Base (mem : IMember) => // { base_ctor : IMethod; }
-
- checkObject(expression.Location, mem);
-
- | LocalFunRef(lv, _) // { decl : LocalValue; type_parms : list [TyVar]; }
- | LocalRef (lv) => // { decl : LocalValue; }
-
- checkObject(expression.Location, lv)
-
- | Literal(Literal.Enum(_, ty)) =>
-
- checkObject(expression.Location, ty);
-
- | Literal => // { val : Nemerle.Compiler.Literal; }
-
- when (!typeof(void).Equals(expression.SystemType))
- checkLocated(expression);
-
- | Error
- | ImplicitValueTypeCtor
- | DefaultValue
- | Goto // { target : int; mutable try_block : int; }
- | This
- | OpCode => // { name : string; }
-
- stop = stop || IsIn(expression.Location);
-
- | MethodRef (obj, mem : IMember, _, _) // { obj : TExpr; meth : IMethod; type_parms : list [TyVar]; notvirtual : bool; }
- | EventMember (obj, mem : IMember) // { obj : TExpr; ev : IEvent; }
- | FieldMember (obj, mem : IMember) // { obj : TExpr; fld : IField; }
- | PropertyMember(obj, mem : IMember) => // { obj : TExpr; prop : IProperty; }
-
- def isThis = obj is TExpr.This;
-
- unless (isThis)
- Go(obj);
-
- when (!stop && IsIn(expression.Location))
- checkObject(expression.Location, mem);
-
- when (isThis)
- Go(obj);
-
- | Block (_, e) // { jump_out : LocalValue; body : TExpr; }
- | Throw (e) // { exn : TExpr; }
- | TypeConversion(e, _, _) // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
- | Label (_, e) => // { id : int; body : TExpr; }
-
- Go(e);
-
- | Call as call => // { mutable func : TExpr; mutable parms : list [Parm]; mutable is_tail : bool; }
-
- foreach (parm in call.parms)
- Go(parm.expr);
-
- Go(call.func);
-
- | Try(body, cases) => // { body : TExpr; mutable cases : list [Try_case]; }
-
- def walkTry_case(cases)
- {
- | Try_case.Fault(handler) :: tail // { handler : TExpr; }
- | Catch(_, handler) :: tail => // { exn : LocalValue; handler : TExpr; }
-
- Go(handler);
- walkTry_case(tail)
-
- | Filter(_, filter, handler) :: tail => // { exn : LocalValue; filter : TExpr; handler : TExpr; }
-
- Go(filter);
- Go(handler);
- walkTry_case(tail)
-
- | [] => ()
- }
-
- Go(body);
- walkTry_case(cases);
-
- | DefValIn(name, val, body) => // { name : LocalValue; val : TExpr; mutable body : TExpr; }
-
- checkLocated(name);
- Go(val);
-
- unless (body == null)
- Go(body);
-
- | Sequence(TExpr.Call(TExpr.Base as b, _, _), e2) as seq =>
-
- when (seq.Location != b.Location)
- Go(b);
-
- Go(e2);
-
- | Assign (e1, e2) // { target : TExpr; source : TExpr; }
- | TryFinally(e1, e2) // { body : TExpr; handler : TExpr; }
- | Sequence (e1, e2) => // { mutable e1 : TExpr; mutable e2 : TExpr; }
-
- Go(e1);
- Go(e2);
-
- | Tuple(args) => // { args : list [TExpr]; }
-
- args.Iter(Go);
-
- | Array(args, dim) => // { args : list [TExpr]; dimensions : list [TExpr]; }
-
- args.Iter(Go);
- dim. Iter(Go);
-
- | ArrayIndexer(obj, args) => // { obj : TExpr; args : list [TExpr]; }
-
- Go(obj);
- args.Iter(Go);
-
- | TupleIndexer(obj, _, _) => // { obj : TExpr; pos : int; len : int; } // 0-based
-
- Go(obj);
-
- //// invalid after T2
- | Delayed(susp) => // { susp : Typer.DelayedTyping; }
-
- unless (susp.IsResolved)
- susp.Resolve();
-
- when (susp.IsResolved)
- Go(susp.ResolutionResult);
-
- //// invalid after T3
- | DefFunctionsIn as dfun => // { funs : list [Fun_header]; mutable body : TExpr; }
-
- foreach (f in dfun.funs)
- {
- if (IsIn(f.Location))
- {
- foreach (p in f.parms)
- checkObject(p.Location, p.decl);
-
- checkLocated(f);
- }
- else
- {
- match (f.body)
- {
- | Typed(expr) => Go(expr);
- | _ => ();
- }
- }
-
- when (stop)
- break;
- }
-
- unless (stop)
- Go(dfun.body);
-
- | Match as m => // { expr : TExpr; cases : list [Match_case]; }
-
- Go(m.expr);
-
- unless (stop) foreach (c in m.cases)
- {
- foreach ((pattern, pexpr, assigns) in c.patterns)
- {
- DoPattern(pattern);
-
- unless (stop)
- {
- unless (pexpr is TExpr.Literal)
- Go(pexpr);
-
- foreach ((_localValue, aexpr) in assigns)
- Go(aexpr);
- }
-
- when (stop)
- break;
- }
-
- Go(c.body);
-
- when (stop)
- break;
- }
-
- | If as eif => // { cond : TExpr; e_then : TExpr; e_else : TExpr; }
-
- Go(eif.cond);
- Go(eif.e_then);
- Go(eif.e_else);
-
- | Switch as e_switch => // { indexing_expr : TExpr; default : option [TExpr]; cases : list [int * TExpr]; }
-
- Go(e_switch.indexing_expr);
-
- match (e_switch.default)
- {
- | Some(expr) => Go(expr)
- | _ => ()
- }
-
- foreach ((_, expr) in e_switch.cases)
- Go(expr);
-
- | HasType as ht => // { expr : TExpr; test_ty : MType; }
-
- Go(ht.expr);
- checkObject(ht.Location, ht.test_ty);
-
- | TypeOf as to => // { target_type : TyVar; }
-
- checkObject(to.Location, to.target_type);
-
- | SelfTailCall // { parms : list [Parm]; }
- | MethodAddress // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
- | MultipleAssign // { assigns : list [LocalValue * TExpr]; }
- | _ =>
-
- not_impl();
-
- }
-
- counter--;
- }
-
- Go(root);
-
- (retLocation, retObject)
- }
} // end class Project
} // end namespace
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n Sun Sep 3 01:17:51 2006
@@ -1,17 +1,19 @@
using System;
using System.IO;
using System.Diagnostics;
+
using SCG = System.Collections.Generic;
+using SR = System.Reflection;
+
using Nemerle.Assertions;
using Nemerle.Collections;
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
using Nemerle.Imperative;
using Nemerle.Utility;
-
using Nemerle.Compiler.Utils;
+
using Typed = Nemerle.Compiler.Typedtree;
-using SR = System.Reflection;
namespace Nemerle.Completion2
{
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
More information about the svn
mailing list