From 64c50de445ee0c57a83717248b42ff04e5a93e06 Mon Sep 17 00:00:00 2001 From: Robert van der Hulst Date: Fri, 16 Sep 2022 10:01:39 +0200 Subject: [PATCH] [Compiler] Fix for instance keyword, #X-Sharp/XSharpPublic/issues/1115 --- Tests/Applications/C868/Prg/C868.prg | 15 +++++++++++---- Tests/xSharp Tests.viproj | 18 +++++++++--------- XSharp/src/Common/BuildNumber.h | 4 ++-- XSharp/src/Common/Constants.cs | 4 ++-- .../Parser/XSharpTokenExtensions.cs | 10 +++++++--- .../Parser/XSharpTreeTransformationCore.cs | 5 ++++- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Tests/Applications/C868/Prg/C868.prg b/Tests/Applications/C868/Prg/C868.prg index 732e0b16b8..2e2b0d58c4 100644 --- a/Tests/Applications/C868/Prg/C868.prg +++ b/Tests/Applications/C868/Prg/C868.prg @@ -5,10 +5,17 @@ FUNCTION Start() AS VOID LOCAL o AS TestClass o := TestClass{} -? o:iInstance -o:iInstance := 123 -? o:iInstance +// ? o:iInstance +// o:iInstance := 123 +// ? o:iInstance CLASS TestClass -INSTANCE iInstance := 555 AS INT + + INSTANCE iInstance := 555 AS INT +END CLASS + +CLASS SubClass INHERIT TestClass + CONSTRUCTOR + SUPER() + iInstance := 444 END CLASS diff --git a/Tests/xSharp Tests.viproj b/Tests/xSharp Tests.viproj index c7dcbab58b..9c916d1610 100644 --- a/Tests/xSharp Tests.viproj +++ b/Tests/xSharp Tests.viproj @@ -114631,7 +114631,7 @@ Target = 0 Platform = AnyCPU Language = XSharp Runtime = CLR4 -Dialect = VO +Dialect = Vulcan Folder = %ProjectPath%\Applications\C868\ PrgSubFolder = \Prg ResourcesSubFolder = @@ -114663,8 +114663,8 @@ FileType = Code CopyToBin = 0 [C868 - INSTANCE iVars are incorrectly treated as public vars References] ReferenceGAC = CLR4,System,1,0,4.0.0.0 -ReferenceGAC = CLR4,XSharp.Core,1,0,2.6.0.0 -ReferenceGAC = CLR4,XSharp.RT,1,0,2.6.0.0 +ReferenceGAC = XSharp.Core,1,0,2.6.0.0 +ReferenceGAC = XSharp.RT,1,0,2.6.0.0 [C868 - INSTANCE iVars are incorrectly treated as public vars Resources] [C868 - INSTANCE iVars are incorrectly treated as public vars Native Resources] [C868 - INSTANCE iVars are incorrectly treated as public vars License files] @@ -114741,7 +114741,7 @@ GalleryName = GalleryPage = GalleryDefaultName = Target = 0 -Platform = AnyCPU +Platform = x86 Language = XSharp Runtime = CLR4 Dialect = VO @@ -114776,8 +114776,8 @@ FileType = Code CopyToBin = 0 [C869 - IVarGetInfo() returns incorrect results References] ReferenceGAC = CLR4,System,1,0,4.0.0.0 -ReferenceGAC = CLR4,XSharp.Core,1,0,2.6.0.0 -ReferenceGAC = CLR4,XSharp.RT,1,0,2.6.0.0 +ReferenceBrowse = C:\XSharp\DevRt\Binaries\Debug\XSharp.Core.dll,1,1 +ReferenceBrowse = C:\XSharp\DevRt\Binaries\Debug\XSharp.RT.dll,1,1 [C869 - IVarGetInfo() returns incorrect results Resources] [C869 - IVarGetInfo() returns incorrect results Native Resources] [C869 - IVarGetInfo() returns incorrect results License files] @@ -114854,7 +114854,7 @@ GalleryName = GalleryPage = GalleryDefaultName = Target = 0 -Platform = AnyCPU +Platform = x86 Language = XSharp Runtime = CLR4 Dialect = VO @@ -114889,8 +114889,8 @@ FileType = Code CopyToBin = 0 [C870 - Default() function with NULL_OBJECT incompatibility with VO References] ReferenceGAC = CLR4,System,1,0,4.0.0.0 -ReferenceGAC = CLR4,XSharp.Core,1,0,2.6.0.0 -ReferenceGAC = CLR4,XSharp.RT,1,0,2.6.0.0 +ReferenceBrowse = C:\XSharp\DevRt\Binaries\Debug\XSharp.RT.dll,1,1 +ReferenceBrowse = C:\XSharp\DevRt\Binaries\Debug\XSharp.Core.dll,1,1 [C870 - Default() function with NULL_OBJECT incompatibility with VO Resources] [C870 - Default() function with NULL_OBJECT incompatibility with VO Native Resources] [C870 - Default() function with NULL_OBJECT incompatibility with VO License files] diff --git a/XSharp/src/Common/BuildNumber.h b/XSharp/src/Common/BuildNumber.h index 156a542f95..120713d1d0 100644 --- a/XSharp/src/Common/BuildNumber.h +++ b/XSharp/src/Common/BuildNumber.h @@ -13,13 +13,13 @@ #ifdef RUNTIME #define VERSION_NUMBER "2.6.0.0" #else - #define VERSION_NUMBER "2.13.2.1" + #define VERSION_NUMBER "2.13.2.2" #endif // This is the file version number, which is ignored by .NET but used by Windows installer to determine // whether one file is newer than another. // This typically would change if we're generating a patch, otherwise it should be the same as VERSION_NUMBER - #define FILEVERSION_NUMBER "2.13.2.1" + #define FILEVERSION_NUMBER "2.13.2.2" #define INFORMATIONAL_NUMBER "2.13b GA" #ifdef __DEBUG__ diff --git a/XSharp/src/Common/Constants.cs b/XSharp/src/Common/Constants.cs index 3b1973ae08..00ef6c8e91 100644 --- a/XSharp/src/Common/Constants.cs +++ b/XSharp/src/Common/Constants.cs @@ -16,9 +16,9 @@ internal class Constants #if RUNTIME internal const string Version = "2.6.0.0"; #else - internal const string Version = "2.13.2.1"; + internal const string Version = "2.13.2.2"; #endif - internal const string FileVersion = "2.13.2.1"; + internal const string FileVersion = "2.13.2.2"; internal const string ProductVersion = "2.13b GA"; internal const string PublicKey = "ed555a0467764586"; internal const string Copyright = "Copyright © XSharp BV 2015-2022"; diff --git a/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTokenExtensions.cs b/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTokenExtensions.cs index 2f17b9515f..e7ee3e06d8 100644 --- a/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTokenExtensions.cs +++ b/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTokenExtensions.cs @@ -15,6 +15,7 @@ using Antlr4.Runtime; using Antlr4.Runtime.Tree; using LanguageService.CodeAnalysis.XSharp.SyntaxParser; +using System.Security.Policy; namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax { @@ -1107,7 +1108,7 @@ public static SyntaxToken SyntaxKeyword(this IToken token) r = SyntaxFactory.MakeToken(SyntaxKind.GlobalKeyword, text); break; case XSharpParser.INSTANCE: - r = SyntaxFactory.MakeToken(SyntaxKind.ProtectedKeyword, text); + r = SyntaxFactory.MakeToken(SyntaxKind.None); break; case XSharpParser.ASCENDING: r = SyntaxFactory.MakeToken(SyntaxKind.AscendingKeyword, text); @@ -1718,7 +1719,7 @@ private static SyntaxToken makeGeneratedToken(SyntaxKind kind) token.XGenerated = true; return token; } - public static void FixDefaultVisibility(this SyntaxListBuilder list) + public static void FixDefaultVisibility(this SyntaxListBuilder list, bool isInstance = false) { for (int i = 0; i < list.Count; i++) { @@ -1726,7 +1727,10 @@ public static void FixDefaultVisibility(this SyntaxListBuilder list) if (SyntaxFacts.IsAccessibilityModifier((SyntaxKind)item.RawKind)) return; } - list.Add(makeGeneratedToken(SyntaxKind.PublicKeyword)); + if (isInstance) + list.Add(makeGeneratedToken(SyntaxKind.ProtectedKeyword)); + else + list.Add(makeGeneratedToken(SyntaxKind.PublicKeyword)); } public static bool CanBeVirtual(this SyntaxListBuilder list) diff --git a/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs b/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs index 459dada2f6..db8e724591 100644 --- a/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs +++ b/XSharp/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs @@ -5107,13 +5107,16 @@ public override void ExitClassModifiers([NotNull] XP.ClassModifiersContext conte public override void ExitClassvarModifiers([NotNull] XP.ClassvarModifiersContext context) { SyntaxListBuilder modifiers = _pool.Allocate(); + bool isInstance = false; foreach (var m in context._Tokens) { modifiers.AddCheckUnique(m.SyntaxKeyword()); if (m.Type == XP.FIXED && context._FIXED == null) context._FIXED = m; + if (m.Type == XP.INSTANCE) + isInstance = true; } - modifiers.FixDefaultVisibility(); + modifiers.FixDefaultVisibility(isInstance); context.PutList(modifiers.ToList()); _pool.Free(modifiers); }