Browse Source

Fixed code completion bugs regarding "global::"/"Global".

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@240 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
80c70338c7
  1. 6
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs
  2. 1
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 10
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  4. 16
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  5. 25
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expressions/GlobalReferenceExpression.cs
  6. 4
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/GlobalScope/TypeDeclaration.cs
  7. 20
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs
  8. 1835
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  9. 133
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  10. 1534
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  11. 53
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  12. 6
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs
  13. 1
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs
  14. 32
      src/Libraries/NRefactory/Test/Parser/Expressions/GlobalReferenceExpressionTests.cs
  15. 14
      src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs
  16. 4
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  17. 4
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs
  18. 41
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

6
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs

@ -509,6 +509,12 @@ namespace CSharpBinding.Parser
case '.': case '.':
curTokenType = Dot; curTokenType = Dot;
break; break;
case ':':
if (GetNext() == ':') {
// treat :: like dot
curTokenType = Dot;
}
break;
case '\'': case '\'':
case '"': case '"':
if (ReadStringLiteral(ch)) { if (ReadStringLiteral(ch)) {

1
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -188,7 +188,6 @@
<Compile Include="Src\Parser\Visitors\CSharpToVBNetConvertVisitor.cs" /> <Compile Include="Src\Parser\Visitors\CSharpToVBNetConvertVisitor.cs" />
<Compile Include="Src\Parser\Visitors\PrefixFieldsVisitor.cs" /> <Compile Include="Src\Parser\Visitors\PrefixFieldsVisitor.cs" />
<Compile Include="Src\Parser\Visitors\VBNetToCSharpConvertVisitor.cs" /> <Compile Include="Src\Parser\Visitors\VBNetToCSharpConvertVisitor.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\GlobalReferenceExpression.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" /> <Content Include="Src\Lexer\CSharp\KeywordList.txt" />

10
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -123,6 +123,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(TypeReference typeReference, object data) public object Visit(TypeReference typeReference, object data)
{ {
if (typeReference.IsGlobal) {
outputFormatter.PrintText("global::");
}
if (typeReference.Type == null || typeReference.Type.Length ==0) { if (typeReference.Type == null || typeReference.Type.Length ==0) {
outputFormatter.PrintText("void"); outputFormatter.PrintText("void");
} else { } else {
@ -342,7 +345,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (i > 0) { if (i > 0) {
PrintFormattedComma(); PrintFormattedComma();
} }
outputFormatter.PrintIdentifier((string)typeDeclaration.BaseTypes[i]); nodeTracker.TrackedVisit(typeDeclaration.BaseTypes[i], data);
} }
} }
@ -2073,11 +2076,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null; return null;
} }
public object Visit(GlobalReferenceExpression globalReferenceExpression, object data) {
outputFormatter.PrintText("global::");
return null;
}
public object Visit(ObjectCreateExpression objectCreateExpression, object data) public object Visit(ObjectCreateExpression objectCreateExpression, object data)
{ {
outputFormatter.PrintToken(Tokens.New); outputFormatter.PrintToken(Tokens.New);

16
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -125,6 +125,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(TypeReference typeReference, object data) public object Visit(TypeReference typeReference, object data)
{ {
if (typeReference.IsGlobal) {
outputFormatter.PrintToken(Tokens.Global);
outputFormatter.PrintToken(Tokens.Dot);
}
if (typeReference.Type == null || typeReference.Type.Length ==0) { if (typeReference.Type == null || typeReference.Type.Length ==0) {
outputFormatter.PrintText("Void"); outputFormatter.PrintText("Void");
} else { } else {
@ -309,9 +313,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.NewLine(); outputFormatter.NewLine();
if (typeDeclaration.BaseTypes != null) { if (typeDeclaration.BaseTypes != null) {
foreach (string baseType in typeDeclaration.BaseTypes) { foreach (TypeReference baseTypeRef in typeDeclaration.BaseTypes) {
outputFormatter.Indent(); outputFormatter.Indent();
string baseType = baseTypeRef.Type;
bool baseTypeIsInterface = baseType.StartsWith("I") && (baseType.Length <= 1 || Char.IsUpper(baseType[1])); bool baseTypeIsInterface = baseType.StartsWith("I") && (baseType.Length <= 1 || Char.IsUpper(baseType[1]));
if (!baseTypeIsInterface || typeDeclaration.Type == Types.Interface) { if (!baseTypeIsInterface || typeDeclaration.Type == Types.Interface) {
@ -320,7 +325,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Implements); outputFormatter.PrintToken(Tokens.Implements);
} }
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintIdentifier(baseType); nodeTracker.TrackedVisit(baseTypeRef, data);
outputFormatter.NewLine(); outputFormatter.NewLine();
} }
} }
@ -2126,13 +2131,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null; return null;
} }
public object Visit(GlobalReferenceExpression globalReferenceExpression, object data)
{
outputFormatter.PrintToken(Tokens.Global);
outputFormatter.PrintToken(Tokens.Dot);
return null;
}
public object Visit(ObjectCreateExpression objectCreateExpression, object data) public object Visit(ObjectCreateExpression objectCreateExpression, object data)
{ {
outputFormatter.PrintToken(Tokens.New); outputFormatter.PrintToken(Tokens.New);

25
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expressions/GlobalReferenceExpression.cs

@ -1,25 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
namespace ICSharpCode.NRefactory.Parser.AST
{
public class GlobalReferenceExpression : Expression
{
public override object AcceptVisitor(IASTVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
public override string ToString()
{
return String.Format("[GlobalReferenceExpression]");
}
}
}

4
src/Libraries/NRefactory/Project/Src/Parser/AST/General/GlobalScope/TypeDeclaration.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
// Children of Enum: FieldDeclaration // Children of Enum: FieldDeclaration
string name = ""; string name = "";
Types type = Types.Class; // Class | Interface | Struct | Enum Types type = Types.Class; // Class | Interface | Struct | Enum
ArrayList bases = new ArrayList(); // TODO: can be generics too! List<TypeReference> bases = new List<TypeReference>();
List<TemplateDefinition> templates = new List<TemplateDefinition>(); List<TemplateDefinition> templates = new List<TemplateDefinition>();
public string Name { public string Name {
@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
} }
} }
public ArrayList BaseTypes { public List<TypeReference> BaseTypes {
get { get {
return bases; return bases;
} }

20
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs

@ -20,6 +20,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
int pointerNestingLevel = 0; int pointerNestingLevel = 0;
int[] rankSpecifier = null; int[] rankSpecifier = null;
List<TypeReference> genericTypes = new List<TypeReference>(1); List<TypeReference> genericTypes = new List<TypeReference>(1);
bool isGlobal = false;
static Dictionary<string, string> types = new Dictionary<string, string>(); static Dictionary<string, string> types = new Dictionary<string, string>();
static Dictionary<string, string> vbtypes = new Dictionary<string, string>(); static Dictionary<string, string> vbtypes = new Dictionary<string, string>();
@ -131,6 +132,18 @@ namespace ICSharpCode.NRefactory.Parser.AST
} }
} }
/// <summary>
/// Gets/Sets if the type reference had a "global::" prefix.
/// </summary>
public bool IsGlobal {
get {
return isGlobal;
}
set {
isGlobal = value;
}
}
public static TypeReference CheckNull(TypeReference typeReference) public static TypeReference CheckNull(TypeReference typeReference)
{ {
return typeReference == null ? NullTypeReference.Instance : typeReference; return typeReference == null ? NullTypeReference.Instance : typeReference;
@ -161,6 +174,13 @@ namespace ICSharpCode.NRefactory.Parser.AST
this.systemType = systemType; this.systemType = systemType;
} }
public TypeReference(string type, List<TypeReference> genericTypes) : this(type)
{
if (genericTypes != null) {
this.genericTypes = genericTypes;
}
}
public TypeReference(string type, int[] rankSpecifier) : this(type, 0, rankSpecifier) public TypeReference(string type, int[] rankSpecifier) : this(type, 0, rankSpecifier)
{ {
} }

1835
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

133
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -125,7 +125,7 @@ bool IsQualident(ref Token pt, out string qualident)
if (pt.kind == Tokens.Identifier) { if (pt.kind == Tokens.Identifier) {
qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val); qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val);
pt = Peek(); pt = Peek();
while (pt.kind == Tokens.Dot) { while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) {
pt = Peek(); pt = Peek();
if (pt.kind != Tokens.Identifier) { if (pt.kind != Tokens.Identifier) {
qualident = String.Empty; qualident = String.Empty;
@ -703,7 +703,7 @@ NamespaceMemberDecl
TypeDecl<Modifiers m, List<AttributeSection> attributes> TypeDecl<Modifiers m, List<AttributeSection> attributes>
(. (.
TypeReference type; TypeReference type;
ArrayList names; List<TypeReference> names;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>(); List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
string name; string name;
List<TemplateDefinition> templates; List<TemplateDefinition> templates;
@ -780,9 +780,7 @@ TypeDecl<Modifiers m, List<AttributeSection> attributes>
newType.Type = Types.Enum; newType.Type = Types.Enum;
.) .)
ident (. newType.Name = t.val; .) ident (. newType.Name = t.val; .)
[ ":" IntegralType<out name> (. newType.BaseTypes = new ArrayList(); [ ":" IntegralType<out name> (. newType.BaseTypes.Add(new TypeReference(name)); .)
newType.BaseTypes.Add(name);
.)
] (. newType.StartLocation = t.EndLocation; .) ] (. newType.StartLocation = t.EndLocation; .)
EnumBody EnumBody
[ ";" ] (. newType.EndLocation = t.Location; [ ";" ] (. newType.EndLocation = t.Location;
@ -822,15 +820,14 @@ Qualident<out string qualident>
} (. qualident = qualidentBuilder.ToString(); .) } (. qualident = qualidentBuilder.ToString(); .)
. .
ClassBase<out ArrayList names> ClassBase<out List<TypeReference> names>
(. (.
string qualident; TypeReference typeRef;
names = new ArrayList(); names = new List<TypeReference>();
List<TypeReference> types;
.) .)
= =
":" ClassType<out qualident, out types> (. names.Add(qualident); // TODO: enter the types .) ":" ClassType<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .)
{ "," Qualident<out qualident> (. names.Add(qualident); .) } { "," TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) }
. .
ClassBody ClassBody
@ -847,14 +844,14 @@ ClassBody
"}" "}"
. .
StructInterfaces<out ArrayList names> StructInterfaces<out List<TypeReference> names>
(. (.
string qualident; TypeReference typeRef;
names = new ArrayList(); names = new List<TypeReference>();
.) .)
= =
":" Qualident<out qualident> (. names.Add(qualident); .) ":" TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .)
{ "," Qualident<out qualident> (. names.Add(qualident); .) } { "," TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) }
. .
StructBody StructBody
@ -871,14 +868,14 @@ StructBody
"}" "}"
. .
InterfaceBase<out ArrayList names> InterfaceBase<out List<TypeReference> names>
(. (.
string qualident; TypeReference typeRef;
names = new ArrayList(); names = new List<TypeReference>();
.) .)
= =
":" Qualident<out qualident> (. names.Add(qualident); .) ":" TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .)
{ "," Qualident<out qualident> (. names.Add(qualident); .) } { "," TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) }
. .
InterfaceBody InterfaceBody
@ -894,43 +891,42 @@ EnumBody (. FieldDeclaration f; .)
Type<out TypeReference type> Type<out TypeReference type>
(. (.
string name = ""; string name;
int pointer = 0; int pointer = 0;
List<TypeReference> types = null;
type = null; type = null;
.) .)
= =
( ClassType<out name, out types> ( ClassType<out type>
| SimpleType<out name> | SimpleType<out name> (. type = new TypeReference(name); .)
| "void" "*" (. pointer = 1; name = "void"; .) | "void" "*" (. pointer = 1; type = new TypeReference("void"); .)
) (. ArrayList r = new ArrayList(); .) ) (. List<int> r = new List<int>(); .)
{ IF (IsPointerOrDims()) (. int i = 0; .) { IF (IsPointerOrDims()) (. int i = 0; .)
( "*" (. ++pointer; .) ( "*" (. ++pointer; .)
| "[" { "," (. ++i; .) } "]" (. r.Add(i); .) | "[" { "," (. ++i; .) } "]" (. r.Add(i); .)
) )
} (. int[] rank = new int[r.Count]; r.CopyTo(rank); }
type = new TypeReference(name, pointer, rank, types); (. type.RankSpecifier = r.ToArray();
type.PointerNestingLevel = pointer;
.) .)
. .
NonArrayType<out TypeReference type> NonArrayType<out TypeReference type>
(. (.
string name = ""; string name;
int pointer = 0; int pointer = 0;
List<TypeReference> genericTypes = null; type = null;
.) .)
= =
( ClassType<out name, out genericTypes> ( ClassType<out type>
| SimpleType<out name> | SimpleType<out name> (. type = new TypeReference(name); .)
| "void" "*" (. pointer = 1; name = "void"; .) | "void" "*" (. pointer = 1; type = new TypeReference("void"); .)
) )
{ IF (IsPointer()) { IF (IsPointer())
"*" (. ++pointer; .) "*" (. ++pointer; .)
} (. }
type = new TypeReference(name, pointer, null, genericTypes); (. type.PointerNestingLevel = pointer; .)
.)
. .
SimpleType<out string name> SimpleType<out string name>
@ -1003,15 +999,12 @@ TypeModifier<Modifiers m>
| ident (. if (t.val == "partial") { m.Add(Modifier.Partial); } .) | ident (. if (t.val == "partial") { m.Add(Modifier.Partial); } .)
. .
ClassType<out string name, out List<TypeReference> types> ClassType<out TypeReference typeRef>
(. string qualident; name = ""; (. TypeReference r; typeRef = null; .)
List<TypeReference> t;
types = null;
.)
= =
TypeName<out qualident, out t> (. name = qualident; types = t; .) TypeName<out r> (. typeRef = r; .)
| "object" (. name = "object"; .) | "object" (. typeRef = new TypeReference("object"); .)
| "string" (. name = "string"; .) | "string" (. typeRef = new TypeReference("string"); .)
. .
IntegralType<out string name> (. name = ""; .) IntegralType<out string name> (. name = ""; .)
@ -1793,17 +1786,22 @@ CatchClauses<out ArrayList catchClauses>
catchClauses = new ArrayList(); catchClauses = new ArrayList();
.) .)
= =
"catch" (. string name; "catch" (. string identifier;
string identifier;
Statement stmt; Statement stmt;
List<TypeReference> types; TypeReference typeRef;
.) .)
/*--- general catch clause (as only catch clause) */ /*--- general catch clause (as only catch clause) */
( (
Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
/*--- specific catch clause */ /*--- specific catch clause */
| "(" ClassType<out name, out types> (. identifier = null; .) [ ident (. identifier = t.val; .) ] ")" Block<out stmt> (. catchClauses.Add(new CatchClause(new TypeReference(name, 0, null, types), identifier, stmt)); .) | "(" ClassType<out typeRef> (. identifier = null; .)
{ IF (IsTypedCatch()) "catch" "(" ClassType<out name, out types> (. identifier = null; .) [ ident (. identifier = t.val; .) ] ")" Block<out stmt> (. catchClauses.Add(new CatchClause(new TypeReference(name, 0, null, types), identifier, stmt)); .) } [ ident (. identifier = t.val; .) ]
")" Block<out stmt>
(. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .)
{ IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef> (. identifier = null; .)
[ ident (. identifier = t.val; .) ]
")" Block<out stmt>
(. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) }
/*--- general catch clause (after specific catch clauses, optional) */ /*--- general catch clause (after specific catch clauses, optional) */
[ "catch" Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) ] [ "catch" Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) ]
) )
@ -1929,6 +1927,8 @@ PrimaryExpr<out Expression pexpr>
| "false" (.pexpr = new PrimitiveExpression(false, "false"); .) | "false" (.pexpr = new PrimitiveExpression(false, "false"); .)
| "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */ | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */
| Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .) | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon)
TypeName<out type> (. pexpr = new TypeReferenceExpression(type); .)
/*--- simple name: */ /*--- simple name: */
| ident (. pexpr = new IdentifierExpression(t.val); .) | ident (. pexpr = new IdentifierExpression(t.val); .)
/*--- parenthesized expression: */ /*--- parenthesized expression: */
@ -2021,6 +2021,16 @@ PrimaryExpr<out Expression pexpr>
/*--- member access */ /*--- member access */
| "->" ident (. pexpr = new PointerReferenceExpression(pexpr, t.val); .) | "->" ident (. pexpr = new PointerReferenceExpression(pexpr, t.val); .)
| "." ident (. pexpr = new FieldReferenceExpression(pexpr, t.val);.) | "." ident (. pexpr = new FieldReferenceExpression(pexpr, t.val);.)
/*| "::" ident (.
if (pexpr is IdentifierExpression) {
if (((IdentifierExpression)pexpr).Identifier == "global") {
pexpr = new GlobalReferenceExpression();
}
} else {
Error("expression before :: must be an identifier");
}
pexpr = new FieldReferenceExpression(pexpr, t.val);
.) */
/* member access on generic type */ /* member access on generic type */
| ( IF (IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr)) | ( IF (IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr))
TypeArgumentList<out typeList> ) TypeArgumentList<out typeList> )
@ -2191,11 +2201,28 @@ MultiplicativeExpr<ref Expression outExpr>
/* .NET 2.0 rules */ /* .NET 2.0 rules */
TypeName<out string qualident, out List<TypeReference> types> TypeName<out TypeReference typeRef>
(. List<TypeReference> t; types = new List<TypeReference>(); .) (. List<TypeReference> typeArguments = null;
string alias = null;
string qualident;
.)
= =
[ IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon)
ident (. alias = t.val; .)
"::"
]
Qualident<out qualident> Qualident<out qualident>
[ TypeArgumentList<out t> (. types = t; .)] [ TypeArgumentList<out typeArguments> ]
(.
if (alias == null) {
typeRef = new TypeReference(qualident, typeArguments);
} else if (alias == "global") {
typeRef = new TypeReference(qualident, typeArguments);
typeRef.IsGlobal = true;
} else {
typeRef = new TypeReference(alias + "." + qualident, typeArguments);
}
.)
. .
TypeArgumentList<out List<TypeReference> types> TypeArgumentList<out List<TypeReference> types>

