[svn] r7431: nemerle/trunk/ncc/parsing/ParseTree.n
nemerle/trunk/ncc/typing/LocalValue.n nemerle/trunk/ncc...
IT
svnadmin at nemerle.org
Thu Feb 15 05:36:54 CET 2007
Log:
Working on ExprFinder.
Author: IT
Date: Thu Feb 15 05:36:48 2007
New Revision: 7431
Modified:
nemerle/trunk/ncc/parsing/ParseTree.n
nemerle/trunk/ncc/typing/LocalValue.n
nemerle/trunk/ncc/typing/Typer-PatternTyper.n
nemerle/trunk/ncc/typing/Typer.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
Modified: nemerle/trunk/ncc/parsing/ParseTree.n
==============================================================================
--- nemerle/trunk/ncc/parsing/ParseTree.n (original)
+++ nemerle/trunk/ncc/parsing/ParseTree.n Thu Feb 15 05:36:48 2007
@@ -416,8 +416,7 @@
| TypedPattern { body : Typedtree.Pattern; }
| TypedType { body : TyVar; }
- [Accessor (flags = WantSetter)]
- mutable typed_object : Typedtree.TExpr;
+ [Accessor] internal mutable typed_object : object;
public override ToString () : string {
PrettyPrint.SprintExpr (None (), this);
@@ -431,8 +430,7 @@
| Expression { expr : PExpr; }
| HalfId { prefix : Parsetree.Name; }
- [Accessor (flags = WantSetter)]
- mutable typed_object : IMember;
+ [Accessor] internal mutable typed_object : IMember;
public GetName () : Parsetree.Name {
match (this) {
@@ -475,8 +473,7 @@
// it generates a dummy name and puts the pattern in this field
internal mutable pattern_hack : PExpr;
- [Accessor (flags = WantSetter)]
- mutable typed_object : Typedtree.Fun_parm;
+ [Accessor] internal mutable typed_object : Typedtree.Fun_parm;
public this (name : Splicable, ty : PExpr, modifiers : Modifiers)
{
@@ -536,8 +533,7 @@
public ret_type : PExpr;
public parms : list [Fun_parm];
- [Accessor (flags = WantSetter)]
- mutable typed_object : Typedtree.Fun_header;
+ [Accessor] internal mutable typed_object : Typedtree.Fun_header;
public ParsedName : Name {
get { name.GetName () }
Modified: nemerle/trunk/ncc/typing/LocalValue.n
==============================================================================
--- nemerle/trunk/ncc/typing/LocalValue.n (original)
+++ nemerle/trunk/ncc/typing/LocalValue.n Thu Feb 15 05:36:48 2007
@@ -45,7 +45,7 @@
[Accessor] is_mutable : bool;
[Accessor] defined_in : Fun_header;
- [Accessor] mutable name_location : Location;
+ [Accessor] internal mutable name_location : Location;
[Accessor] mutable used_in : Set [Fun_header];
[Accessor (flags = WantSetter)] mutable in_closure : bool;
Modified: nemerle/trunk/ncc/typing/Typer-PatternTyper.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-PatternTyper.n (original)
+++ nemerle/trunk/ncc/typing/Typer-PatternTyper.n Thu Feb 15 05:36:48 2007
@@ -388,7 +388,7 @@
name : PT.PExpr, pattern : PT.PExpr,
is_where : bool) : Pattern
{
- match (Util.QidOfExpr (name)) {
+ def pat = match (Util.QidOfExpr (name)) {
| Some (([id], name)) when !is_where && (System.Char.IsLower (id [0]) || id [0] == '_') =>
match (pattern) {
| PT.PExpr.Wildcard =>
@@ -552,6 +552,10 @@
ReportError (messenger, "expected qualified identifier in pattern");
Pattern.Error ()
}
+
+ when (name.typed_object == null)
+ name.typed_object = pat;
+ pat;
}
@@ -560,7 +564,7 @@
when (Manager.IsCompletioInProgress)
Manager.CompletePattern (pattern, matched_value_type, this, typer.env);
- match (pattern) {
+ def pat = match (pattern) {
| PT.PExpr.TypeEnforcement (_, PT.PExpr.ToComplete (_))
| PT.PExpr.TypeEnforcement (_, PT.PExpr.Member (_, Parsetree.Splicable.HalfId (_)))
| PT.PExpr.Is (_, PT.PExpr.ToComplete (_))
@@ -571,7 +575,7 @@
| PT.PExpr.ListLiteral (l) =>
TypePattern (matched_value_type, Macros.Lift (l))
- | PT.PExpr.As (pat, PT.Splicable.Name (name)) =>
+ | PT.PExpr.As (pat, PT.Splicable.Name (name) as sname) =>
def typed_pattern = TypePattern (matched_value_type, pat);
def fixed_type =
match (typed_pattern) {
@@ -587,6 +591,7 @@
}
def decl = DefinePatternVariable (name, fixed_type);
+ decl.name_location = sname.Location;
Pattern.As (typed_pattern, decl)
@@ -776,6 +781,10 @@
ReportError (messenger, "invalid pattern");
Pattern.Error ()
}
+
+ when (pattern.typed_object == null)
+ pattern.typed_object = pat;
+ pat;
}
}
}
Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n (original)
+++ nemerle/trunk/ncc/typing/Typer.n Thu Feb 15 05:36:48 2007
@@ -1103,7 +1103,8 @@
e'
});
- e.TypedObject = texpr;
+ when (e.typed_object == null)
+ e.typed_object = texpr;
texpr;
}
@@ -1216,9 +1217,11 @@
else
TExpr.Error ()
- | DefMutable (TypeEnforcement (nm, ty), val) =>
- DoType (PT.PExpr.DefMutable (nm, PT.PExpr.TypeEnforcement (ty.Location.Combine(val.Location), val, ty)),
- expected, is_toplevel_in_seq)
+ | DefMutable (TypeEnforcement (nm, ty) as te, val) =>
+ def nte = PT.PExpr.TypeEnforcement (ty.Location.Combine(val.Location), val, ty);
+ def exp = DoType (PT.PExpr.DefMutable (nm, nte), expected, is_toplevel_in_seq);
+ te.typed_object = nte.typed_object;
+ exp;
| DefMutable => Message.FatalError ($"incorrect mutable variables definition: $expression")
@@ -1731,7 +1734,8 @@
Util.ice ("The completion tokens allowed only if Manager.IsCompletioInProgress is true.")
}
- expression.TypedObject = texpr;
+ when (expression.typed_object == null)
+ expression.typed_object = texpr;
texpr
}
@@ -1822,7 +1826,7 @@
kind = ParmKind.Normal,
modifiers = p.modifiers);
fp.GetLocalDefaultValueFromModifiers (this);
- p.TypedObject = fp;
+ p.typed_object = fp;
fp
});
def name_obj = fn.header.name.GetName ();
@@ -1835,7 +1839,7 @@
tenv = tenv,
loc = fn.header.loc);
- fn.header.TypedObject = header;
+ fn.header.typed_object = header;
def parm_types = List.Map (parms, fun (p : Fun_parm) { p.ty });
def fun_type = ConstructFunctionType (parm_types, header.ret_type);
@@ -2399,7 +2403,7 @@
| Some (lst) =>
def (expr, mem) = MakeOverloadedNode (lst, expected);
- name.TypedObject = mem;
+ name.typed_object = mem;
expr;
| None =>
Delay (DelayedTyping.Kind.MemberAccess (obj, mem_name), expected)
@@ -3014,7 +3018,7 @@
dt.SetCallExpr (expr);
dt.Resolve (); // just try
when (dt.IsResolved)
- pfnc.TypedObject = dt.ResolutionResult;
+ pfnc.typed_object = dt.ResolutionResult;
expr
// special cases when call has been folded to something else
@@ -3042,8 +3046,8 @@
| _ => ()
}
- when (pfnc.TypedObject == null)
- pfnc.TypedObject = res;
+ when (pfnc.typed_object == null)
+ pfnc.typed_object = res;
res
}
#endregion
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 Thu Feb 15 05:36:48 2007
@@ -16,9 +16,18 @@
{
mutable _line : int;
mutable _col : int;
+ mutable _parentObject : object;
mutable _pexprObject : object;
mutable _texprObject : object;
- mutable _pexprLocation : Location;
+ mutable _location : Location;
+
+ GetTypedObject(obj : object) : object
+ {
+ | pe is PExpr => pe.TypedObject;
+ | fh is P.Fun_header => fh.TypedObject;
+ | sp is Splicable => sp.TypedObject : object;
+ | _ => null;
+ }
PFinder(info : ExprWalkInfo) : void
{
@@ -30,21 +39,16 @@
if (IsIn(loc))
{
- def texpr = match (obj)
- {
- | pe is PExpr => pe.TypedObject;
- | fh is P.Fun_header => fh.TypedObject;
- | sp is Splicable => sp.TypedObject : object;
- | _ => null;
- }
+ def texpr = GetTypedObject(obj);
when (texpr != null)
{
- when (_pexprObject == null || _pexprLocation.Contains(loc))
+ when (_pexprObject == null || _location.Contains(loc))
{
PrintAdd(info.Nodes.Length);
- _pexprLocation = loc;
+ _parentObject = _pexprObject;
+ _location = loc;
_pexprObject = info.Node;
_texprObject = texpr;
}
@@ -85,6 +89,30 @@
if (_texprObject != null)
{
+ def setloc(obj : object, loc) { _location = loc; obj; }
+ def setobj(obj) { _location = obj.Location; obj; }
+
+ _pexprObject = match (_pexprObject)
+ {
+ | PExpr.Member(_, Splicable.Name as name) when IsIn(name.Location) => setobj(name);
+ | PExpr.TypeEnforcement(Ref as r, _) when IsIn(r.Location) && _parentObject is PExpr.DefMutable =>
+
+ _texprObject = (_parentObject :> PExpr).TypedObject;
+ r;
+
+ | o => o;
+ }
+
+ _texprObject = match (_texprObject)
+ {
+ | TExpr.DefValIn (name, _, _) when IsInEx(name.NameLocation) => setloc(name, name.NameLocation);
+ | TExpr.TypeConversion(_, ty, _, tloc) when IsInEx(tloc) => setloc(ty, tloc);
+ | Pattern.As (_, decl) when IsInEx(decl.NameLocation) => decl;
+ | TExpr.LocalRef (val) => val;
+ | TExpr.StaticRef (_, mem, _) => mem : object;
+ | o => o;
+ }
+
#if PRINT_AST && DEBUG
Trace.WriteLine("");
Trace.WriteLine($"PExpr: $(_pexprObject.GetType())");
@@ -104,15 +132,7 @@
});
#endif
- (
- _pexprLocation,
- _pexprObject,
- match (_texprObject)
- {
- | TExpr.StaticRef(_, mem, _) => mem;
- | o => o;
- }
- )
+ (_location, _pexprObject, _texprObject)
}
else
(Location.Default, null, null)
@@ -129,8 +149,8 @@
_line = line;
_col = col;
+ _location = Location.Default;
_pexprObject = null;
- _pexprLocation = Location.Default;
_texprObject = null;
}
@@ -139,6 +159,11 @@
!location.IsGenerated && location.Contains(_line, _col);
}
+ IsInEx(location : Location) : bool
+ {
+ location.Contains(_line, _col);
+ }
+
Print(obj : object, loc : Location, level : int) : void
{
_ = obj.ToString();
@@ -158,7 +183,8 @@
Trace.WriteLine(s +
$"$(obj.GetType().FullName) "
"$(loc.Line):$(loc.Column):$(loc.EndLine):$(loc.EndColumn)"
- "$(if (loc.IsGenerated) '-' else '+') "
+ "$(if (loc.IsGenerated) '-' else '+')"
+ "$(if (GetTypedObject(obj) == null) '-' else '+') "
"$_line:$_col.");
Trace.WriteLine(s + os.Replace("\n", "\n" + s));
#endif
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n Thu Feb 15 05:36:48 2007
@@ -87,8 +87,8 @@
{
Go(header.typarms);
Go(header.name);
- Go(header.ret_type);
Go(header.parms);
+ Go(header.ret_type);
_info.Pop();
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n Thu Feb 15 05:36:48 2007
@@ -4,14 +4,29 @@
{
public class Class1
{
+ ParamTest(arr : array[int]) : void
+ {
+ def foo( ppp /*012:-2*/) {}
+
+ foo(1);
+
+ mutable iii/*010:-1*/ : int/*009:-1*/;
+ _ = arr/*008:-1*/[0];
+ }
+
MacroTest() : void
{
+ foreach (ch/*011:-1*/ in "123")
+ {
+ }
+
if/*003:-1*/ ("".Length/*004:-1*/ == 0) {}
else {}
}
WriteLineTest() : void
{
+ System.Console.WriteLine/*006:-1*/("");
WriteLine/*002:-1*/("");
}
@@ -20,6 +35,7 @@
def bar/*005:-1*/()
{
_ = ReadLine/*001:-1*/();
+ def _iii/*007:-1*/ = ReadLine();
}
bar();
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n Thu Feb 15 05:36:48 2007
@@ -20,20 +20,36 @@
{
def file = FileQuickTip2;
- def test(testNumber, expected)
+ def test(testNumber, len, expected)
{
def (line, col) = ReadLocation(file, testNumber);
def result = _project.GetQuickTipInfo(file, line, col);
Assert.IsNotNull(result, "result is null");
- Assert.IsTrue (result.Text.Split('\n')[0].IndexOf(expected) > 0);
- }
- test("005", "bar");
- test("004", "Length");
- test("003", "Nemerle.Core.if");
- test("002", "WriteLine");
- test("001", "ReadLine");
+ def line0 = result.Text.Split('\n')[0];
+
+ if (expected[0] == '-')
+ Assert.IsTrue(line0.IndexOf(expected.Substring(1)) < 0);
+ else
+ Assert.IsTrue(line0.IndexOf(expected) >= 0);
+
+ when (len > 0)
+ Assert.AreEqual(len, result.ColEnd - result.ColStart);
+ }
+
+ test("012", 3, "ppp");
+ test("011", 2, "ch");
+ test("010", 3, "iii");
+ test("009", 3, "Int32");
+ test("008", 3, "arr");
+ test("007", 0, "_iii");
+ test("006", 9, "WriteLine");
+ test("005", 0, "bar");
+ test("004", 0, "Length");
+ test("003", 0, "Nemerle.Core.if");
+ test("002", 0, "WriteLine");
+ test("001", 0, "ReadLine");
}
[Test]
More information about the svn
mailing list