[svn] r6646: vs-plugin/trunk/Nemerle.Compiler.Utils:
Nemerle.Completion2/CodeModel/ExprFinder.n Nemerle.Co...
IT
svnadmin at nemerle.org
Wed Sep 13 06:24:37 CEST 2006
Log:
1. Refactoring.
2. FindExpr convertion bug.
Author: IT
Date: Wed Sep 13 06:24:33 2006
New Revision: 6646
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.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 Wed Sep 13 06:24:33 2006
@@ -371,9 +371,13 @@
expression.Location, fun() { CheckObject(expression.Location, mem) },
obj.Location, fun() { Go(obj) });
+ | TypeConversion(e, t, _) => // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
+
+ Go(e);
+ CheckObject(expression.Location, t);
+
| 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);
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 Wed Sep 13 06:24:33 2006
@@ -71,24 +71,17 @@
}
}
- private GetTypeQuickTip(
+ private FindObject(
typeDecl : Decl.Type,
fileIndex : int,
line : int,
col : int,
getText : GetText
)
- : QuickTipInfo
+ : Location * object
{
def typeBuilder = typeDecl.Builder;
- def members = typeBuilder.GetActiveMembers(fileIndex, line, col);
-
- def member = match (members)
- {
- | [m] => m
- | [] => null
- | m :: tail => tail.FindWithDefault(m, (f) => f is PropertyBuilder);
- }
+ def member = typeBuilder.GetActiveMember(fileIndex, line, col, (f) => f is PropertyBuilder);
match (member)
{
@@ -102,53 +95,33 @@
def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, loc);
- mutable ret = null;
- mutable findLocation = false;
- mutable pExpr;
- mutable pLoc;
- mutable pObj;
-
- when (pBody != null)
+ def (pLoc, pExpr, findLocation) = if (pBody != null)
{
- (pLoc, pObj) = ExprFinder().Find(pBody.expr, line, col);
+ def (pLoc, pObj) = ExprFinder().Find(pBody.expr, line, col);
match (pObj)
{
- | PExpr.MacroCall as mc =>
-
- findLocation = true;
- pExpr = mc;
-
- | _ => ()
+ | PExpr.MacroCall as mc => (pLoc, mc, true)
+ | _ => (pLoc, null, false)
}
}
+ else
+ (Location(), null, false);
- when (ret == null && tBody != null)
+ if (tBody != null)
{
def (eLoc, obj) = ExprFinder().Find(tBody.expr, line, col, pLoc, findLocation);
def loc = if (pLoc.Contains(line, col)) pLoc.Intersect(eLoc) else eLoc;
- if (findLocation)
- {
match (pExpr)
{
- | PExpr.MacroCall as mc => ret = QuickTipInfo(loc, mc, obj :> TExpr)
- | _ => ()
- }
+ | PExpr.MacroCall as mc when findLocation => (loc, (mc, obj :> TExpr))
+ | _ => (loc, obj)
}
- else match (obj)
- {
- | lv is LocalValue => ret = QuickTipInfo(loc, lv);
- | mm is IMember => ret = QuickTipInfo(loc, mm);
- | tv is TyVar => ret = QuickTipInfo(loc, tv);
- | fh is Typedtree.Fun_header => ret = QuickTipInfo(loc, fh);
- | _ => ()
}
- }
-
- ret
-
+ else
+ (Location(), null)
}
else
{
@@ -164,120 +137,63 @@
//array(0); // completion outside body (try conplete types)
}
*/
- null
+ (Location(), null)
}
- | fb is FieldBuilder => QuickTipInfo(fb.Location, fb)
- | pb is PropertyBuilder => QuickTipInfo(pb.Location, pb)
- | null => null
+ | fb is FieldBuilder => (fb.Location, fb)
+ | pb is PropertyBuilder => (pb.Location, pb)
+ | null => (Location(), null)
| _ =>
Trace.Assert(false, $"Unknown member type '$member'.");
throw System.Exception($"Unknown member type '$member'.");
}
}
- private GetTypeGoto(
+ private GetTypeQuickTip(
typeDecl : Decl.Type,
fileIndex : int,
line : int,
col : int,
getText : GetText
)
- : GotoInfo
- {
- def typeBuilder = typeDecl.Builder;
- def members = typeBuilder.GetActiveMembers(fileIndex, line, col);
-
- def member = match (members)
- {
- | [m] => m
- | [] => null
- | m :: tail => tail.FindWithDefault(m, (f) => f is PropertyBuilder);
- }
-
- match (member)
- {
- | method is MethodBuilder =>
-
- def location = method.BodyLocation;
-
- if (location.Contains(line, col)) // in method body
+ : QuickTipInfo
{
- def bodyCode = getText(location.Line, location.Column, location.EndLine, location.EndColumn);
-
- def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, location);
+ def (loc, obj) = FindObject(typeDecl, fileIndex, line, col, getText);
- mutable ret = null;
- mutable findLocation = false;
- mutable pExpr;
- mutable pLocation;
- mutable pObj;
-
- when (pBody != null)
+ match (obj)
{
- (pLocation, pObj) = ExprFinder().Find(pBody.expr, line, col);
-
- match (pObj)
- {
- | PExpr.MacroCall as mc =>
-
- findLocation = true;
- pExpr = mc;
-
- | _ => ()
+ | mc is (PExpr.MacroCall * TExpr) => (QuickTipInfo(loc, mc[0], mc[1]))
+ | lv is LocalValue => (QuickTipInfo(loc, lv))
+ | mm is IMember => (QuickTipInfo(loc, mm))
+ | tv is TyVar => (QuickTipInfo(loc, tv))
+ | fh is Typedtree.Fun_header => (QuickTipInfo(loc, fh))
+ | fb is FieldBuilder => (QuickTipInfo(fb.Location, fb))
+ | pb is PropertyBuilder => (QuickTipInfo(pb.Location, pb))
+ | _ => (null)
}
}
- when (ret == null && tBody != null)
- {
- def (eLocation, obj) = ExprFinder().Find(tBody.expr, line, col, pLocation, findLocation);
-
- def _loc = if (pLocation.Contains(line, col)) pLocation else eLocation;
-
- if (findLocation)
- {
- match (pExpr)
- {
- | PExpr.MacroCall as mc => ret = GotoInfo(mc, obj :> TExpr)
- | _ => ()
- }
- }
- else match (obj)
+ private GetTypeGoto(
+ typeDecl : Decl.Type,
+ fileIndex : int,
+ line : int,
+ col : int,
+ getText : GetText
+ )
+ : GotoInfo
{
- | lv is LocalValue => ret = GotoInfo(lv);
- | mm is IMember => ret = GotoInfo(mm);
- | tv is TyVar => ret = GotoInfo(tv);
- | fh is Typedtree.Fun_header => ret = GotoInfo(fh);
- | _ => ()
- }
- }
-
- ret
+ def (_, obj) = FindObject(typeDecl, fileIndex, line, col, getText);
- }
- else
- {
- /*
- // Completin in AutoModule
- if (member.DeclaringType.FullName == _autoModule)
+ match (obj)
{
- //_topKeywords;
- }
- else
- {
- //Trace.WriteLine($"# Completion outside body");
- //array(0); // completion outside body (try conplete types)
- }
- */
- null
- }
-
- | fb is FieldBuilder => GotoInfo(fb)
- | pb is PropertyBuilder => GotoInfo(pb)
- | null => null
- | _ =>
- Trace.Assert(false, $"Unknown member type '$member'.");
- throw System.Exception($"Unknown member type '$member'.");
+ | mc is (PExpr.MacroCall * TExpr) => (GotoInfo(mc[0], mc[1]))
+ | lv is LocalValue => (GotoInfo(lv))
+ | mm is IMember => (GotoInfo(mm))
+ | tv is TyVar => (GotoInfo(tv))
+ | fh is Typedtree.Fun_header => (GotoInfo(fh))
+ | fb is FieldBuilder => (GotoInfo(fb))
+ | pb is PropertyBuilder => (GotoInfo(pb))
+ | _ => (null)
}
}
@@ -290,37 +206,11 @@
)
: list[MethodTipInfo]
{
- def typeBuilder = typeDecl.Builder;
- def member = typeBuilder.GetActiveMember(fileIndex, line, col);
-
- match (member)
- {
- | method is MethodBuilder =>
- def loc = method.BodyLocation;
+ def (_, obj) = FindObject(typeDecl, fileIndex, line, col, getText);
- if (loc.Contains(line, col)) // completion in method body
- {
- def bodyCode = getText(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
- def completionCode = getText(loc.Line, loc.Column, line, col);
- def result = _engine.RunCompletionEngine(method, bodyCode, completionCode.Length);
+ _ = obj;
- if (result == null)
- {
- Trace.WriteLine("### RunCompletionEngine() return null!");
- [];
- }
- else
- {
- Trace.WriteLine($"# RunCompletionEngine() return $(result.ObjectType)");
- _ = MakeCompletionList(result);
- null
- }
- }
- else
- null
- | null => []
- | _ => throw System.Exception($"Unknown member type '$member'.");
+ ([])
}
}
- } // end class Project
-} // end namespace
+}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n Wed Sep 13 06:24:33 2006
@@ -197,11 +197,31 @@
loop(members);
}
+ public GetActiveMember(
+ this typeBuilder : TypeBuilder,
+ fileIndex : int,
+ line : int,
+ col : int,
+ predicate : IMember -> bool
+ )
+ : IMember
+ {
+ def members = typeBuilder.GetActiveMembers(fileIndex, line, col);
+
+ match (members)
+ {
+ | [m] => (m)
+ | [] => (null)
+ | m :: tail => (tail.FindWithDefault(m, predicate))
+ }
+ }
+
public GetActiveMembers(
this typeBuilder : TypeBuilder,
fileIndex : int,
line : int,
- col : int)
+ col : int
+ )
: list[IMember]
{
def loop(members : list[IMember])
More information about the svn
mailing list