1534
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

53
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -588,8 +588,9 @@ TypeParameterConstraints<TemplateDefinition template>
/* 6.4.2 */ /* 6.4.2 */
NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
(. (.
string name = String.Empty; string name = null;
ArrayList names = null; TypeReference typeRef = null;
List<TypeReference> baseInterfaces = null;
.) = .) =
(. m.Check(Modifier.Classes); .) (. m.Check(Modifier.Classes); .)
/* Spec, 7.5 */ /* Spec, 7.5 */
@ -605,8 +606,8 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .) Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .)
TypeParameterList<newType.Templates> TypeParameterList<newType.Templates>
EndOfStmt EndOfStmt
[ ClassBaseType<out name> (. newType.BaseTypes.Add(name); .) ] [ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
{ TypeImplementsClause<out names> (. newType.BaseTypes.AddRange(names); .) } { TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
ClassBody<newType> ClassBody<newType>
(. (.
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
@ -634,7 +635,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(newType); compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType); compilationUnit.BlockStart(newType);
newType.StartLocation = t.Location; newType.StartLocation = t.Location;
newType.Type = Types.Struct; ArrayList baseInterfaces = new ArrayList(); newType.Type = Types.Struct;
.) .)
Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .) Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .)
TypeParameterList<newType.Templates> TypeParameterList<newType.Templates>
@ -656,7 +657,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
newType.Type = Types.Enum; newType.Type = Types.Enum;
.) .)
Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .) Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .)
[ "As" PrimitiveTypeName<out name> (. newType.BaseTypes.Add(name); .) ] [ "As" PrimitiveTypeName<out name> (. newType.BaseTypes.Add(new TypeReference(name)); .) ]
EOL EOL
EnumBody<newType> EnumBody<newType>
(. (.
@ -670,11 +671,11 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
compilationUnit.AddChild(newType); compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType); compilationUnit.BlockStart(newType);
newType.Type = Types.Interface;ArrayList baseInterfaces; newType.Type = Types.Interface;
.) .)
Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .) Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .)
TypeParameterList<newType.Templates> TypeParameterList<newType.Templates>
EndOfStmt { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces.ToArray()); .) } EndOfStmt { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
InterfaceBody<newType> InterfaceBody<newType>
(. (.
newType.EndLocation = t.Location; newType.EndLocation = t.Location;
@ -879,15 +880,14 @@ ClassMemberDecl<Modifiers m, List<AttributeSection> attributes> =
StructureMemberDecl<m, attributes> StructureMemberDecl<m, attributes>
. .
ClassBaseType<out string name> ClassBaseType<out TypeReference typeRef>
(. (.
TypeReference type; typeRef = null;
name = String.Empty; .) =
.) =
"Inherits" "Inherits"
TypeName<out type> (. name = type.Type; .) TypeName<out typeRef>
EndOfStmt EndOfStmt
. .
/* 7.6.1 */ /* 7.6.1 */
StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
@ -1368,33 +1368,33 @@ HandlesClause<out ArrayList handlesClause>
. .
/* 7.8. */ /* 7.8. */
InterfaceBase <out ArrayList bases> InterfaceBase <out List<TypeReference> bases>
(. (.
TypeReference type; TypeReference type;
bases = new ArrayList(); bases = new List<TypeReference>();
.) = .) =
"Inherits" "Inherits"
TypeName<out type> (. bases.Add(type.Type); .) TypeName<out type> (. bases.Add(type); .)
{ {
"," ","
TypeName<out type> (. bases.Add(type.Type); .) TypeName<out type> (. bases.Add(type); .)
} }
EOL EOL
. .
/* 7.2 */ /* 7.2 */
TypeImplementsClause<out ArrayList baseInterfaces> TypeImplementsClause<out List<TypeReference> baseInterfaces>
(. (.
baseInterfaces = new ArrayList(); baseInterfaces = new List<TypeReference>();
TypeReference type = null; TypeReference type = null;
.) = .) =
"Implements" TypeName<out type> "Implements" TypeName<out type>
(. (.
baseInterfaces.Add(type.Type); baseInterfaces.Add(type);
.) .)
{ {
"," TypeName<out type> "," TypeName<out type>
(. baseInterfaces.Add(type.Type); .) (. baseInterfaces.Add(type); .)
} }
EndOfStmt EndOfStmt
. .
@ -1496,9 +1496,9 @@ SimpleExpr<out Expression pexpr>
| (. Expression retExpr = null; .) | (. Expression retExpr = null; .)
( "MyBase" (. retExpr = new BaseReferenceExpression(); .) ( "MyBase" (. retExpr = new BaseReferenceExpression(); .)
| "MyClass" (. retExpr = new ClassReferenceExpression(); .) | "MyClass" (. retExpr = new ClassReferenceExpression(); .)
| "Global" (. retExpr = new GlobalReferenceExpression(); .)
) )
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(retExpr, name); .) "." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(retExpr, name); .)
| IF (la.kind == Tokens.Global) TypeName<out type> (. pexpr = new TypeReferenceExpression(type); .)
| ObjectCreateExpression<out expr> (. pexpr = expr; .) | ObjectCreateExpression<out expr> (. pexpr = expr; .)
| /* 11.11 */ ( "DirectCast" | "CType" ) "(" Expr<out expr> "," TypeName<out type> ")" (. pexpr = new CastExpression(type, expr); .) | /* 11.11 */ ( "DirectCast" | "CType" ) "(" Expr<out expr> "," TypeName<out type> ")" (. pexpr = new CastExpression(type, expr); .)
| /* 11.11 */ "TryCast" "(" Expr<out expr> "," TypeName<out type> ")" (. pexpr = new BinaryOperatorExpression(expr, BinaryOperatorType.AsCast, new TypeReferenceExpression(type)); .) | /* 11.11 */ "TryCast" "(" Expr<out expr> "," TypeName<out type> ")" (. pexpr = new BinaryOperatorExpression(expr, BinaryOperatorType.AsCast, new TypeReferenceExpression(type)); .)
@ -1753,6 +1753,11 @@ NonArrayTypeName<out TypeReference typeref>
"(" "Of" TypeArgumentList<typeref.GenericTypes> ")" "(" "Of" TypeArgumentList<typeref.GenericTypes> ")"
] ]
| "Object" (. typeref = new TypeReference("System.Object"); .) | "Object" (. typeref = new TypeReference("System.Object"); .)
| "Global" "." Qualident<out name>
(. typeref = new TypeReference(name); typeref.IsGlobal = true; .)
[IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeArgumentList<typeref.GenericTypes> ")"
]
| PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .) | PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .)
. .

