[svn] r7263: nemerle/trunk/ncc: generation/DecisionTreeCompiler.n
generation/ILEmitter.n testsuite/misc/de...
nazgul
svnadmin at nemerle.org
Fri Jan 12 22:24:58 CET 2007
Log:
Fix debugging locations in match. Do not mark simple constructs if inside complex constructs
Author: nazgul
Date: Fri Jan 12 22:24:45 2007
New Revision: 7263
Added:
nemerle/trunk/ncc/testsuite/misc/debugging.n
Modified:
nemerle/trunk/ncc/generation/DecisionTreeCompiler.n
nemerle/trunk/ncc/generation/ILEmitter.n
Modified: nemerle/trunk/ncc/generation/DecisionTreeCompiler.n
==============================================================================
--- nemerle/trunk/ncc/generation/DecisionTreeCompiler.n (original)
+++ nemerle/trunk/ncc/generation/DecisionTreeCompiler.n Fri Jan 12 22:24:45 2007
@@ -95,7 +95,7 @@
if (body_emitted || label_id.IsNone) prev
else {
body_emitted = true;
- TExpr.Sequence (prev.loc + body.loc, body.Type, prev, body)
+ TExpr.Sequence (prev.loc, body.Type, prev, body)
}
}
}
Modified: nemerle/trunk/ncc/generation/ILEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/ILEmitter.n (original)
+++ nemerle/trunk/ncc/generation/ILEmitter.n Fri Jan 12 22:24:45 2007
@@ -67,6 +67,10 @@
private _labels : Hashtable [int, Label] = Hashtable ();
private _label_usage : Hashtable [int, TExpr] = Hashtable ();
+ // marks how deep we are inside in the blocks of code,
+ // which disable debug-marking of simple constructs, like local value or field access
+ private mutable limited_debug_nesting = 0;
+
static MS_NET_RuntimeType : System.Type
= typeof (object).Assembly.GetType ("System.RuntimeType");
@@ -188,6 +192,11 @@
}
}
+ MaybeMark (loc : Location) : void {
+ when (limited_debug_nesting == 0)
+ Mark (loc);
+ }
+
IsDebugEnabled : bool {
get { _debug_doc != null }
}
@@ -410,8 +419,10 @@
emit_parms (parms : list [Parm]) : void
{
+ limited_debug_nesting++;
foreach (parm in parms)
emit (parm.expr);
+ limited_debug_nesting--;
}
static skipped (expr : TExpr) : void
@@ -590,7 +601,9 @@
_ilg.Emit (opcode, else_label);
| HasType (val, ty) =>
+ limited_debug_nesting++;
emit (val);
+ limited_debug_nesting--;
need_reference (val.SystemType);
_ilg.Emit (OpCodes.Isinst, ty.SystemType);
_ilg.Emit (OpCodes.Brfalse, else_label);
@@ -613,7 +626,9 @@
| _ =>
//Message.Debug (e.loc, pretty_print (e));
// most of other expressions here are TExpr.Ref
+ limited_debug_nesting++;
emit (expr);
+ limited_debug_nesting--;
unless (expr.Throws)
_ilg.Emit (OpCodes.Brfalse, else_label);
}
@@ -694,7 +709,7 @@
/* load runtime representation of given type */
| TypeOf (t) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
_ilg.Emit (OpCodes.Ldtoken, t.SystemType);
_ilg.Emit (OpCodes.Call, SystemTypeCache.Type_GetTypeFromHandle);
@@ -817,7 +832,7 @@
/* unbox value types or perform value type conversion */
| TypeConversion (val, cast_to_type, kind) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
def is_checked = ! (kind is IL (false));
emit (val);
def type_of_expr = val.SystemType;
@@ -855,19 +870,21 @@
/* load the value of a local variable or a method parameter */
| LocalRef (decl) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
unless (is_void (decl.Type))
emit_ce_ref (decl, get_address_for_value_types = expr.NeedAddress)
/* load the value of a field */
| FieldMember (base_object, field) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
def result_will_be_address = expr.NeedAddress;
+ limited_debug_nesting++;
if (result_will_be_address)
_ = emit_and_convert_to_address (base_object);
else
emit (base_object);
+ limited_debug_nesting--;
maybe_volatile (expr);
@@ -882,7 +899,7 @@
/* load the value of a static field */
| StaticRef (t, f is IField, _) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
def field_info = GetFieldInfo (t.SystemType, f);
assert (field_info.IsStatic, "GlobalRef to a non-static field");
@@ -901,9 +918,11 @@
/* load an array element */
| ArrayIndexer (array_obj, [index]) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
+ limited_debug_nesting++;
emit (array_obj);
emit (index);
+ limited_debug_nesting--;
def element_type = array_obj.SystemType.GetElementType ();
assert (element_type != null, "non-array in TExpr.ArrayIndexer");
@@ -914,12 +933,14 @@
| ArrayIndexer (array_obj, indexes) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
+ limited_debug_nesting++;
emit (array_obj);
List.Iter (indexes, emit);
def method =
if (expr.NeedAddress) array_addr_method (array_obj)
else array_get_method (array_obj);
+ limited_debug_nesting--;
emit_method_call (expr, true, method);
@@ -941,7 +962,9 @@
| Assign (LocalRef (local_var), val) when local_var.IsByRefParm =>
Mark (expr.loc);
emit_ldarg (local_var.ParmIndex);
+ limited_debug_nesting++;
emit (val);
+ limited_debug_nesting--;
def ty = val.SystemType;
if (ty.IsValueType || ty.IsGenericParameter)
_ilg.Emit (OpCodes.Stobj, ty)
@@ -952,7 +975,9 @@
/* assignment to a local variable */
| Assign (LocalRef (local_var), val) =>
Mark (expr.loc);
+ limited_debug_nesting++;
emit (val);
+ limited_debug_nesting--;
unless (val.Throws)
store_local (local_var);
@@ -960,8 +985,10 @@
/* assignment to a field */
| Assign (FieldMember (base_object, field) as target, val) =>
Mark (expr.loc);
+ limited_debug_nesting++;
emit (base_object);
emit (val);
+ limited_debug_nesting--;
maybe_volatile (target);
def field_info = GetFieldInfo (base_object, field);
@@ -972,7 +999,9 @@
/* assignment to a static field */
| Assign (StaticRef (t, f is IField, _) as target, val) =>
Mark (expr.loc);
+ limited_debug_nesting++;
emit (val);
+ limited_debug_nesting--;
maybe_volatile (target);
def field_info = GetFieldInfo (t.SystemType, f);
@@ -984,20 +1013,23 @@
| Assign (ArrayIndexer (array_obj, [index]) as target, val) =>
Mark (expr.loc);
def type_of_val = val.SystemType;
-
+ limited_debug_nesting++;
emit (array_obj);
emit (index);
when (type_of_val.IsValueType && !type_of_val.IsPrimitive)
_ilg.Emit (OpCodes.Ldelema, type_of_val);
emit (val);
+ limited_debug_nesting--;
emit_array_store_opcode (target.SystemType);
| Assign (ArrayIndexer (array_obj, indexes), val) =>
Mark (expr.loc);
+ limited_debug_nesting++;
emit (array_obj);
List.Iter (indexes, emit);
emit (val);
+ limited_debug_nesting--;
def method = array_set_method (array_obj);
emit_method_call (expr, true, method);
@@ -1016,7 +1048,9 @@
else
_ilg.Emit (OpCodes.Pop);
}
+ limited_debug_nesting++;
foreach ((_, e) in assigns) emit (e);
+ limited_debug_nesting--;
List.Iter (List.Rev (assigns), emit_store);
@@ -1238,7 +1272,9 @@
| Throw (exc) =>
Mark (expr.loc);
+ limited_debug_nesting++;
emit (exc);
+ limited_debug_nesting--;
_ilg.Emit (OpCodes.Throw);
@@ -1348,7 +1384,9 @@
/* -- TUPLES -------------------------------------------------------- */
| Tuple (vals) =>
+ limited_debug_nesting++;
foreach (v in vals) emit (v);
+ limited_debug_nesting--;
def ctor = InternalType.GetTupleType (vals.Length).Ctor;
_ilg.Emit (OpCodes.Newobj, GetConstructorInfo (expr.SystemType, ctor));
@@ -1357,7 +1395,9 @@
def tt = InternalType.GetTupleType (len);
//when (tt.TyCon.IsValueType && !obj.NeedAddress)
// obj.NeedAddress = true;
+ limited_debug_nesting++;
emit (obj);
+ limited_debug_nesting--;
_ilg.Emit (OpCodes.Ldfld, GetFieldInfo (obj.SystemType, tt.GetField (pos + 1)));
@@ -1377,6 +1417,7 @@
/* loads a literal on the evaluation stack */
| Literal (l) =>
+ MaybeMark (expr.Location);
Util.cassert (l != null);
if (l is Literal.Null)
match (expr.MType) {
@@ -1387,7 +1428,6 @@
}
else if (l is Literal.Void) {
when (IsDebugEnabled) {
- Mark (expr.Location);
_ilg.Emit (OpCodes.Nop);
}
} else
@@ -1395,7 +1435,7 @@
/* loads address of given method */
| MethodAddress (from, meth, is_virt, typarms) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
def meth = GetMethodInfo (from, meth, typarms);
if (is_virt && meth.IsVirtual) {
// ldvirtftn expects also an object reference
@@ -1409,7 +1449,7 @@
/* creates object of value type using implicit ctor */
| ImplicitValueTypeCtor =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
when (_debug_doc != null) _ilg.BeginScope ();
def t = expr.SystemType;
def local_slot = _ilg.DeclareLocal (t);
@@ -1421,13 +1461,13 @@
/* creates a new array, given a list of initializers */
| Array (initializers, [size]) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
def element_type =
match (expr.Type.Fix ()) {
| MType.Array (t, _) => t.SystemType
| _ => Util.ice ()
}
-
+ limited_debug_nesting++;
emit (size);
_ilg.Emit (OpCodes.Newarr, element_type);
@@ -1446,10 +1486,12 @@
load_elements (index + 1, rest)
}
};
+ limited_debug_nesting--;
load_elements (0, initializers);
| Array (initializers, dimensions) =>
- Mark (expr.loc);
+ MaybeMark (expr.loc);
+ limited_debug_nesting++;
mutable size = 0;
foreach (element in dimensions) {
++size;
@@ -1501,6 +1543,7 @@
}
load_elements (array (dimensions_array.Length), initializers);
}
+ limited_debug_nesting--;
| _ =>
Message.Warning ($ "FIXME: unmatched: $expr");
Added: nemerle/trunk/ncc/testsuite/misc/debugging.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/misc/debugging.n Fri Jan 12 22:24:45 2007
@@ -0,0 +1,48 @@
+using SCG = System.Collections.Generic;
+
+variant V {
+ | A { x : int }
+ | B
+ | C { y : string }
+}
+
+class C {
+ public static foo (s : SCG.IEnumerable [int], mutable ini : int) : int {
+ foreach (x in s)
+ ini += x;
+ ini
+ }
+
+
+ public static bar (x : string) : string {
+ System.Console.WriteLine (x);
+ x
+ }
+}
+
+def x = C.foo ([1,2,3], 10);
+System.Console.WriteLine (x);
+System.Console.WriteLine (
+ C.bar (
+ C.bar (
+ C.bar (
+ "ddd")))
+ );
+
+System.Console.WriteLine (x);
+
+def x = V.A (1) : V;
+match (x) {
+ | C (c) when 1 == 0 =>
+ System.Console.WriteLine (c);
+
+ | A (a)
+ | B with a = 1 =>
+ System.Console.WriteLine (a);
+ System.Console.WriteLine (a);
+
+ | C (c) when 1 == 1 =>
+ System.Console.WriteLine (c);
+}
+
+System.Console.WriteLine (x);
More information about the svn
mailing list