Skip to content

Commit

Permalink
Feature/x sharp compiler (#55)
Browse files Browse the repository at this point in the history
* [Compiler tests] Adjusted tests for #1187 and #1191

* [Compiler tests] Added C877 and adjusted R882 for #1184

* [Compiler tests] Added C878 for #1194 (and missing C877 from previous commit)

* [Common] Fixes #/issues/1194

* WIP on StackAlloc, debugger sequence points and line numbers in error messages

* [Compiler tests] Added test C879 for #1195

* [Compiler] Switch to .Net Analyzers version 7.0.0

* [Compiler] Fixes #/issues/1195
Adjust overload resolution to only use our "logic" when:
- functions are involved
- our types are involved
- param is passed by reference
- argument is enum

* [Compiler] Suppress error messages about updated NetAnalyzers. Also suppress NetAnalyzer all together for X# code

* [Tests] Fixed one more test

* Fixes #/issues/1184, C877 and R882

* [Tests] SUM command has been fixed in the header file

* [Compiler] Fixes #/issues/1084

* [Tests] Added test for Stackalloc keyword

* [Compiler] A predicate prevents STACKALLOC(123) from being parsed as STACKALLOC followed by a paren expression

* [Compiler] Fixes #/issues/1166, issue number 1

* [Compiler] Fixes #/issues/1109

* [Tests] Added pragma to several tests to suppress messages about missing REF or OUT modifiers for parameters

* [tests] Changed incorrect '.' operators to ':' in two tests

* [tests] Updated STACKALLOC test to use STACKALLOC as an identifier for a local

* [tests] Set compiler profile to debug tests

Co-authored-by: cpyrgas <chris@xsharp.eu>
  • Loading branch information
RobertvanderHulst and cpyrgas committed Jan 18, 2023
1 parent 4a11668 commit 80144f1
Show file tree
Hide file tree
Showing 34 changed files with 1,450 additions and 937 deletions.
2 changes: 1 addition & 1 deletion Roslyn/eng/Versions.props
Expand Up @@ -28,7 +28,7 @@
<PropertyGroup>
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>3.3.2-beta1.20562.1</RoslynDiagnosticsNugetPackageVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview1.21054.10</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>7.0.0</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20623.3</MicrosoftCodeAnalysisTestingVersion>
<CodeStyleAnalyzerVersion>3.8.0</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>16.8.181</VisualStudioEditorPackagesVersion>
Expand Down
Expand Up @@ -6496,7 +6496,18 @@ private BoundExpression MakeMemberAccessValue(BoundExpression expr, DiagnosticBa
{
options |= LookupOptions.MustBeInvocableIfMember;
}

#if XSHARP
if (node.XNode is XSharpParser.AccessMemberContext amc)
{
if (amc.Op.Type == XSharpLexer.DOT && ! leftType.IsVoStructOrUnion())
{
if (! Compilation.Options.HasOption(CompilerOption.AllowDotForInstanceMembers, node))
{
Error(diagnostics, ErrorCode.ERR_DotForInstanceMember, node, right.ToString());
}
}
}
#endif
var lookupResult = LookupResult.GetInstance();
try
{
Expand Down
2 changes: 2 additions & 0 deletions Tests/Applications/C129/Prg/C129.prg
@@ -1,7 +1,9 @@
// 129. Assertion failed at BetterConversionExpression...
// using REF for the last argument gets rid of the failed assertion
#pragma warnings(9071, off) // Parameter 3 needs a(n) 'Out' modifier. This modifier was automatically added.
FUNCTION Start() AS VOID
LOCAL n,m,k AS INT
n := 1;m := 1;k := 1
? Math.DivRem( n, m, k )
? k

11 changes: 6 additions & 5 deletions Tests/Applications/C181/Prg/C181.prg
@@ -1,11 +1,12 @@
// 181. error XS0121: The call is ambiguous between the following methods or properties:
// 181. error XS0121: The call is ambiguous between the following methods or properties:
// 'TestClass.MyMethod(ref int)' and 'TestClass.MyMethod(ref double)'
// vulcan allows passing params by reference without specifying REF in the caller code,
// so that must be fully supported in x# as well, but I think it would be btter to make
// the compiler report a warning in such calls with missing REF
// vulcan allows passing params by reference without specifying REF in the caller code,
// so that must be fully supported in x# as well, but I think it would be btter to make
// the compiler report a warning in such calls with missing REF
#pragma warnings(9071, off) // Parameter needs a(n) 'Out' modifier. This modifier was automatically added.
FUNCTION Start() AS VOID
TestClass{}:CallMethod()

CLASS TestClass
METHOD CallMethod() AS VOID
LOCAL nInt := 0 AS INT
Expand Down
1 change: 1 addition & 0 deletions Tests/Applications/C356/Prg/C356.prg
@@ -1,6 +1,7 @@
// 356. error XS1503: Argument 1: cannot convert from 'byte' to 'string'
#pragma warnings(165, off) // uniassigned local
#pragma warnings(9068, off) // auto psz
#pragma warnings(9071, off) // Parameter needs a(n) 'Out' modifier. This modifier was automatically added.
FUNCTION Start() AS VOID

/*
Expand Down
32 changes: 32 additions & 0 deletions Tests/Applications/C877/Prg/C877.prg
@@ -0,0 +1,32 @@
// 877. Problems with interpolated strings
// https://github.com/X-Sharp/XSharpPublic/issues/1184
FUNCTION Start( ) AS VOID
LOCAL n := 123 AS INT
LOCAL c AS STRING
c := i"{n}"
? c
xAssert(c == "123")

c := i"{1}"
? c
xAssert(c == "1")

c := i"{n} {{"
? c
xAssert(c == "123 {")

c := i"{n} }}"
? c
xAssert(c == "123 }")

c := i"{n} {{}}"
? c
xAssert(c == "123 {}")
RETURN

PROC xAssert(l AS LOGIC)
IF .NOT. l
THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()}
END IF
? "Assertion passed"
RETURN
24 changes: 24 additions & 0 deletions Tests/Applications/C878/Prg/C878.prg
@@ -0,0 +1,24 @@
// 878. Preprocessor problem with the SUM UDC (with nested brackets)

FUNCTION Start() AS VOID
LOCAL uSum1,uSum2 AS INT

SUM 10 TO uSum1 WHILE 1==1 FOR "a"=="a"
? uSum1
xAssert(uSum1 == 10)
SUM 100,200 TO uSum1 , uSum2 WHILE TRUE FOR TRUE

? uSum1, uSum2
xAssert(uSum1 == 100)
xAssert(uSum2 == 200)

FUNCTION DbEval(cb)
Eval(cb)
RETURN NIL

PROC xAssert(l AS LOGIC)
IF .NOT. l
THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()}
END IF
? "Assertion passed"
RETURN
18 changes: 18 additions & 0 deletions Tests/Applications/C879/Prg/C879.prg
@@ -0,0 +1,18 @@
// 879. Compiler incorrectly selects constructor overload with OBJECT[] parameter
//
/*
System.ArgumentException: Non white space characters cannot be added to content.
at System.Xml.Linq.XDocument.ValidateString(String s)
at System.Xml.Linq.XContainer.AddStringSkipNotify(String s)
at System.Xml.Linq.XContainer.AddContentSkipNotify(Object content)
*/

USING System.Xml.Linq

FUNCTION Start( ) AS VOID
LOCAL x AS XDocument
x := XDocument{}
x := XDocument{x} // this works fine
x := XDocument{XDeclaration{"1.0", "utf-8", "False"}} // incorrect overload picked here
? x:Declaration:Version
RETURN
6 changes: 3 additions & 3 deletions Tests/Applications/R827/Prg/R827.prg
@@ -1,7 +1,7 @@
// https://github.com/X-Sharp/XSharpPublic/issues/770

FUNCTION Start() AS VOID STRICT
TestClass{}.Test()
TestClass{}:Test()
RETURN

PUBLIC CLASS TestClass
Expand All @@ -12,7 +12,7 @@ PUBLIC CLASS TestClass

LOCAL b := a?:B AS ClassB // without the question mark (i.e. "local b := a.B as ClassB") no exception is thrown
xAssert(b:S == "X#rules")
b := a:B
b := a:B
xAssert(b:S == "X#rules")
RETURN

Expand Down Expand Up @@ -44,5 +44,5 @@ IF .not. l
THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()}
END IF
? "Assertion passed"
RETURN
RETURN

12 changes: 6 additions & 6 deletions Tests/Applications/R871/Prg/R871.prg
Expand Up @@ -3,10 +3,10 @@

function Start() as void strict
try
Dummy{}.Test(42)
xAssert(Dummy{}.Test(42) == 42)
Dummy{}.Test("abc")
xAssert(Dummy{}.Test("abc") == 0)
Dummy{}:Test(42)
xAssert(Dummy{}:Test(42) == 42)
Dummy{}:Test("abc")
xAssert(Dummy{}:Test("abc") == 0)
catch e as Exception
? e:ToString()
end try
Expand All @@ -20,15 +20,15 @@ class Dummy

if (param is int)
nParam := (int)param
self.test(nparam)
self:test(nparam)
else
? "Param not an int :" + param:ToString()
endif

return 0

method Test(param as int?) as int
? "Param is int : " + (param ?? 0).toString()
? "Param is int : " + (param ?? 0):toString()
return param:Value
end class

Expand Down
24 changes: 14 additions & 10 deletions Tests/Applications/R880/Prg/R880.prg
@@ -1,16 +1,20 @@
// https://github.com/X-Sharp/XSharpPublic/issues/1187
// https://github.com/X-Sharp/XSharpPublic/issues/1190
static class Test
public static method GetVal() as logic
local nAbc := 1 as int
STATIC CLASS Test
PUBLIC STATIC METHOD GetVal() AS LOGIC
LOCAL nAbc := 1 AS INT

if (nAbc > 0) // error here and not in the elseif line
nop()
elseif (self:nAbc == 0)
nop()
endif
IF (nAbc > 0) // error here and not in the elseif line
NOP()
ELSEIF (SELF:nAbc == 0)
NOP()
ENDIF

REPEAT
? "test"
UNTIL (unkonwn == 123)

return true
end class
RETURN TRUE
END CLASS


21 changes: 18 additions & 3 deletions Tests/Applications/R882/Prg/R882.prg
@@ -1,5 +1,20 @@
// https://github.com/X-Sharp/XSharpPublic/issues/1184
function start as void
var teststring := ie"{1}}"
FUNCTION start AS VOID
VAR teststring := ie"{1}}"
? testString
return

testString := ie"{}" // An internal compiler error here
// c# reports "error CS1733: Expected expression"
RETURN

/*
R882.prg(1,1): error XS9999: An internal compiler error has occurred: 'Object reference not set to an instance of an object.', at LanguageService.CodeAnalysis.GreenNode.AdjustFlagsAndWidth(GreenNode node) in D:\a\XSharpDev\XSharpDev\Roslyn\Src\Compilers\Core\Portable\Syntax\GreenNode.cs:line 117
at LanguageService.CodeAnalysis.XSharp.Syntax.InternalSyntax.ArgumentSyntax..ctor(SyntaxKind kind, NameColonSyntax nameColon, SyntaxToken refKindKeyword, ExpressionSyntax expression, SyntaxFactoryContext context) in D:\a\XSharpDev\XSharpDev\Roslyn\Src\Compilers\CSharp\Portable\Generated\CSharpSyntaxGenerator\CSharpSyntaxGenerator.SourceGenerator\Syntax.xml.Internal.Generated.cs:line 5576
at LanguageService.CodeAnalysis.XSharp.Syntax.InternalSyntax.ContextAwareSyntax.Argument(NameColonSyntax nameColon, SyntaxToken refKindKeyword, ExpressionSyntax expression) in D:\a\XSharpDev\XSharpDev\Roslyn\Src\Compilers\CSharp\Portable\Generated\CSharpSyntaxGenerator\CSharpSyntaxGenerator.SourceGenerator\Syntax.xml.Internal.Generated.cs:line 35293
at LanguageService.CodeAnalysis.XSharp.Syntax.InternalSyntax.XSharpTreeTransformationCore.CreateInterPolatedStringExpression(IToken token, XSharpParserRuleContext context) in D:\a\XSharpDev\XSharpDev\XSharp\src\Compiler\XSharpCodeAnalysis\Parser\XSharpTreeTransformationCore.cs:line 8988
at LanguageService.CodeAnalysis.XSharp.Syntax.InternalSyntax.XSharpTreeTransformationCore.ExitLiteralValue(LiteralValueContext context) in D:\a\XSharpDev\XSharpDev\XSharp\src\Compiler\XSharpCodeAnalysis\Parser\XSharpTreeTransformationCore.cs:line 9106
at LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.LiteralValueContext.ExitRule(IParseTreeListener listener) in D:\a\XSharpDev\XSharpDev\XSharp\src\Compiler\XSharpCodeAnalysis\Generated\XSharpParser.cs:line 20941
at LanguageService.SyntaxTree.Tree.ParseTreeWalker.ExitRule(IParseTreeListener listener, IRuleNode r) in D:\a\XSharpDev\XSharpDev\XSharp\src\Compiler\XSharpCodeAnalysis\Antlr4.Runtime\Tree\ParseTreeWalker.cs:line 95
at LanguageService.SyntaxTree.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t) in D:\a\XSharpDev\XSharpDev\XSharp\src\Compiler\XSharpCodeAnalysis\Antlr4.Runtime\Tree\ParseTreeWalker.cs:line 54
at LanguageService.CodeAnalysis.XSharp.Syntax.InternalSyntax.XSharpLanguageParser.ParseCompilationUnitCore() in D:\a\XSharpDev\XSharpDev\XSharp\src\Compiler\XSharpCodeAnalysis\Parser\XSharpLanguageParser.cs:line 395
*/
35 changes: 30 additions & 5 deletions Tests/Applications/R883/Prg/R883.prg
@@ -1,14 +1,39 @@
FUNCTION Start() AS VOID STRICT
VAR x := StackAlloc<DWORD>(10)
LOCAL dim y[10] as dword
? @x
? @y
VAR x := StackAlloc <dword>{1,2,3,4,5,6,7,8,9,10}
VAR y := StackAlloc dword[]{10}
//var z := STACKALLOC 10
local STACKALLOC := "sometext" as string
? STACKALLOC
xAssert(x[1] == 1)
xAssert(x[10] == 10)
? x[1], x[2], x[3], x[4]
? y[1], y[2], y[3], y[4]
y[1] := x[1] := 42
y[2] := x[2] := 42*42
x[3] := 42 * x[2]
y[4] := x[4] := 42 * x[3]
? x[1], x[2], x[3], x[4]
? y[1], y[2], y[3], y[4]
Console.Read()
xAssert(x[1] == 42)
xAssert(y[1] == 42)
xAssert(x[4] == 42*42*42*42)
xAssert(y[4] == 42*42*42*42)
? @x
for var i := 1 to 10
? i, @x[i], x[i]
next
? " outside of boundaries, no exception, this may be dangerous"

for var i := 11 to 20
? i, @x[i], x[i]
next
return


PROC xAssert(l AS LOGIC) AS VOID
IF l
? "Assertion passed"
ELSE
THROW Exception{"Incorrect result"}
END IF
RETURN
1 change: 1 addition & 0 deletions Tests/Applications/RuntimeTests/Prg/RuntimeTests.prg
Expand Up @@ -30,6 +30,7 @@ FUNCTION Start() AS INT
"C811", "C812", "C813", "C814", "C815", "C817","C820", /*"C827", */"C830", "C832", "C834", ;
"C836", "C837", "C840", "C846", "C847", "C848", "C849", "C850","C851","C853",;
"C857", "C859", "C860", "C865", "C866", "C867", "C869", "C870","C871","C873",;
"C879", ;
"R678", "R681", "R690", "R698", "R699", "R700" ,"R701", "R702", "R710",;
"R711", "R712", "R725", "R729", "R730", "R732","R735", "R736","R741","R742","R743",;
"R750", "R751", "R752", "R753", "R754", "R755","R756", "R757","R759","R763", "R765",;
Expand Down

0 comments on commit 80144f1

Please sign in to comment.