6
src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs

@ -973,12 +973,6 @@ namespace ICSharpCode.NRefactory.Parser
return data; return data;
} }
public virtual object Visit(GlobalReferenceExpression globalReferenceExpression, object data)
{
Debug.Assert(globalReferenceExpression != null);
return data;
}
public virtual object Visit(ObjectCreateExpression objectCreateExpression, object data) public virtual object Visit(ObjectCreateExpression objectCreateExpression, object data)
{ {
Debug.Assert(objectCreateExpression != null); Debug.Assert(objectCreateExpression != null);

1
src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs

@ -117,7 +117,6 @@ namespace ICSharpCode.NRefactory.Parser
object Visit(IndexerExpression indexerExpression, object data); object Visit(IndexerExpression indexerExpression, object data);
object Visit(ThisReferenceExpression thisReferenceExpression, object data); object Visit(ThisReferenceExpression thisReferenceExpression, object data);
object Visit(BaseReferenceExpression baseReferenceExpression, object data); object Visit(BaseReferenceExpression baseReferenceExpression, object data);
object Visit(GlobalReferenceExpression globalReferenceExpression, object data);
object Visit(ObjectCreateExpression objectCreateExpression, object data); object Visit(ObjectCreateExpression objectCreateExpression, object data);
object Visit(ArrayCreateExpression arrayCreateExpression, object data); object Visit(ArrayCreateExpression arrayCreateExpression, object data);
object Visit(FieldReferenceExpression fieldReferenceExpression, object data); object Visit(FieldReferenceExpression fieldReferenceExpression, object data);

32
src/Libraries/NRefactory/Test/Parser/Expressions/GlobalReferenceExpressionTests.cs

@ -16,22 +16,38 @@ namespace ICSharpCode.NRefactory.Tests.AST
[TestFixture] [TestFixture]
public class GlobalReferenceExpressionTests public class GlobalReferenceExpressionTests
{ {
#region C#
[Test] [Test]
public void CSharpGlobalReferenceExpressionTest() public void CSharpGlobalReferenceExpressionTest()
{ {
FieldReferenceExpression fre = (FieldReferenceExpression)ParseUtilCSharp.ParseExpression("global::System", typeof(FieldReferenceExpression)); TypeReferenceExpression tre = (TypeReferenceExpression)ParseUtilCSharp.ParseExpression("global::System", typeof(TypeReferenceExpression));
Assert.IsTrue(fre.TargetObject is GlobalReferenceExpression); Assert.IsTrue(tre.TypeReference.IsGlobal);
Assert.AreEqual("System", tre.TypeReference.Type);
} }
#endregion
#region VB.NET
[Test] [Test]
public void VBNetGlobalReferenceExpressionTest() public void VBNetGlobalReferenceExpressionTest()
{ {
FieldReferenceExpression fre = (FieldReferenceExpression)ParseUtilVBNet.ParseExpression("Global.System", typeof(FieldReferenceExpression)); TypeReferenceExpression tre = (TypeReferenceExpression)ParseUtilVBNet.ParseExpression("Global.System", typeof(TypeReferenceExpression));
Assert.IsTrue(fre.TargetObject is GlobalReferenceExpression); Assert.IsTrue(tre.TypeReference.IsGlobal);
Assert.AreEqual("System", tre.TypeReference.Type);
}
[Test]
public void CSharpGlobalTypeDeclaration()
{
LocalVariableDeclaration lvd = (LocalVariableDeclaration)ParseUtilCSharp.ParseStatment("global::System.String a;", typeof(LocalVariableDeclaration));
TypeReference typeRef = lvd.GetTypeForVariable(0);
Assert.IsTrue(typeRef.IsGlobal);
Assert.AreEqual("System.String", typeRef.Type);
}
[Test]
public void VBNetGlobalTypeDeclaration()
{
LocalVariableDeclaration lvd = (LocalVariableDeclaration)ParseUtilVBNet.ParseStatment("Dim a As Global.System.String", typeof(LocalVariableDeclaration));
TypeReference typeRef = lvd.GetTypeForVariable(0);
Assert.IsTrue(typeRef.IsGlobal);
Assert.AreEqual("System.String", typeRef.Type);
} }
#endregion
} }
} }

