[svn]
r7505: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel:
ExprFinder.n ExprWalker...
kliss
svnadmin at nemerle.org
Wed Feb 28 21:00:22 CET 2007
Log:
Remove warnings.
Author: kliss
Date: Wed Feb 28 21:00:18 2007
New Revision: 7505
Modified:
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/CodeModel/Formatter.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 Feb 28 21:00:18 2007
@@ -272,14 +272,14 @@
!location.IsGenerated && location.Contains(_line, _col);
}
- IsInList(locations : list[Location]) : bool
- {
- match(locations.Find(IsIn))
- {
- | Some => true;
- | _ => false;
- }
- }
+ //IsInList(locations : list[Location]) : bool
+ //{
+ // match(locations.Find(IsIn))
+ // {
+ // | Some => true;
+ // | _ => false;
+ // }
+ //}
IsInEx(location : Location) : bool
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 Wed Feb 28 21:00:18 2007
@@ -47,7 +47,8 @@
| t is Decl.Type => Go(t.Builder);
| GlobalAttribute
| Using
- | None => ()
+ | None
+ | _ => ()
}
_info.Pop();
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n Wed Feb 28 21:00:18 2007
@@ -1,19 +1,12 @@
-// IT: we use spaces for indentation in the compiler and integration projects.
-// Please, follow this rule.
-// You can switch to spaces in the C++ project settings (old Nemerle integration is fake).
-// To control spaces and tabs use Ctrl+R+W.
-//
-// Another issue is warnings. Please, don't leave them in the source code you submit in the repository.
-//
-// After you are done with your settings, please, remove this comment.
-
using Nemerle.Utility;
using Nemerle.Compiler;
using Nemerle.Completion2;
using System;
using System.Diagnostics;
+using Nemerle.Compiler.Utils;
using SCG = System.Collections.Generic;
+using Nemerle.Compiler.Parsetree;
using MsgBox = System.Windows.Forms.MessageBox;
@@ -43,6 +36,10 @@
mutable _startLine = 0;
mutable _endLine = 0;
+ mutable _results : list[FormatterResult] = [];
+ mutable _expectedLine = 0;
+ mutable _expectedCol = 0;
+
public Engine : Engine
{
mutable _engine : Engine;
@@ -55,52 +52,209 @@
Engine = engine;
}
- public FormatDocument(filePath : string) : SCG.List[FormatterResult]
+ private FormatNamespace(ns : Decl.Namespace) : SCG.List[FormatterResult]
{
- def results = SCG.List.[FormatterResult]();
- def declNS = this.Engine.Project.CompileUnits[filePath];
- def usings = SCG.List.[Decl.Using]();
- mutable usingsLocation = Location.Default;
-
- def processUsing(ns : Decl.Using)
+ def result = SCG.List.[FormatterResult]();
+ foreach(x in ns.Decls)
+ {
+ match(x)
{
- usings.Add(ns);
- usingsLocation += ns.Location;
+ | Decl.Namespace as n => result.AddRange(FormatNamespace(n));
+ | Decl.Type as t => result.AddRange(FormatType(t));
+ | Decl.Using as u => result.AddRange(FormatUsing(u));
+ | _ => ()
+ }
+ }
+
+ result;
}
- def processDecls(decls : list[Decl])
+ private FormatUsing(us : Decl.Using) : SCG.List[FormatterResult]
{
- match(decls)
+ def result = SCG.List.[FormatterResult]();
+ def level = 1;
+ if(us.Location.Column > level)
{
- | (Decl.Using as d) :: rest => processUsing(d); processDecls(rest);
- | _ => ();
+ def startCol = 1;
+ def endCol = us.Location.Column;
+ def line = us.Location.Line;
+ def loc = Location(us.Location.FileIndex, line, startCol, line, endCol);
+ result.Add(FormatterResult(loc, "\t\t"));
}
+ else
+ {
+ def startCol = us.Location.Column;
+ def endCol = us.Location.Column;
+ def line = us.Location.Line;
+ def loc = Location(us.Location.FileIndex, line, startCol, line, endCol);
+ result.Add(FormatterResult(loc, "\t\t"));
+ }
+ result;
+ }
+
+ private FormatType(_tb : Decl.Type) : SCG.List[FormatterResult]
+ {
+ def result = SCG.List.[FormatterResult]();
+ result;
}
- def writeFormattedUsings()
+ private WalkHandler (info : ExprWalkInfo) : void
+ {
+ def node = info.Node;
+
+ if(node != null)
+ {
+ def loc = if(node is Located)
+ (node :> Located).Location
+ else if(node is IMember)
+ (node :> IMember).Location
+ else if(node is Decl)
+ (node :> Decl).Location
+ else
+ Location.Default;
+ Print(node, loc, 1);
+
+ match(node)
{
- def replacement = System.Text.StringBuilder();
- foreach(usingDecl in usings)
+ | pe is PExpr when pe.Location.Line == pe.Location.EndLine =>
+ match(pe)
{
- _ = replacement.AppendFormat("using {0};{1}",
- usingDecl.Name.ToString("."),
- Environment.NewLine);
+ | PExpr.Define
+ | PExpr.Assign
+ | PExpr.Call
+ | PExpr.Sequence => info.Skip()
+ | _ => ()
}
+ | se is SyntaxElement when se.Location.Line == se.Location.EndLine =>
+ info.Skip();
+ | _ => ()
+ }
+ }
+ else
+ {
+ Trace.WriteLine("info.Node is null");
+ }
+ }
+
+ Print(obj : object, loc : Location, level : int) : void
+ {
+ _ = obj.ToString();
+
+#if DEBUG
+ def indentation = string(' ', level);
+ mutable os = obj.ToString();
+
+ when (os.Length > 200)
+ os = os.Substring(0, 200) + "...";
- def fr = FormatterResult(usingsLocation.Column - 1, usingsLocation.Line - 1,
- usingsLocation.EndColumn, usingsLocation.EndLine - 1,
- replacement.ToString());
- results.Add(fr);
+ Trace.WriteLine("");
+ Trace.WriteLine(indentation +
+ $"$(obj.GetType().FullName) "
+ "$(loc.Line):$(loc.Column):$(loc.EndLine):$(loc.EndColumn)"
+ "$(if (loc.IsGenerated) '-' else '+')");
+ Trace.WriteLine(indentation + os.Replace("\n", "\n" + indentation));
+#endif
+
+ ignore(obj); ignore(loc); ignore(level);
}
- processDecls(declNS.Decls);
- writeFormattedUsings();
+ public FormatDocument(filePath : string) : SCG.List[FormatterResult]
+ {
+ def results = SCG.List.[FormatterResult]();
+ def declNS = this.Engine.Project.CompileUnits[filePath];
+
+ //def frm = AstBrowserForm(this.Engine.NameTree.NamespaceTree);
+ //_ = frm.ShowDialog();
+
+ //mutable usings : list[Decl.Using] = [];
+
+ //mutable usingsLocation = Location.Default;
+
+ //def processUsing(ns : Decl.Using)
+ //{
+ // usings ::= ns;
+ // usingsLocation += ns.Location;
+ //}
+
+ //def processDecls(decls : list[Decl])
+ //{
+ // match(decls)
+ // {
+ // | x :: xs =>
+ // match(x)
+ // {
+ // | Decl.Using as u => processUsing(u);
+ // | Decl.Type as t => Debug.WriteLine($"Found type: $t");
+ // | _ => ();
+ // }
+ // processDecls(xs);
+ // | _ => ();
+ // }
+ //}
+ //
+ //def writeFormattedUsings()
+ //{
+ // def replacement = System.Text.StringBuilder();
+ //
+ // def compareFirstWord(u1, u2)
+ // {
+ // string.Compare(u1.Name.Head, u2.Name.Head);
+ // }
+ // def compareLength(u1, u2)
+ // {
+ // u1.Name.ToArray().Length - u2.Name.ToArray().Length;
+ // }
+ // def compareSystem(u1, u2)
+ // {
+ // if(u1.Name.Head.Equals("System"))
+ // -1
+ // else if(u2.Name.Head.Equals("System"))
+ // 1
+ // else 0
+ // }
+ // def compareAlias(u1 : Decl.Using, u2)
+ // {
+ // def first = if(string.IsNullOrEmpty(u1.Alias)) 1 else 0;
+ // def second = if(string.IsNullOrEmpty(u2.Alias)) 1 else 0;
+ // second - first
+ // }
+ //
+ // usings = usings
+ // .Sort(compareFirstWord)
+ // .Sort(compareLength)
+ // .Sort(compareSystem)
+ // .Sort(compareAlias);
+ //
+ // foreach(usingDecl in usings)
+ // {
+ // _ = replacement.AppendFormat("using {0}{1};{2}",
+ // if(usingDecl.Alias == "") ""
+ // else $"$(usingDecl.Alias) = ",
+ // usingDecl.Name.ToString("."),
+ // Environment.NewLine);
+ // }
+ //
+ // def fr = FormatterResult(usingsLocation.Column - 1, usingsLocation.Line - 1,
+ // usingsLocation.EndColumn, usingsLocation.EndLine - 1,
+ // replacement.ToString());
+ // results.Add(fr);
+ //}
+
+ //processDecls(declNS.Decls);
+ //writeFormattedUsings();
+ //
+
+ //def (loc1, d1) = ExprFinder().Find(declNS, 4, 8);
+ //def (loc2, d2) = ExprFinder().Find(declNS, 17, 16);
+ //def (loc3, d3) = ExprFinder().Find(declNS, 11, 7);
+ ExprWalker().Walk(declNS, WalkHandler);
+ //results.AddRange(FormatNamespace(declNS));
results;
}
- // Here we have to fund out what piece of AST to analyze
+ // Here we have to find out what piece of AST to analyze
public FormatSpan(_startLine : int, _startCol : int, _endLine : int,
_endCol : int, _filePath : string) : SCG.List[FormatterResult]
{
More information about the svn
mailing list