[svn] r7730: nemerle/trunk/ncc/Makefile
nemerle/trunk/ncc/generation/ILEmitter.n
nemerle/trunk/ncc/generat...
IT
svnadmin at nemerle.org
Mon Jul 2 07:28:20 CEST 2007
Log:
1. Moved ExprWalker to the compiler.
2. Working on debugging.
Author: IT
Date: Mon Jul 2 07:28:11 2007
New Revision: 7730
Added:
nemerle/trunk/ncc/misc/ExprWalker.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprDeclWalker.n
Removed:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
Modified:
nemerle/trunk/ncc/Makefile
nemerle/trunk/ncc/generation/ILEmitter.n
nemerle/trunk/ncc/generation/Typer3.n
nemerle/trunk/ncc/generation/Typer4.n
nemerle/trunk/ncc/misc/PrettyPrint.n
nemerle/trunk/ncc/parsing/ParseTree.n
nemerle/trunk/ncc/parsing/Utility.n
nemerle/trunk/ncc/typing/TypedTree.n
nemerle/trunk/ncc/typing/Typer.n
nemerle/trunk/ncc/typing/Typer2.n
vs-plugin/trunk/Nemerle.Compiler.Utils/AstBrowserForm.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
Modified: nemerle/trunk/ncc/Makefile
==============================================================================
--- nemerle/trunk/ncc/Makefile (original)
+++ nemerle/trunk/ncc/Makefile Mon Jul 2 07:28:11 2007
@@ -102,6 +102,7 @@
hierarchy/TypesManager.n \
hierarchy/XmlDump.n \
misc/AssemblyInfo.n \
+ misc/ExprWalker.n \
misc/PrettyPrint.n \
misc/Stats.n \
misc/ComponentsFactory.n \
Modified: nemerle/trunk/ncc/generation/ILEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/ILEmitter.n (original)
+++ nemerle/trunk/ncc/generation/ILEmitter.n Mon Jul 2 07:28:11 2007
@@ -201,6 +201,7 @@
when (IsDebugEnabled && loc.Line != 0 && !debug_tmp_disabled && !prev_location.Contains(loc)) {
prev_location = loc;
Util.cassert (loc.Line <= loc.EndLine, "spoiled location " + loc.File + " " + loc.ToString ());
+//IT.TEMP
_ilg.MarkSequencePoint (_debug_doc, loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
}
}
@@ -1633,12 +1634,49 @@
}
limited_debug_nesting--;
+ | DebugInfo as di =>
+ emit_debug_info(di);
+
| _ =>
Message.Warning ($ "FIXME: unmatched: $expr");
});
log (EMIT, $"} emit");
}
+ private emit_debug_info(di : TExpr.DebugInfo) : void
+ {
+ if (_debug_doc == null)
+ {
+ emit(di.expr);
+ }
+ else
+ {
+ def emit_debug(line, col, eline, ecol, emit_nop)
+ {
+ _ilg.MarkSequencePoint (_debug_doc, line, col, eline, ecol);
+
+ when (emit_nop)
+ _ilg.Emit (OpCodes.Nop);
+ }
+
+ def l = di.loc;
+
+ match (di.pexpr)
+ {
+ | Sequence => emit_debug(l.Line, l.Column, l.Line, l.Column + 1, true);
+ | _ => emit_debug(l.Line, l.Column, l.EndLine, l.EndColumn, false);
+ }
+
+ emit(di.expr);
+
+ match (di.pexpr)
+ {
+ | Sequence => emit_debug(l.EndLine, l.EndColumn - 1, l.EndLine, l.EndColumn, false);
+ | _ => ()
+ }
+ }
+ }
+
private array_set_method (t : System.Type) : MethodInfo
{
def rank = t.GetArrayRank ();
Modified: nemerle/trunk/ncc/generation/Typer3.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer3.n (original)
+++ nemerle/trunk/ncc/generation/Typer3.n Mon Jul 2 07:28:11 2007
@@ -1033,6 +1033,7 @@
| TExpr.MacroEnvelope (_, _, e)
| TExpr.TypeConversion (e, _, _, _)
| TExpr.Label (_, e)
+ | TExpr.DebugInfo (e, _)
=> SimpleFlow (e)
| TExpr.Call (e, p, _)
@@ -1098,7 +1099,6 @@
| TExpr.Cache
| TExpr.CacheRef
| TExpr.Error
- | TExpr.DebugInfo
=> Util.ice ("invalid expression in Typer3")
}
}
@@ -1308,6 +1308,9 @@
)
)
+ | TExpr.DebugInfo (e, pe) =>
+ TExpr.DebugInfo (o.loc, null, inject(e), pe);
+
//invalid things
| TExpr.PropertyMember
| TExpr.StaticPropertyRef
@@ -1319,7 +1322,6 @@
| TExpr.Cache
| TExpr.CacheRef
| TExpr.Error
- | TExpr.DebugInfo
=> Util.ice ("invalid expression in Typer3")
}
}
@@ -2249,7 +2251,8 @@
| Goto
| DefaultValue
| If
- | Switch =>
+ | Switch
+ | DebugInfo =>
null
| Cache
@@ -2265,8 +2268,7 @@
| DefFunctionsIn
| Match
| SelfTailCall
- | Block
- | DebugInfo =>
+ | Block =>
Util.cassert (Message.SeenError);
null
}
Modified: nemerle/trunk/ncc/generation/Typer4.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer4.n (original)
+++ nemerle/trunk/ncc/generation/Typer4.n Mon Jul 2 07:28:11 2007
@@ -316,6 +316,9 @@
| None => all // ???
}
+ | DebugInfo (e, _) =>
+ Throws (e, allow_try, is_top)
+
| Cache
| CacheRef
| LocalFunRef
@@ -326,7 +329,6 @@
| ConstantObjectRef
| Delayed
| Error
- | DebugInfo
| DefFunctionsIn
| Match
| Block
Added: nemerle/trunk/ncc/misc/ExprWalker.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/misc/ExprWalker.n Mon Jul 2 07:28:11 2007
@@ -0,0 +1,704 @@
+using System;
+
+using Nemerle.Assertions;
+using Nemerle.Utility;
+
+using P = Nemerle.Compiler.Parsetree;
+using T = Nemerle.Compiler.Typedtree;
+
+namespace Nemerle.Compiler
+{
+ public interface IExprWalkerCallback
+ {
+ Push(info : ExprWalkInfo) : void;
+ Pop (info : ExprWalkInfo) : void;
+ Stop(info : ExprWalkInfo) : void;
+ Skip(info : ExprWalkInfo) : void;
+ }
+
+ public delegate ExprWalkHandler(info : ExprWalkInfo) : void;
+
+ public class ExprWalkInfo
+ {
+ mutable _isStopped : bool;
+ mutable _isSkipped : bool;
+ mutable _handler : ExprWalkHandler;
+ mutable _callback : IExprWalkerCallback;
+
+ [Accessor] mutable _node : object;
+
+ internal Init(handler : ExprWalkHandler, callback : IExprWalkerCallback) : void
+ {
+ _handler = handler;
+ _callback = callback;
+ _isStopped = false;
+ _isSkipped = false;
+ }
+
+ internal Push(node : object) : bool
+ {
+ _node = node;
+
+ if (_isStopped || _isSkipped || node == null || _handler == null)
+ {
+ false;
+ }
+ else
+ {
+ _handler(this);
+
+ if (!_isStopped && !_isSkipped)
+ {
+ when (_callback != null)
+ _callback.Push(this);
+ true
+ }
+ else
+ false
+ }
+ }
+
+ internal Pop() : void
+ {
+ unless (_isStopped)
+ when (_callback != null)
+ _callback.Pop(this);
+ }
+
+ private Walk(walk : ExprWalker -> void) : void
+ {
+ walk(ExprWalker(_callback));
+ Skip();
+ }
+
+ public Walk(node : P.PExpr) : void { Walk(w => w.Walk(node, _handler)) }
+ public Walk(node : T.TExpr) : void { Walk(w => w.Walk(node, _handler)) }
+ public Walk(node : T.Pattern) : void { Walk(w => w.Walk(node, _handler)) }
+
+ public Stop() : void
+ {
+ _isStopped = true;
+ when (_callback != null)
+ _callback.Stop(this);
+ }
+
+ public Skip() : void
+ {
+ _isSkipped = true;
+ when (_callback != null)
+ _callback.Skip(this);
+ }
+ }
+
+ public class ExprWalker
+ {
+ [Accessor] mutable _info : ExprWalkInfo = ExprWalkInfo();
+ [Accessor] mutable _callback : IExprWalkerCallback;
+
+ public this()
+ {
+ }
+
+ public this(callback : IExprWalkerCallback)
+ {
+ _callback = callback;
+ }
+
+ protected Push (node : object) : bool
+ {
+ _info.Push(node);
+ }
+
+ protected Pop () : void
+ {
+ _info.Pop();
+ }
+
+ protected Init(walkHandler : ExprWalkHandler) : void
+ {
+ _info.Init(walkHandler, _callback);
+ }
+
+ protected Go(lst : list[P.PExpr]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.ClassMember]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.Splicable]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.SyntaxElement]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.Function_decl]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.MatchCase]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.TryCase]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[P.Fun_parm]) : void { when (lst != null) foreach (item in lst) Go(item); }
+
+ protected Go(lst : list[T.TExpr]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[T.Parm]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[T.Try_case]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[T.Fun_parm]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[T.Fun_header]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[T.Pattern]) : void { when (lst != null) foreach (item in lst) Go(item); }
+ protected Go(lst : list[T.Match_case]) : void { when (lst != null) foreach (item in lst) Go(item); }
+
+ protected Go(lst : list[IMember]) : void { when (lst != null) foreach (item in lst) Go(item); }
+
+/*
+ protected Go(lst : list[Decl]) : void { when (lst != null) foreach (item in lst) Go(item); }
+
+ protected Go(decl : Decl) : void
+ {
+ when(_info.Push(decl))
+ {
+ match(decl)
+ {
+ | n is Decl.Namespace => Go(n.Decls);
+ | t is Decl.Type => Go(t.Builder);
+ | GlobalAttribute
+ | Using
+ | None
+ | _ => ()
+ }
+ _info.Pop();
+ }
+ }
+*/
+
+ protected Go(member : IMember) : void
+ {
+ when(_info.Push(member))
+ {
+ match(member)
+ {
+ | mb is MethodBuilder =>
+ Go(mb.Ast.name);
+ unless(mb.IsAbstract)
+ Go(mb.BodyParsed);
+
+ | fb is FieldBuilder =>
+ Go(fb.Ast.name);
+ when(fb.IsInitializerPresent)
+ Go(fb.InitializerParsed);
+
+ | tb is TypeBuilder =>
+ Go(tb.Ast.name);
+ Go(tb.GetDirectMembers().Reverse());
+
+ | pb is PropertyBuilder =>
+ unless(pb.IsAbstract)
+ {
+ Go(pb.GetGetter());
+ Go(pb.GetSetter());
+ }
+
+ | _ => ();
+ }
+ _info.Pop();
+ }
+ }
+
+ protected Go(body : FunBody) : void
+ {
+ when (_info.Push(body))
+ {
+ match (body)
+ {
+ | Parsed(e) => Go(e); // { expr : Parsetree.PExpr; }
+ | Typed (e) => Go(e); // { expr : Typedtree.TExpr; }
+ | ILed
+ | Abstract => ();
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(splicable : P.Splicable) : void
+ {
+ when (_info.Push(splicable))
+ {
+ match (splicable)
+ {
+ | Expression(e) => Go(e); // { expr : PExpr; }
+ | Name // { body : Parsetree.Name; }
+ | HalfId => (); // { prefix : Parsetree.Name; }
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(parms : P.Typarms) : void
+ {
+ when (_info.Push(parms))
+ {
+ Go(parms.tyvars);
+
+ foreach (c in parms.constraints)
+ {
+ Go(c.tyvar);
+ Go(c.ty);
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(header : P.Fun_header) : void
+ {
+ when (_info.Push(header))
+ {
+ Go(header.typarms);
+ Go(header.name);
+ Go(header.parms);
+ Go(header.ret_type);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(decl : P.Function_decl) : void
+ {
+ when (_info.Push(decl))
+ {
+ Go(decl.header);
+ Go(decl.body);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(parm : P.Fun_parm) : void
+ {
+ when (_info.Push(parm))
+ {
+ Go(parm.ty);
+ Go(parm.name);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(tryCase : P.TryCase) : void
+ {
+ when (_info.Push(tryCase))
+ {
+ match (tryCase)
+ {
+ | Catch (sp, e1, e2) => Go(sp); Go(e1); Go(e2); // { exn : Splicable; exn_ty : PExpr; handler : PExpr; }
+ | Filter(sp, e1, e2, e3) => Go(sp); Go(e1); Go(e2); Go(e3); // { exn : Splicable; exn_ty : PExpr; filter : PExpr; handler : PExpr; }
+ | Ellipsis(e) => Go(e); // { body : PExpr; }
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(matchCase : P.MatchCase) : void
+ {
+ when (_info.Push(matchCase))
+ {
+ Go(matchCase.patterns);
+ Go(matchCase.body);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(decl : P.TopDeclaration) : void
+ {
+ when (_info.Push(decl))
+ {
+ match (decl)
+ {
+ | Class (lst, m) // { mutable t_extends : list [PExpr]; decls : list [ClassMember]; }
+ | Interface(lst, m) // { mutable t_extends : list [PExpr]; methods : list [ClassMember]; }
+ | Variant (lst, m) // { mutable t_extends : list [PExpr]; mutable decls : list [ClassMember]; }
+ | Enum (lst, m) => Go(lst); Go(m); // { t_extends : list [PExpr]; decls : list[ClassMember]; }
+ | Alias (ty) => Go(ty); // { ty : PExpr; }
+ | VariantOption(decls) => Go(decls); // { decls : list [ClassMember]; }
+ | Macro (h, lst, e) => Go(h); Go(lst); Go(e); // { header : Fun_header; synt : list [PExpr]; expr : PExpr; }
+ | Delegate (h) => Go(h); // { header : Fun_header; }
+ }
+
+ Go(decl.name);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(member : P.ClassMember) : void
+ {
+ when (_info.Push(member))
+ {
+ match (member)
+ {
+ | TypeDeclaration(td) => Go(td); // { td : TopDeclaration; }
+ | Field (e) // { mutable ty : PExpr; }
+ | EnumOption(Some(e)) => Go(e); // { value : option [PExpr]; }
+ | Function (h, _, body) => Go(h); Go(body); // { header : Fun_header; kind : FunKind; mutable body : FunBody; }
+ | EnumOption => ()
+ | Property(ty, prop_ty, dims, get, set) => // { ty : PExpr; prop_ty : PExpr; dims : list [Fun_parm]; get : option [ClassMember]; set : option [ClassMember]; }
+
+ Go(ty);
+ Go(prop_ty);
+ Go(dims);
+ match (get) { | Some(m) => Go(m) | _ => () }
+ match (set) { | Some(m) => Go(m) | _ => () }
+
+ | Event(ty, field, add, remove) => // { ty : PExpr; field : ClassMember.Field; add : ClassMember.Function; remove : ClassMember.Function; }
+
+ Go(ty);
+ Go(field);
+ Go(add);
+ Go(remove);
+ }
+
+ Go(member.name);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(element : P.SyntaxElement) : void
+ {
+ when (_info.Push(element))
+ {
+ match (element)
+ {
+ | Expression (e) // { body : PExpr; }
+ | TType (e) => Go(e); // { body : PExpr; }
+ | MatchCase (mc) => Go(mc); // { body : Parsetree.MatchCase; }
+ | Function (body) => Go(body); // { body : Function_decl; }
+ | Parameter (body) => Go(body); // { body : Fun_parm; }
+ | ClassMember (body) => Go(body); // { body : Parsetree.ClassMember; }
+ | ParameterBuilder // { body : Typedtree.Fun_parm; }
+ | RawToken // { body : Token; }
+ | TypeBuilder // { body : Compiler.TypeBuilder; }
+ | FieldBuilder // { body : Compiler.FieldBuilder; }
+ | MethodBuilder // { body : Compiler.MethodBuilder; }
+ | PropertyBuilder // { body : Compiler.PropertyBuilder; }
+ | EventBuilder => (); // { body : Compiler.EventBuilder; }
+ }
+
+ _info.Pop();
+ }
+ }
+
+ private Sort[T] (lst : list[T]) : list[T] where T : Located
+ {
+ lst.Sort((i1, i2) =>
+ {
+ match (i1.Location.Line - i2.Location.Line)
+ {
+ | n when n < 0 => -1
+ | 0 => i1.Location.Column - i2.Location.Column
+ | _ => 1
+ }
+ });
+ }
+
+ protected Go(expression : P.PExpr) : void
+ {
+ when (_info.Push(expression))
+ {
+ match (expression)
+ {
+ | Wildcard
+ | Ref // { name : Name; }
+ | Literal // { val : Nemerle.Compiler.Literal; }
+ | This
+ | Base
+ | Error
+ | ToComplete // { body : Name; }
+ | TypedPattern // { body : Typedtree.Pattern; }
+ | TypedType // { body : TyVar; }
+ | Void => ()
+ | Typed (body) => Go(body); // { body : Typedtree.TExpr; }
+ | As (e, sp) // { pat : PExpr; name : Splicable; }
+ | Member (e, sp) => Go(e); Go(sp); // { obj : PExpr; member : Splicable; }
+ | Is (e1, e2) // { pat : PExpr; ty : PExpr; }
+ | Where (e1, e2) // { name : PExpr; fields : PExpr; }
+ | Assign (e1, e2) // { target : PExpr; source : PExpr; }
+ | DefMutable (e1, e2) // { name : PExpr; val : PExpr; }
+ | Define (e1, e2) // { pattern : PExpr; val : PExpr; }
+ | TryFinally (e1, e2) // { body : PExpr; handler : PExpr; }
+ | TypeConversion (e1, e2) // { expr : PExpr; ty : PExpr; } // (expr :> ty)
+ | TypeEnforcement (e1, e2) // { expr : PExpr; ty : PExpr; } // (expr : ty)
+ | Array (e1, e2) => Go(e1); Go(e2); // { rank : PExpr; args : PExpr; }
+ | Throw (e) // { exn : PExpr; }
+ | Typeof (e) // { ty : PExpr; }
+ | ParmByRef (e) // { parm : PExpr; }
+ | ParmOut (e) // { parm : PExpr; }
+ | Spliced (e) // { body : PExpr; }
+ | Ellipsis (e) => Go(e); // { body : PExpr; }
+ | Match (e, cs) => Go(e); Go(cs); // { expr : PExpr; cases : list [MatchCase]; }
+ | Call (e, lst) // { func : PExpr; parms : list [PExpr]; }
+ | GenericSpecifier(e, lst) // { func : PExpr; generic_parms : list [PExpr]; }
+ | Indexer (e, lst) => // { obj : PExpr; args : list [PExpr]; }
+
+ match (lst)
+ {
+ | [] => Go(e);
+ | _ => Go(Sort(e :: lst));
+ }
+
+ | ListLiteral (lst) // { elements : list [PExpr]; }
+ | Sequence (lst) // { body : list [PExpr]; }
+ | Tuple (lst) // { args : list [PExpr]; }
+ | EmptyArray (lst) => Go(lst); // { sizes : list [PExpr]; }
+ | DefFunctions (funs) => Go(funs); // { funs : list [Function_decl]; }
+ | Lambda (decl) => Go(decl); // { decl : Function_decl; }
+ | Try (b, cs) => Go(b); Go(cs); // { body : PExpr; cases : list [TryCase]; }
+ | Quoted (el) => Go(el); // { body : SyntaxElement; }
+ | MacroCall (_, _, parms) => // { name : Name; ns : NamespaceTree.Node; parms : list [SyntaxElement]; }
+
+ Go(parms.Sort((p1, p2) =>
+ {
+ match (p1.Location.Line - p2.Location.Line)
+ {
+ | p when p < 0 => -1
+ | 0 => p1.Location.Column - p2.Location.Column
+ | _ => 1
+ }
+ }));
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(parm : T.Parm) : void
+ {
+ when (_info.Push(parm))
+ {
+ Go(parm.expr);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(tryCase : T.Try_case) : void
+ {
+ when (_info.Push(tryCase))
+ {
+ match (tryCase)
+ {
+ | Fault (e) // { handler : TExpr; }
+ | Catch (_, e) => Go(e); // { exn : LocalValue; handler : TExpr; }
+ | Filter(_, e1, e2) => Go(e1); Go(e2); // { exn : LocalValue; filter : TExpr; handler : TExpr; }
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(parm : T.Fun_parm) : void
+ {
+ when (_info.Push(parm))
+ {
+ match (parm.default_value) { | Some(e) => Go(e) | _ => () }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(header : T.Fun_header) : void
+ {
+ when (_info.Push(header))
+ {
+ Go(header.parms);
+ Go(header.body);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(case : T.Match_case) : void
+ {
+ when (_info.Push(case))
+ {
+ foreach ((pat, expr, lst) in case.patterns)
+ {
+ Go(pat);
+ Go(expr);
+
+ foreach ((_, expr) in lst)
+ Go(expr);
+ }
+
+ Go(case.body);
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(pattern : T.Pattern) : void
+ {
+ when (_info.Push(pattern))
+ {
+ match (pattern)
+ {
+ | Literal // { lit : Nemerle.Compiler.Literal; }
+ | Enum // { fld : IField; val : Nemerle.Compiler.Literal; }
+ | HasType // { typ : MType; }
+ | Wildcard
+ | Error => ()
+ | Application(_, pat) // { name : TypeInfo; arg : Pattern; }
+ | As (pat, _) => Go(pat); // { pat : Pattern; decl : LocalValue; }
+ | Tuple (lst) => Go(lst); // { args : list [Pattern]; }
+ | Record (args) => // { args : list [IMember * Pattern]; }
+
+ foreach ((_, pat) in args)
+ Go(pat);
+ }
+
+ _info.Pop();
+ }
+ }
+
+ protected Go(expression : T.TExpr) : void
+ {
+ when (_info.Push(expression))
+ {
+ match (expression)
+ {
+ | Block (_, e) // { jump_out : LocalValue; body : TExpr; }
+ | Label (_, e) // { id : int; body : TExpr; }
+ | TupleIndexer (e, _, _) // { obj : TExpr; pos : int; len : int; } // 0-based
+ | Throw (e) // { exn : TExpr; }
+ | HasType (e, _) // { expr : TExpr; test_ty : MType; }
+ | PropertyMember(e, _) // { obj : TExpr; prop : IProperty; }
+ | FieldMember (e, _) // { obj : TExpr; fld : IField; }
+ | EventMember (e, _) // { obj : TExpr; ev : IEvent; }
+ | DebugInfo (e, _) // { expr : TExpr; pe : PExpr; }
+ | TypeConversion(e, _, _, _) // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; target_type_location : Location; }
+ | MacroEnvelope (_, _, e) // { original : Parsetree.PExpr; the_macro : IMacro; expanded : TExpr; }
+ | MethodRef (e, _, _, _) => Go(e); // { obj : TExpr; meth : IMethod; type_parms : list [TyVar]; notvirtual : bool; }
+ | ArrayIndexer (e, lst) => Go(e); Go(lst); // { obj : TExpr; args : list [TExpr]; }
+ | Call (e, lst, _) => Go(e); Go(lst); // { mutable func : TExpr; mutable parms : list [Parm]; mutable is_tail : bool; }
+ | Sequence (e1, e2) // { mutable e1 : TExpr; mutable e2 : TExpr; }
+ | TryFinally (e1, e2) // { body : TExpr; handler : TExpr; }
+ | Assign (e1, e2) // { target : TExpr; source : TExpr; }
+ | DefValIn (_, e1, e2) => Go(e1); Go(e2); // { name : LocalValue; val : TExpr; mutable body : TExpr; }
+ | Try (e, lst) => Go(e); Go(lst); // { body : TExpr; mutable cases : list [Try_case]; }
+ | Tuple (lst) => Go(lst); // { args : list [TExpr]; }
+ | SelfTailCall (lst) => Go(lst); // { parms : list [Parm]; }
+ | Array (l1, l2) => Go(l1); Go(l2); // { args : list [TExpr]; dimensions : list [TExpr]; }
+ | DefFunctionsIn(lst, e) => Go(lst); Go(e); // { funs : list [Fun_header]; mutable body : TExpr; }
+ | Match (e, lst) => Go(e); Go(lst); // { expr : TExpr; cases : list [Match_case]; }
+ | If (e1, e2, e3) => Go(e1); Go(e2); Go(e3); // { cond : TExpr; e_then : TExpr; e_else : TExpr; }
+ | Switch (e, o, lst) => // { indexing_expr : TExpr; default : option [TExpr]; cases : list [int * TExpr]; }
+
+ Go(e);
+ match (o) { | Some(e) => Go(e) | _ => () }
+
+ foreach ((_, e) in lst)
+ Go(e);
+
+ | MultipleAssign(lst) => // { assigns : list [LocalValue * TExpr]; }
+
+ foreach ((_, e) in lst)
+ Go(e);
+
+ | Delayed(susp) => // { susp : Typer.DelayedTyping; }
+
+ when (susp.IsResolved)
+ Go(susp.ResolutionResult);
+
+ | Cache (desc, e) => Go(desc.TExpr); Go(e);
+ | CacheRef(desc) => Go(desc.TExpr);
+
+ | ImplicitValueTypeCtor
+ | StaticEventRef // { from : MType.Class; ev : IEvent; }
+ | ConstantObjectRef // { from : MType.Class; mem : IField; }
+ | StaticPropertyRef // { from : MType.Class; prop : IProperty; }
+ | StaticRef // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
+ | LocalRef // { decl : LocalValue; }
+ | LocalFunRef // { decl : LocalValue; type_parms : list [TyVar]; }
+ | Literal // { val : Nemerle.Compiler.Literal; }
+ | MethodAddress // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
+ | Base // { base_ctor : IMethod; }
+ | TypeOf // { target_type : TyVar; }
+ | OpCode // { name : string; }
+ | Goto // { target : int; mutable try_block : int; }
+ | DefaultValue
+ | Error
+ | This => ()
+ }
+
+ _info.Pop();
+ }
+ }
+
+ public Walk([NotNull] expression : P.PExpr, [NotNull] walkHandler : ExprWalkHandler) : void
+ {
+ Init(walkHandler);
+ Go(expression);
+ }
+
+ public Walk([NotNull] pattern : T.Pattern, [NotNull] walkHandler : ExprWalkHandler) : void
+ {
+ Init(walkHandler);
+ Go(pattern);
+ }
+
+ public Walk([NotNull] member : P.ClassMember, [NotNull] walkHandler : ExprWalkHandler) : void
+ {
+ Init(walkHandler);
+ Go(member);
+ }
+
+ public Walk([NotNull] expression : T.TExpr, [NotNull] walkHandler : ExprWalkHandler) : void
+ {
+ Init(walkHandler);
+ Go(expression);
+ }
+
+ /*
+ public Walk([NotNull] expression : Decl, [NotNull] walkHandler : ExprWalkHandler) : void
+ {
+ .Init(walkHandler);
+ Go(expression);
+ }
+ */
+
+ public GetLocation(expression : P.PExpr) : Location
+ {
+ mutable loc = expression.Location;
+
+ Walk(expression, info =>
+ {
+ when (info.Node is Located)
+ loc = loc.Combine((info.Node :> Located).Location);
+ });
+
+ loc
+ }
+
+ public GetLocation(member : P.ClassMember) : Location
+ {
+ mutable loc = member.Location;
+
+ Walk(member, info =>
+ {
+ when (info.Node is Located)
+ loc = loc.Combine((info.Node :> Located).Location);
+ });
+
+ loc
+ }
+
+ public Resolve(expression : T.TExpr) : void
+ {
+ Walk(expression, info =>
+ {
+ match (info.Node)
+ {
+ | tExpr is T.TExpr =>
+ match (tExpr)
+ {
+ | T.TExpr.Delayed(susp) when !susp.IsResolved => susp.Resolve();
+ | _ => ()
+ }
+ | _ => ()
+ }
+ });
+ }
+ }
+}
Modified: nemerle/trunk/ncc/misc/PrettyPrint.n
==============================================================================
--- nemerle/trunk/ncc/misc/PrettyPrint.n (original)
+++ nemerle/trunk/ncc/misc/PrettyPrint.n Mon Jul 2 07:28:11 2007
@@ -1237,8 +1237,9 @@
| TT.TExpr.Error =>
append ("(ERROR)")
- | TT.TExpr.DebugInfo =>
- append ("(DEBUG)")
+ | TT.TExpr.DebugInfo (e, _) =>
+ append ("(DEBUG_INFO) :\n");
+ recurse_and_indent (e);
| TT.TExpr.MethodAddress (_, meth, is_virt, _) =>
append ($ "ADDR($meth, $is_virt)")
Modified: nemerle/trunk/ncc/parsing/ParseTree.n
==============================================================================
Modified: nemerle/trunk/ncc/parsing/Utility.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Utility.n (original)
+++ nemerle/trunk/ncc/parsing/Utility.n Mon Jul 2 07:28:11 2007
@@ -329,7 +329,7 @@
if (mng.IsIntelliSenseMode)
s [s.Count - 1].AsGenerated ()
else
- s [s.Count - 1]
+ s [s.Count - 1]//IT.TEMP.AsGenerated ()
}
}
}
Modified: nemerle/trunk/ncc/typing/TypedTree.n
==============================================================================
--- nemerle/trunk/ncc/typing/TypedTree.n (original)
+++ nemerle/trunk/ncc/typing/TypedTree.n Mon Jul 2 07:28:11 2007
@@ -28,7 +28,6 @@
using Nemerle.Compiler;
using Nemerle.Utility;
-using Nemerle.Compiler.Typedtree;
using Nemerle.Assertions;
namespace Nemerle.Compiler.Typedtree
@@ -707,7 +706,7 @@
| Switch { indexing_expr : TExpr;
default : option [TExpr];
cases : list [int * TExpr]; }
- | DebugInfo { expr : TExpr; }
+ | DebugInfo { expr : TExpr; pexpr : Nemerle.Compiler.Parsetree.PExpr}
public mutable ty : TyVar;
@@ -829,6 +828,8 @@
ty = InternalType.Boolean
| MacroEnvelope (_, _, e) =>
ty = e.Type
+ | DebugInfo (e, _) =>
+ ty = e.Type
| Cache as c =>
assert (c.body != null, $ "when trying to determin type, body is null: $this");
ty = c.body.Type
@@ -989,7 +990,6 @@
| LocalRef
| LocalFunRef
| StaticRef
- | DebugInfo
| Error
| OpCode
| TypeOf
@@ -1135,6 +1135,14 @@
TypeConversion (expr, t, kind, tl)
+ | DebugInfo (e, pe) =>
+ def e' = walk (f, e);
+ if (e' : object == e)
+ null
+ else
+ DebugInfo (expr.loc, null, e', pe)
+
+
| Sequence (e1, e2) =>
def e1' = walk (f, e1);
def e2' = walk (f, e2);
Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n (original)
+++ nemerle/trunk/ncc/typing/Typer.n Mon Jul 2 07:28:11 2007
@@ -1175,6 +1175,14 @@
Manager.Complete (expression, expected, this, env);
}
+ def addDebugInfo(res)
+ {
+ //if (expression.IsGenerated || expression.loc.IsEmpty || Manager.IsIntelliSenseMode)
+ res
+ //else
+ // TExpr.DebugInfo(expression.Location, null, res, expression);
+ }
+
def texpr = match (expression)
{
| PT.PExpr.ParmByRef
@@ -1188,6 +1196,7 @@
| PT.PExpr.DefMutable (PT.PExpr.Ref as name, val)
| PT.PExpr.Define (PT.PExpr.Ref as name, val) =>
def is_mutable = expression is PT.PExpr.DefMutable;
+ def res =
if (Expect (expected, InternalType.Void, "definition ``result''"))
if (is_toplevel_in_seq)
TypeLocalDefinition (is_mutable, name.name, name.Location, val)
@@ -1199,9 +1208,10 @@
PopLocals ()
}
else
- TExpr.Error ()
+ TExpr.Error ();
+ addDebugInfo(res);
- | DefMutable (Tuple (Ref (first_n) :: names), Tuple (first_v :: vals)) =>
+ | PT.PExpr.DefMutable (Tuple (Ref (first_n) :: names), Tuple (first_v :: vals)) =>
if (Expect (expected, InternalType.Void, "definition ``result''"))
try {
unless (is_toplevel_in_seq)
@@ -1236,13 +1246,13 @@
else
TExpr.Error ()
- | DefMutable (TypeEnforcement (nm, ty) as te, val) =>
+ | PT.PExpr.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")
+ | PT.PExpr.DefMutable => Message.FatalError ($"incorrect mutable variables definition: $expression")
| PT.PExpr.Define (pat, expr) =>
if (Expect (expected, InternalType.Void, "definition ``result''"))
@@ -1638,7 +1648,7 @@
| PT.PExpr.Sequence ([]) =>
_ = Expect (expected, InternalType.Void, "empty sequence");
- VoidLiteral ()
+ addDebugInfo (VoidLiteral ())
| PT.PExpr.Sequence (l) =>
@@ -1660,7 +1670,7 @@
def res = loop ([], l);
//Message.Debug ("pop seq");
PopLocals ();
- res
+ addDebugInfo (res)
| PT.PExpr.Tuple (l) =>
Modified: nemerle/trunk/ncc/typing/Typer2.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer2.n (original)
+++ nemerle/trunk/ncc/typing/Typer2.n Mon Jul 2 07:28:11 2007
@@ -1351,7 +1351,8 @@
| TExpr.Error => null
- | TExpr.DebugInfo => null
+ | TExpr.DebugInfo (e, pe) =>
+ TExpr.DebugInfo (expr.loc, null, Walk (ctx, e), pe);
| TExpr.Goto =>
unless (ctx %&& Context.AllowGoto)
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/AstBrowserForm.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 Mon Jul 2 07:28:11 2007
@@ -47,8 +47,7 @@
<Compile Include="Nemerle.Completion2\CodeModel\Checker.n" />
<Compile Include="Nemerle.Completion2\CodeModel\CompileUnitCollection.n" />
<Compile Include="Nemerle.Completion2\CodeModel\ExprFinder.n" />
- <Compile Include="Nemerle.Completion2\CodeModel\ExprWalkInfo.n" />
- <Compile Include="Nemerle.Completion2\CodeModel\ExprWalker.n" />
+ <Compile Include="Nemerle.Completion2\CodeModel\ExprDeclWalker.n" />
<Compile Include="Nemerle.Completion2\CodeModel\GlyphType.n" />
<Compile Include="Nemerle.Completion2\CodeModel\GotoInfo.n" />
<Compile Include="Nemerle.Completion2\CodeModel\MethodTipInfo.n" />
Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprDeclWalker.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprDeclWalker.n Mon Jul 2 07:28:11 2007
@@ -0,0 +1,54 @@
+using System;
+
+using Nemerle.Assertions;
+using Nemerle.Compiler;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Compiler.Typedtree;
+using Nemerle.Compiler.Utils;
+using Nemerle.Imperative;
+using Nemerle.Utility;
+
+using P = Nemerle.Compiler.Parsetree;
+using T = Nemerle.Compiler.Typedtree;
+
+namespace Nemerle.Completion2
+{
+ public class ExprDeclWalker : ExprWalker
+ {
+ public this()
+ {
+ }
+
+ public this(callback : IExprWalkerCallback)
+ {
+ base(callback);
+ }
+
+ private Go(lst : list[Decl]) : void { when (lst != null) foreach (item in lst) Go(item); }
+
+ private Go(decl : Decl) : void
+ {
+ when (Push(decl))
+ {
+ match (decl)
+ {
+ | n is Decl.Namespace => Go(n.Decls);
+ | t is Decl.Type => Go(t.Builder);
+ | GlobalAttribute
+ | Using
+ | None
+ | _ => ()
+ }
+
+ Pop();
+ }
+ }
+
+ public Walk([NotNull] expression : Decl, [NotNull] walkHandler : ExprWalkHandler) : void
+ {
+ Init(walkHandler);
+ Go(expression);
+ }
+ }
+}
+
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 Mon Jul 2 07:28:11 2007
@@ -12,7 +12,7 @@
namespace Nemerle.Completion2
{
- class ExprFinder
+ class ExprFinder : IExprWalkerCallback
{
mutable _line : int;
mutable _col : int;
@@ -21,6 +21,41 @@
mutable _texprObject : object;
mutable _decl : Decl;
mutable _location : Location;
+ mutable _walkedNodes : list[object] = [];
+
+ #region IExprWalkerCallback interface
+
+ Push(info : ExprWalkInfo) : void implements IExprWalkerCallback.Push
+ {
+ _walkedNodes ::= info.Node;
+ }
+
+ Pop (_ : ExprWalkInfo) : void implements IExprWalkerCallback.Pop
+ {
+ match (_walkedNodes)
+ {
+ | _ :: tail => _walkedNodes = tail;
+ | [] => ()
+ }
+ }
+
+ Stop(_ : ExprWalkInfo) : void implements IExprWalkerCallback.Stop
+ {
+#if PRINT_AST && DEBUG
+ repeat (_walkedNodes.Length) Trace.Write(" ");
+ Trace.WriteLine("Stopped!");
+#endif
+ }
+
+ Skip(_ : ExprWalkInfo) : void implements IExprWalkerCallback.Skip
+ {
+#if PRINT_AST && DEBUG
+ repeat (_walkedNodes.Length) Trace.Write(" ");
+ Trace.WriteLine("Skipped!");
+#endif
+ }
+
+ #endregion
GetTypedObject(obj : object) : object
{
@@ -37,7 +72,7 @@
{
def loc = obj.Location;
- Print(obj, loc, info.Nodes.Length);
+ Print(obj, loc, _walkedNodes.Length);
if (IsIn(loc))
{
@@ -47,7 +82,7 @@
{
when (_pexprObject == null || _location.Contains(loc))
{
- PrintAdd(info.Nodes.Length);
+ PrintAdd(_walkedNodes.Length);
_parentObject = _pexprObject;
_location = loc;
@@ -78,7 +113,7 @@
{
def loc = obj.Location;
- Print(obj, loc, info.Nodes.Length);
+ Print(obj, loc, _walkedNodes.Length);
if (IsIn(loc))
{
@@ -239,7 +274,7 @@
{
match (info.Node)
{
- | l is Located => Print(info.Node, l.Location, info.Nodes.Length);
+ | l is Located => Print(info.Node, l.Location, _walkedNodes.Length);
| _ => ()
}
});
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
==============================================================================
More information about the svn
mailing list