14
src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual(Types.Class, td.Type); Assert.AreEqual(Types.Class, td.Type);
Assert.AreEqual("MyClass", td.Name); Assert.AreEqual("MyClass", td.Name);
Assert.AreEqual("My.Base.Class", td.BaseTypes[0]); Assert.AreEqual("My.Base.Class", td.BaseTypes[0].Type);
Assert.AreEqual(Modifier.None, td.Modifier); Assert.AreEqual(Modifier.None, td.Modifier);
} }
@ -97,7 +97,7 @@ public class Generic<T, S> : System.IComparable where S : G<T[]> where T : MyNa
Assert.AreEqual("Generic", td.Name); Assert.AreEqual("Generic", td.Name);
Assert.AreEqual(Modifier.Public, td.Modifier); Assert.AreEqual(Modifier.Public, td.Modifier);
Assert.AreEqual(1, td.BaseTypes.Count); Assert.AreEqual(1, td.BaseTypes.Count);
Assert.AreEqual("System.IComparable", td.BaseTypes[0]); Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type);
Assert.AreEqual(2, td.Templates.Count); Assert.AreEqual(2, td.Templates.Count);
Assert.AreEqual("T", td.Templates[0].Name); Assert.AreEqual("T", td.Templates[0].Name);
@ -127,9 +127,9 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(Modifier.Public | Modifier.Abstract, td.Modifier); Assert.AreEqual(Modifier.Public | Modifier.Abstract, td.Modifier);
Assert.AreEqual(1, td.Attributes.Count); Assert.AreEqual(1, td.Attributes.Count);
Assert.AreEqual(3, td.BaseTypes.Count); Assert.AreEqual(3, td.BaseTypes.Count);
Assert.AreEqual("MyBase", td.BaseTypes[0]); Assert.AreEqual("MyBase", td.BaseTypes[0].Type);
Assert.AreEqual("Interface1", td.BaseTypes[1]); Assert.AreEqual("Interface1", td.BaseTypes[1].Type);
Assert.AreEqual("My.Test.Interface2", td.BaseTypes[2]); Assert.AreEqual("My.Test.Interface2", td.BaseTypes[2].Type);
} }
[Test] [Test]
@ -183,7 +183,7 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestEnum", td.Name); Assert.AreEqual("TestEnum", td.Name);
Assert.AreEqual(Types.Enum, td.Type); Assert.AreEqual(Types.Enum, td.Type);
Assert.AreEqual("Byte", td.BaseTypes[0].ToString()); Assert.AreEqual("Byte", td.BaseTypes[0].Type);
} }
[Test] [Test]
@ -262,7 +262,7 @@ End Class
Assert.AreEqual("Generic", td.Name); Assert.AreEqual("Generic", td.Name);
Assert.AreEqual(Modifier.Public, td.Modifier); Assert.AreEqual(Modifier.Public, td.Modifier);
Assert.AreEqual(1, td.BaseTypes.Count); Assert.AreEqual(1, td.BaseTypes.Count);
Assert.AreEqual("System.IComparable", td.BaseTypes[0]); Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type);
Assert.AreEqual(2, td.Templates.Count); Assert.AreEqual(2, td.Templates.Count);
Assert.AreEqual("T", td.Templates[0].Name); Assert.AreEqual("T", td.Templates[0].Name);

