[Mono-devel-list] mcs patch for precise location handling

Marek Safar marek.safar at seznam.cz
Wed Jun 29 11:37:39 EDT 2005


Hello Eno,

> Sorry, the last patch actually didn't include the fix for bug
> #57047. This time it should be included (I found it running diff
> against two diff files).
> This time the patch changes only a few things than before:
> http://monkey.workarea.jp/tmp/20050627/precise-location-20050628_2.diff
>
I think can be useful make 'public class LocatedToken' struct as is 
passed only as an argument.
And use this class in similar way as MemberName for every relevant 
consumers.
For example:

@@ -334,17 +334,18 @@
 	: USING IDENTIFIER ASSIGN 
 	  namespace_or_type_name SEMICOLON
 	  {
-		current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
+		LocatedToken lt = (LocatedToken) $2;
+		current_namespace.UsingAlias (lt.StringValue, (MemberName) $4, lt.Location);
 	  }
 	| USING error {
-		CheckIdentifierToken (yyToken);
+		CheckIdentifierToken (yyToken, GetLocation ($2));
 	  }
 	;
 
 using_namespace_directive
 	: USING namespace_name SEMICOLON 
 	  {
-		current_namespace.Using ((MemberName) $2, lexer.Location);
+		current_namespace.Using ((MemberName) $2, (Location) $1);
           }
 	;


next example can be this one.

 constant_declarator
 	: IDENTIFIER ASSIGN constant_expression
 	  {
-		$$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
+		LocatedToken lt = (LocatedToken) $1;
+		$$ = new VariableDeclaration (lt.StringValue, $3, lt.Location);
 	  }



One more MemberName

 		current_namespace = new NamespaceEntry (
-			current_namespace, file, name.GetName (), lexer.Location);
+			current_namespace, file, name.GetName (), name.Location);
 	  }


Why is there so many locations ?

@@ -475,7 +475,7 @@
 
 		void Define_Fields ()
 		{
-			Location loc = Location.Null;
+			Location loc = Location;
 
 			pc_field = new Field (
 				this, TypeManager.system_int32_expr, Modifiers.PRIVATE, "PC",
@@ -536,8 +536,7 @@
 			Constructor ctor = new Constructor (
 				this, Name, Modifiers.PUBLIC, ctor_params,
 				new ConstructorBaseInitializer (
-					null, Parameters.EmptyReadOnlyParameters, Location),
-				Location);
+					null, Parameters.EmptyReadOnlyParameters, Location), Location);
 			AddConstructor (ctor);


MemberBase is derived from MemberCore

+Location GetLocation (object obj)
+{
+    if (obj is MemberCore)
+        return ((MemberCore) obj).Location;
+    if (obj is MemberName)
+        return ((MemberName) obj).Location;


The instance property IsNull can be more suitable.

-                if (location.Equals (Location.Null)) {
+                if (Location.IsNull (location)) {

>> It can save a lot.
>
>
> Actually it was 77618 KB to 77570 KB ;) But yeah, still better.

Yeah, it will be better.


Marek



More information about the Mono-devel-list mailing list