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. 139
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  10. 1528
      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. 45
      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 @@ -509,6 +509,12 @@ namespace CSharpBinding.Parser
case '.':
curTokenType = Dot;
break;
case ':':
if (GetNext() == ':') {
// treat :: like dot
curTokenType = Dot;
}
break;
case '\'':
case '"':
if (ReadStringLiteral(ch)) {

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

@ -188,7 +188,6 @@ @@ -188,7 +188,6 @@
<Compile Include="Src\Parser\Visitors\CSharpToVBNetConvertVisitor.cs" />
<Compile Include="Src\Parser\Visitors\PrefixFieldsVisitor.cs" />
<Compile Include="Src\Parser\Visitors\VBNetToCSharpConvertVisitor.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\GlobalReferenceExpression.cs" />
</ItemGroup>
<ItemGroup>
<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 @@ -123,6 +123,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(TypeReference typeReference, object data)
{
if (typeReference.IsGlobal) {
outputFormatter.PrintText("global::");
}
if (typeReference.Type == null || typeReference.Type.Length ==0) {
outputFormatter.PrintText("void");
} else {
@ -342,7 +345,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -342,7 +345,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (i > 0) {
PrintFormattedComma();
}
outputFormatter.PrintIdentifier((string)typeDeclaration.BaseTypes[i]);
nodeTracker.TrackedVisit(typeDeclaration.BaseTypes[i], data);
}
}
@ -2073,11 +2076,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2073,11 +2076,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public object Visit(GlobalReferenceExpression globalReferenceExpression, object data) {
outputFormatter.PrintText("global::");
return null;
}
public object Visit(ObjectCreateExpression objectCreateExpression, object data)
{
outputFormatter.PrintToken(Tokens.New);

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

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

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

@ -1,25 +0,0 @@ @@ -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 @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
// Children of Enum: FieldDeclaration
string name = "";
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>();
public string Name {
@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public ArrayList BaseTypes {
public List<TypeReference> BaseTypes {
get {
return bases;
}

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

@ -20,6 +20,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -20,6 +20,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
int pointerNestingLevel = 0;
int[] rankSpecifier = null;
List<TypeReference> genericTypes = new List<TypeReference>(1);
bool isGlobal = false;
static Dictionary<string, string> types = new Dictionary<string, string>();
static Dictionary<string, string> vbtypes = new Dictionary<string, string>();
@ -131,6 +132,18 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -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)
{
return typeReference == null ? NullTypeReference.Instance : typeReference;
@ -161,6 +174,13 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -161,6 +174,13 @@ namespace ICSharpCode.NRefactory.Parser.AST
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)
{
}

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

File diff suppressed because it is too large Load Diff

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

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

1528
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> @@ -588,8 +588,9 @@ TypeParameterConstraints<TemplateDefinition template>
/* 6.4.2 */
NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
(.
string name = String.Empty;
ArrayList names = null;
string name = null;
TypeReference typeRef = null;
List<TypeReference> baseInterfaces = null;
.) =
(. m.Check(Modifier.Classes); .)
/* Spec, 7.5 */
@ -605,8 +606,8 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -605,8 +606,8 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .)
TypeParameterList<newType.Templates>
EndOfStmt
[ ClassBaseType<out name> (. newType.BaseTypes.Add(name); .) ]
{ TypeImplementsClause<out names> (. newType.BaseTypes.AddRange(names); .) }
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
ClassBody<newType>
(.
compilationUnit.BlockEnd();
@ -634,7 +635,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -634,7 +635,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
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; .)
TypeParameterList<newType.Templates>
@ -656,7 +657,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -656,7 +657,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
newType.Type = Types.Enum;
.)
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
EnumBody<newType>
(.
@ -670,11 +671,11 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -670,11 +671,11 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.Type = Types.Interface;ArrayList baseInterfaces;
newType.Type = Types.Interface;
.)
Identifier (. newType.Name = t.val; newType.StartLocation = t.EndLocation; .)
TypeParameterList<newType.Templates>
EndOfStmt { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces.ToArray()); .) }
EndOfStmt { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
InterfaceBody<newType>
(.
newType.EndLocation = t.Location;
@ -879,15 +880,14 @@ ClassMemberDecl<Modifiers m, List<AttributeSection> attributes> = @@ -879,15 +880,14 @@ ClassMemberDecl<Modifiers m, List<AttributeSection> attributes> =
StructureMemberDecl<m, attributes>
.
ClassBaseType<out string name>
(.
TypeReference type;
name = String.Empty;
.) =
ClassBaseType<out TypeReference typeRef>
(.
typeRef = null;
.) =
"Inherits"
TypeName<out type> (. name = type.Type; .)
TypeName<out typeRef>
EndOfStmt
.
.
/* 7.6.1 */
StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
@ -1368,33 +1368,33 @@ HandlesClause<out ArrayList handlesClause> @@ -1368,33 +1368,33 @@ HandlesClause<out ArrayList handlesClause>
.
/* 7.8. */
InterfaceBase <out ArrayList bases>
InterfaceBase <out List<TypeReference> bases>
(.
TypeReference type;
bases = new ArrayList();
bases = new List<TypeReference>();
.) =
"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
.
/* 7.2 */
TypeImplementsClause<out ArrayList baseInterfaces>
TypeImplementsClause<out List<TypeReference> baseInterfaces>
(.
baseInterfaces = new ArrayList();
baseInterfaces = new List<TypeReference>();
TypeReference type = null;
.) =
"Implements" TypeName<out type>
(.
baseInterfaces.Add(type.Type);
baseInterfaces.Add(type);
.)
{
"," TypeName<out type>
(. baseInterfaces.Add(type.Type); .)
(. baseInterfaces.Add(type); .)
}
EndOfStmt
.
@ -1496,9 +1496,9 @@ SimpleExpr<out Expression pexpr> @@ -1496,9 +1496,9 @@ SimpleExpr<out Expression pexpr>
| (. Expression retExpr = null; .)
( "MyBase" (. retExpr = new BaseReferenceExpression(); .)
| "MyClass" (. retExpr = new ClassReferenceExpression(); .)
| "Global" (. retExpr = new GlobalReferenceExpression(); .)
)
"." 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; .)
| /* 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)); .)
@ -1753,6 +1753,11 @@ NonArrayTypeName<out TypeReference typeref> @@ -1753,6 +1753,11 @@ NonArrayTypeName<out TypeReference typeref>
"(" "Of" TypeArgumentList<typeref.GenericTypes> ")"
]
| "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); .)
.

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

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

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

@ -117,7 +117,6 @@ namespace ICSharpCode.NRefactory.Parser @@ -117,7 +117,6 @@ namespace ICSharpCode.NRefactory.Parser
object Visit(IndexerExpression indexerExpression, object data);
object Visit(ThisReferenceExpression thisReferenceExpression, object data);
object Visit(BaseReferenceExpression baseReferenceExpression, object data);
object Visit(GlobalReferenceExpression globalReferenceExpression, object data);
object Visit(ObjectCreateExpression objectCreateExpression, object data);
object Visit(ArrayCreateExpression arrayCreateExpression, 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 @@ -16,22 +16,38 @@ namespace ICSharpCode.NRefactory.Tests.AST
[TestFixture]
public class GlobalReferenceExpressionTests
{
#region C#
[Test]
public void CSharpGlobalReferenceExpressionTest()
{
FieldReferenceExpression fre = (FieldReferenceExpression)ParseUtilCSharp.ParseExpression("global::System", typeof(FieldReferenceExpression));
Assert.IsTrue(fre.TargetObject is GlobalReferenceExpression);
TypeReferenceExpression tre = (TypeReferenceExpression)ParseUtilCSharp.ParseExpression("global::System", typeof(TypeReferenceExpression));
Assert.IsTrue(tre.TypeReference.IsGlobal);
Assert.AreEqual("System", tre.TypeReference.Type);
}
#endregion
#region VB.NET
[Test]
public void VBNetGlobalReferenceExpressionTest()
{
FieldReferenceExpression fre = (FieldReferenceExpression)ParseUtilVBNet.ParseExpression("Global.System", typeof(FieldReferenceExpression));
Assert.IsTrue(fre.TargetObject is GlobalReferenceExpression);
TypeReferenceExpression tre = (TypeReferenceExpression)ParseUtilVBNet.ParseExpression("Global.System", typeof(TypeReferenceExpression));
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 @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual(Types.Class, td.Type);
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);
}
@ -97,7 +97,7 @@ public class Generic<T, S> : System.IComparable where S : G<T[]> where T : MyNa @@ -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(Modifier.Public, td.Modifier);
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("T", td.Templates[0].Name);
@ -127,9 +127,9 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -127,9 +127,9 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(Modifier.Public | Modifier.Abstract, td.Modifier);
Assert.AreEqual(1, td.Attributes.Count);
Assert.AreEqual(3, td.BaseTypes.Count);
Assert.AreEqual("MyBase", td.BaseTypes[0]);
Assert.AreEqual("Interface1", td.BaseTypes[1]);
Assert.AreEqual("My.Test.Interface2", td.BaseTypes[2]);
Assert.AreEqual("MyBase", td.BaseTypes[0].Type);
Assert.AreEqual("Interface1", td.BaseTypes[1].Type);
Assert.AreEqual("My.Test.Interface2", td.BaseTypes[2].Type);
}
[Test]
@ -183,7 +183,7 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -183,7 +183,7 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestEnum", td.Name);
Assert.AreEqual(Types.Enum, td.Type);
Assert.AreEqual("Byte", td.BaseTypes[0].ToString());
Assert.AreEqual("Byte", td.BaseTypes[0].Type);
}
[Test]
@ -262,7 +262,7 @@ End Class @@ -262,7 +262,7 @@ End Class
Assert.AreEqual("Generic", td.Name);
Assert.AreEqual(Modifier.Public, td.Modifier);
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("T", td.Templates[0].Name);

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

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

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

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

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

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

Loading…
Cancel
Save