4
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -281,8 +281,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
cu.Classes.Add(c); cu.Classes.Add(c);
} }
if (typeDeclaration.BaseTypes != null) { if (typeDeclaration.BaseTypes != null) {
foreach (string type in typeDeclaration.BaseTypes) { foreach (AST.TypeReference type in typeDeclaration.BaseTypes) {
c.BaseTypes.Add(type); c.BaseTypes.Add(type.SystemType);
} }
} }
currentClass.Push(c); currentClass.Push(c);

4
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

@ -285,10 +285,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} else if (expr is TypeReferenceExpression) { } else if (expr is TypeReferenceExpression) {
type = TypeVisitor.CreateReturnType(((TypeReferenceExpression)expr).TypeReference, this); type = TypeVisitor.CreateReturnType(((TypeReferenceExpression)expr).TypeReference, this);
if (type != null) { if (type != null) {
if (type is TypeVisitor.NamespaceReturnType)
return new NamespaceResolveResult(callingClass, callingMember, type.FullyQualifiedName);
IClass c = type.GetUnderlyingClass(); IClass c = type.GetUnderlyingClass();
if (c != null) if (c != null)
return new TypeResolveResult(callingClass, callingMember, type, c); return new TypeResolveResult(callingClass, callingMember, type, c);
} }
return null;
} }
type = expr.AcceptVisitor(typeVisitor, null) as IReturnType; type = expr.AcceptVisitor(typeVisitor, null) as IReturnType;
@ -846,6 +849,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
result.Add(GetPrimitiveClass(pair.Value, primitive)); result.Add(GetPrimitiveClass(pair.Value, primitive));
} }
} }
result.Add("Global");
} else { } else {
foreach (KeyValuePair<string, string> pair in TypeReference.GetPrimitiveTypesCSharp()) { foreach (KeyValuePair<string, string> pair in TypeReference.GetPrimitiveTypesCSharp()) {
result.Add(GetPrimitiveClass(pair.Value, pair.Key)); result.Add(GetPrimitiveClass(pair.Value, pair.Key));

41
src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

@ -299,6 +299,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public override object Visit(TypeReferenceExpression typeReferenceExpression, object data) public override object Visit(TypeReferenceExpression typeReferenceExpression, object data)
{ {
System.Diagnostics.Debugger.Break();
return CreateReturnType(typeReferenceExpression.TypeReference); return CreateReturnType(typeReferenceExpression.TypeReference);
} }
@ -416,11 +417,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return baseClass.DefaultReturnType; return baseClass.DefaultReturnType;
} }
public override object Visit(GlobalReferenceExpression globalReferenceExpression, object data)
{
return new NamespaceReturnType("");
}
public override object Visit(ObjectCreateExpression objectCreateExpression, object data) public override object Visit(ObjectCreateExpression objectCreateExpression, object data)
{ {
return CreateReturnType(objectCreateExpression.CreateType); return CreateReturnType(objectCreateExpression.CreateType);
@ -479,18 +475,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (reference.IsNull) return null; if (reference.IsNull) return null;
LanguageProperties languageProperties = projectContent.Language; LanguageProperties languageProperties = projectContent.Language;
IReturnType t = null; IReturnType t = null;
if (callingClass != null) { if (callingClass != null && !reference.IsGlobal) {
foreach (ITypeParameter tp in callingClass.TypeParameters) { foreach (ITypeParameter tp in callingClass.TypeParameters) {
if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType)) { if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType)) {
t = new GenericReturnType(tp); t = new GenericReturnType(tp);
break; break;
} }
} }
} if (t == null && callingMember is IMethod && (callingMember as IMethod).TypeParameters != null) {
if (callingMember is IMethod && (callingMember as IMethod).TypeParameters != null) {
foreach (ITypeParameter tp in (callingMember as IMethod).TypeParameters) { foreach (ITypeParameter tp in (callingMember as IMethod).TypeParameters) {
if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType)) if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType)) {
return new GenericReturnType(tp); t = new GenericReturnType(tp);
break;
}
}
} }
} }
if (t == null) { if (t == null) {
@ -499,11 +497,30 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
t = ProjectContentRegistry.Mscorlib.GetClass(reference.SystemType).DefaultReturnType; t = ProjectContentRegistry.Mscorlib.GetClass(reference.SystemType).DefaultReturnType;
} else { } else {
if (useLazyReturnType) { if (useLazyReturnType) {
if (reference.IsGlobal)
t = new GetClassReturnType(projectContent, reference.SystemType);
else
t = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.SystemType); t = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.SystemType);
} else { } else {
IClass c = projectContent.SearchType(reference.SystemType, callingClass, caretLine, caretColumn); IClass c;
if (c == null) if (reference.IsGlobal)
c = projectContent.GetClass(reference.SystemType);
else
c = projectContent.SearchType(reference.SystemType, callingClass, caretLine, caretColumn);
if (c == null) {
if (reference.GenericTypes.Count == 0 && !reference.IsArrayType) {
// reference to namespace is possible
if (reference.IsGlobal) {
if (projectContent.NamespaceExists(reference.Type))
return new NamespaceReturnType(reference.Type);
} else {
string name = projectContent.SearchNamespace(reference.Type, callingClass, (callingClass == null) ? null : callingClass.CompilationUnit, caretLine, caretColumn);
if (name != null)
return new NamespaceReturnType(name);
}
}
return null; return null;
}
t = c.DefaultReturnType; t = c.DefaultReturnType;
} }
} }

Loading…
Cancel
Save