Author: lluis
Date: 2006-07-12 13:41:06 -0400 (Wed, 12 Jul 2006)
New Revision: 62520
Modified:
trunk/monodevelop/Extras/CSharpBinding/CSharpBinding.mdp
trunk/monodevelop/Extras/CSharpBinding/ChangeLog
trunk/monodevelop/Extras/CSharpBinding/Parser/LanguageItemVisitor.cs
trunk/monodevelop/Extras/CSharpBinding/Parser/Resolver.cs
trunk/monodevelop/Extras/CSharpBinding/Parser/SharpDevelopTree/ReturnType.cs
Log:
2006-07-12 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* Parser/Resolver.cs: Use a more meaningful name for the "current unit".
Store the name of the file being resolved in currentFile.
Changed SearchVariable, so it now returns a LocalVariable object,
with all information, including the region.
* Parser/LanguageItemVisitor.cs: Fix crash when processing indexers.
Return valid values for object creation expressions.
* Parser/SharpDevelopTree/ReturnType.cs: Added constructor which
takes a properly resolved class as parameter.
Modified: trunk/monodevelop/Extras/CSharpBinding/CSharpBinding.mdp
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/CSharpBinding.mdp 2006-07-12
17:37:42 UTC (rev 62519)
+++ trunk/monodevelop/Extras/CSharpBinding/CSharpBinding.mdp 2006-07-12
17:41:06 UTC (rev 62520)
@@ -13,6 +13,7 @@
<CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True" mainclass=""
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
</Configurations>
+ <DeployTargets />
<DeploymentInformation strategy="File">
<excludeFiles />
</DeploymentInformation>
Modified: trunk/monodevelop/Extras/CSharpBinding/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/ChangeLog 2006-07-12 17:37:42 UTC
(rev 62519)
+++ trunk/monodevelop/Extras/CSharpBinding/ChangeLog 2006-07-12 17:41:06 UTC
(rev 62520)
@@ -1,3 +1,14 @@
+2006-07-12 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * Parser/Resolver.cs: Use a more meaningful name for the "current unit".
+ Store the name of the file being resolved in currentFile.
+ Changed SearchVariable, so it now returns a LocalVariable object,
+ with all information, including the region.
+ * Parser/LanguageItemVisitor.cs: Fix crash when processing indexers.
+ Return valid values for object creation expressions.
+ * Parser/SharpDevelopTree/ReturnType.cs: Added constructor which
+ takes a properly resolved class as parameter.
+
2006-07-10 Alejandro Serrano <[EMAIL PROTECTED]>
* CSharpAmbience.cs: Add support for generics ambience.
Modified: trunk/monodevelop/Extras/CSharpBinding/Parser/LanguageItemVisitor.cs
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/Parser/LanguageItemVisitor.cs
2006-07-12 17:37:42 UTC (rev 62519)
+++ trunk/monodevelop/Extras/CSharpBinding/Parser/LanguageItemVisitor.cs
2006-07-12 17:41:06 UTC (rev 62520)
@@ -61,7 +61,8 @@
ArrayList methods = resolver.SearchMethod(type,
id);
resolver.ShowStatic = false;
if (methods.Count <= 0) {
- return null;
+ // It may be a call to a constructor
+ return resolver.SearchType (id,
resolver.CompilationUnit);
}
// TODO: Find the right method
return methods[0];
@@ -194,20 +195,26 @@
public override object Visit(IndexerExpression
indexerExpression, object data)
{
- IReturnType type =
(IReturnType)indexerExpression.TargetObject.AcceptVisitor(this, data);
- if (type == null) {
+ object ob =
indexerExpression.TargetObject.AcceptVisitor(this, data);
+ IReturnType type = ob as IReturnType;
+ if (type != null) {
+ if (type.ArrayDimensions == null ||
type.ArrayDimensions.Length == 0) {
+ if (indexerExpression.TargetObject is
ThisReferenceExpression) {
+ return null;
+ }
+ ArrayList indexer =
resolver.SearchIndexer(type);
+ if (indexer.Count == 0) {
+ return null;
+ }
+ // TODO: get the right indexer
+ return indexer[0];
+ }
return null;
}
- if (type.ArrayDimensions == null ||
type.ArrayDimensions.Length == 0) {
- if (indexerExpression.TargetObject is
ThisReferenceExpression) {
- return null;
- }
- ArrayList indexer =
resolver.SearchIndexer(type);
- if (indexer.Count == 0) {
- return null;
- }
- // TODO: get the right indexer
- return indexer[0];
+
+ IClass cls = ob as IClass;
+ if (cls != null) {
+ return new ReturnType (cls.FullyQualifiedName,
new int[] { 0 }, 0);
}
return null;
@@ -232,12 +239,12 @@
public override object Visit(ObjectCreateExpression
objectCreateExpression, object data)
{
- return null;
+ return resolver.SearchType
(objectCreateExpression.CreateType.SystemType, resolver.CompilationUnit);
}
public override object Visit(ArrayCreateExpression
arrayCreateExpression, object data)
{
- return null;
+ return resolver.SearchType
(arrayCreateExpression.CreateType.SystemType, resolver.CompilationUnit);
}
public override object Visit(DirectionExpression
directionExpression, object data)
Modified: trunk/monodevelop/Extras/CSharpBinding/Parser/Resolver.cs
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/Parser/Resolver.cs 2006-07-12
17:37:42 UTC (rev 62519)
+++ trunk/monodevelop/Extras/CSharpBinding/Parser/Resolver.cs 2006-07-12
17:41:06 UTC (rev 62520)
@@ -23,7 +23,8 @@
class Resolver
{
IParserContext parserContext;
- ICompilationUnit cu;
+ ICompilationUnit currentUnit;
+ string currentFile;
IClass callingClass;
LookupTableVisitor lookupTableVisitor;
@@ -40,7 +41,7 @@
public ICompilationUnit CompilationUnit {
get {
- return cu;
+ return currentUnit;
}
}
@@ -125,8 +126,10 @@
TypeVisitor typeVisitor = new TypeVisitor(this);
CSharpVisitor cSharpVisitor = new CSharpVisitor();
- cu =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
- if (cu != null) {
+ currentUnit =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
+ currentFile = fileName;
+
+ if (currentUnit != null) {
callingClass = GetInnermostClass();
// Console.WriteLine("CallingClass is " +
callingClass == null ? "null" : callingClass.Name);
}
@@ -144,8 +147,8 @@
fileCompilationUnit = parserContext.ParseFile
(fileName, fileContent).MostRecentCompilationUnit.Tag
as
ICSharpCode.NRefactory.Parser.AST.CompilationUnit;
lookupTableVisitor.Visit(fileCompilationUnit,null);
- cu =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
- if (cu != null) {
+ currentUnit =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
+ if (currentUnit != null) {
callingClass = GetInnermostClass();
}
type=expr.AcceptVisitor(typeVisitor,null) as
IReturnType;
@@ -161,7 +164,8 @@
public IClass ResolveExpressionType
(ICSharpCode.NRefactory.Parser.AST.CompilationUnit fileCompilationUnit,
Expression expr, int line, int col)
{
CSharpVisitor cSharpVisitor = new CSharpVisitor();
- cu =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
+ currentUnit =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
+ currentFile = null;
this.caretLine = line;
this.caretColumn = col;
@@ -173,7 +177,7 @@
TypeVisitor typeVisitor = new TypeVisitor (this);
IReturnType type = expr.AcceptVisitor (typeVisitor,
null) as IReturnType;
if (type != null)
- return SearchType (type.FullyQualifiedName, cu);
+ return SearchType (type.FullyQualifiedName,
currentUnit);
else
return null;
}
@@ -182,6 +186,7 @@
{
IParseInformation parseInfo =
parserContext.GetParseInformation (fileName);
ICSharpCode.NRefactory.Parser.AST.CompilationUnit
fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as
ICSharpCode.NRefactory.Parser.AST.CompilationUnit;
+ currentFile = fileName;
return ResolveIdentifier (fileCompilationUnit, id,
line, col);
}
@@ -189,9 +194,11 @@
{
ICSharpCode.NRefactory.Parser.IParser p =
ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser
(SupportedLanguage.CSharp, new StringReader(id));
Expression expr = p.ParseExpression ();
+ if (expr == null)
+ return null;
CSharpVisitor cSharpVisitor = new CSharpVisitor();
- cu =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
+ currentUnit =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
this.caretLine = line;
this.caretColumn = col;
@@ -258,10 +265,10 @@
if (type == null)
return null;
- IClass returnClass = SearchType
(type.FullyQualifiedName, cu);
+ IClass returnClass = SearchType
(type.FullyQualifiedName, currentUnit);
if (returnClass == null) {
// Try if type is Namespace:
- string n =
SearchNamespace(type.FullyQualifiedName, cu);
+ string n =
SearchNamespace(type.FullyQualifiedName, currentUnit);
if (n == null) {
return null;
}
@@ -510,7 +517,7 @@
if (type == null || memberName == null || memberName ==
"")
return false;
- curType = SearchType (type.FullyQualifiedName, cu);
+ curType = SearchType (type.FullyQualifiedName,
currentUnit);
if (curType == null)
return false;
@@ -599,37 +606,22 @@
return between.Y < end.Y || between.X <= end.X;
}
- ReturnType SearchVariable(string name)
+ LocalVariable SearchVariable (string name)
{
-// Console.WriteLine("Searching Variable");
-//
-// Console.WriteLine("LookUpTable has {0} entries",
lookupTableVisitor.variables.Count);
-// Console.WriteLine("Listing Variables:");
-// IDictionaryEnumerator enumerator =
lookupTableVisitor.variables.GetEnumerator();
-// while (enumerator.MoveNext()) {
-// Console.WriteLine(enumerator.Key);
-// }
-// Console.WriteLine("end listing");
System.Collections.Generic.List<ICSharpCode.NRefactory.Parser.LocalLookupVariable>
variables;
if (!lookupTableVisitor.Variables.TryGetValue (name,
out variables) || variables.Count <= 0) {
-// Console.WriteLine(name + " not in LookUpTable");
return null;
}
- ReturnType found = null;
foreach (LocalLookupVariable v in variables) {
-// Console.WriteLine("Position: ({0}/{1})",
v.StartPos, v.EndPos);
if (IsInside(new Point(caretColumn, caretLine),
v.StartPos, v.EndPos)) {
- found = new ReturnType(v.TypeRef);
-// Console.WriteLine("Variable found");
- break;
+ IClass c = SearchType
(v.TypeRef.SystemType, CompilationUnit);
+ DefaultRegion reg = new DefaultRegion
(v.StartPos, v.EndPos);
+ reg.FileName = currentFile;
+ return new LocalVariable (name, new
ReturnType (v.TypeRef, c), "", reg);
}
}
- if (found == null) {
-// Console.WriteLine("No Variable found");
- return null;
- }
- return found;
+ return null;
}
/// <remarks>
@@ -638,9 +630,9 @@
public ILanguageItem IdentifierLookup (string id)
{
// try if it exists a variable named id
- ReturnType variable = SearchVariable (id);
+ LocalVariable variable = SearchVariable (id);
if (variable != null) {
- return new LocalVariable (id, variable, "");
+ return variable;
}
if (callingClass == null) {
@@ -702,10 +694,10 @@
// Console.WriteLine("name == " + typeName);
// try if it exists a variable named typeName
- ReturnType variable = SearchVariable(typeName);
+ LocalVariable variable = SearchVariable (typeName);
if (variable != null) {
showStatic = false;
- return variable;
+ return variable.ReturnType;
}
// Console.WriteLine("No Variable found");
@@ -854,9 +846,7 @@
// Console.WriteLine("Found!");
return c;
}
- Console.WriteLine("No FullName");
if (unit != null) {
- Console.WriteLine(unit.Usings.Count + "
Usings");
foreach (IUsing u in unit.Usings) {
if (u != null && (u.Region == null ||
u.Region.IsInside(caretLine, caretColumn))) {
// Console.WriteLine("In
UsingRegion");
@@ -915,8 +905,8 @@
/// </remarks>
IClass GetInnermostClass()
{
- if (cu != null) {
- foreach (IClass c in cu.Classes) {
+ if (currentUnit != null) {
+ foreach (IClass c in currentUnit.Classes) {
if (c != null && ((c.Region != null &&
c.Region.IsInside(caretLine, caretColumn)) ||
(c.BodyRegion !=
null && c.BodyRegion.IsInside(caretLine, caretColumn))))
{
@@ -952,8 +942,8 @@
ClassCollection GetOuterClasses()
{
ClassCollection classes = new ClassCollection();
- if (cu != null) {
- foreach (IClass c in cu.Classes) {
+ if (currentUnit != null) {
+ foreach (IClass c in currentUnit.Classes) {
if (c != null && c.Region != null &&
c.BodyRegion.IsInside(caretLine, caretColumn)) {
if (c != GetInnermostClass()) {
GetOuterClasses(classes, c);
@@ -1009,8 +999,9 @@
TypeVisitor typeVisitor = new TypeVisitor (this);
CSharpVisitor csharpVisitor = new CSharpVisitor ();
- cu = (ICompilationUnit)csharpVisitor.Visit (fcu, null);
- if (cu != null) {
+ currentUnit = (ICompilationUnit)csharpVisitor.Visit
(fcu, null);
+ currentFile = fileName;
+ if (currentUnit != null) {
callingClass = GetInnermostClass ();
}
@@ -1018,9 +1009,9 @@
if (type == null || type.PointerNestingLevel != 0) {
fcu = parserContext.ParseFile (fileName,
fileContent).MostRecentCompilationUnit.Tag as
ICSharpCode.NRefactory.Parser.AST.CompilationUnit;
lookupTableVisitor.Visit (fcu, null);
- cu = (ICompilationUnit)csharpVisitor.Visit
(fcu, null);
+ currentUnit =
(ICompilationUnit)csharpVisitor.Visit (fcu, null);
- if (cu != null) {
+ if (currentUnit != null) {
callingClass = GetInnermostClass ();
}
type = expr.AcceptVisitor (typeVisitor, null)
as IReturnType;
@@ -1030,8 +1021,8 @@
if (type.ArrayDimensions != null &&
type.ArrayDimensions.Length > 0)
type = new ReturnType ("System.Array");
- IClass returnClass = SearchType
(type.FullyQualifiedName, cu);
-// IClass returnClass = parserContext.SearchType
(type.FullyQualifiedName, null, cu);
+ IClass returnClass = SearchType
(type.FullyQualifiedName, currentUnit);
+// IClass returnClass = parserContext.SearchType
(type.FullyQualifiedName, null, currentUnit);
if (returnClass == null)
return null;
@@ -1059,8 +1050,9 @@
lookupTableVisitor = new
LookupTableVisitor(StringComparer.InvariantCulture);
lookupTableVisitor.Visit(fileCompilationUnit, null);
CSharpVisitor cSharpVisitor = new CSharpVisitor();
- cu =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
- if (cu != null) {
+ currentUnit =
(ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
+ currentFile = fileName;
+ if (currentUnit != null) {
callingClass = GetInnermostClass();
Console.WriteLine("CallingClass is " +
(callingClass == null ? "null" : callingClass.Name));
}
@@ -1080,7 +1072,7 @@
}
string n = "";
result.AddRange(parserContext.GetNamespaceContents (n,
true));
- foreach (IUsing u in cu.Usings) {
+ foreach (IUsing u in currentUnit.Usings) {
if (u != null && (u.Region == null ||
u.Region.IsInside(caretLine, caretColumn))) {
foreach (string name in u.Usings) {
result.AddRange(parserContext.GetNamespaceContents (name, true));
Modified:
trunk/monodevelop/Extras/CSharpBinding/Parser/SharpDevelopTree/ReturnType.cs
===================================================================
---
trunk/monodevelop/Extras/CSharpBinding/Parser/SharpDevelopTree/ReturnType.cs
2006-07-12 17:37:42 UTC (rev 62519)
+++
trunk/monodevelop/Extras/CSharpBinding/Parser/SharpDevelopTree/ReturnType.cs
2006-07-12 17:41:06 UTC (rev 62520)
@@ -36,9 +36,13 @@
this.pointerNestingLevel = pointerNestingLevel;
}
- public
ReturnType(ICSharpCode.NRefactory.Parser.AST.TypeReference type)
+ public ReturnType
(ICSharpCode.NRefactory.Parser.AST.TypeReference type): this (type, null)
{
- base.FullyQualifiedName = type.SystemType;
+ }
+
+ public ReturnType
(ICSharpCode.NRefactory.Parser.AST.TypeReference type, IClass resolvedClass)
+ {
+ base.FullyQualifiedName = resolvedClass != null ?
resolvedClass.FullyQualifiedName : type.SystemType;
base.arrayDimensions = type.RankSpecifier == null ?
new int[] { } : type.RankSpecifier;
base.pointerNestingLevel = type.PointerNestingLevel;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches