diff --git a/CSharpToJavaScript.csproj b/CSharpToJavaScript.csproj index 5b7b016d..d5572e43 100644 --- a/CSharpToJavaScript.csproj +++ b/CSharpToJavaScript.csproj @@ -6,7 +6,7 @@ net10.0 disable enable - True + False TiLied A library for translating/converting cs into js, using Roslyn. https://tilied.github.io/CSTOJS_Pages/ diff --git a/CSharpToJavaScript/APIs/JS/GlobalObject.cs b/CSharpToJavaScript/APIs/JS/GlobalObject.cs index 426758cb..81e0b013 100644 --- a/CSharpToJavaScript/APIs/JS/GlobalObject.cs +++ b/CSharpToJavaScript/APIs/JS/GlobalObject.cs @@ -43,7 +43,7 @@ public static bool InequalsStrict(dynamic left, dynamic right) /// /// object.property /// true for all cases except when the property is an own non-configurable property, in which case false is returned in non-strict mode. - [Unary("delete ")] + [Unary("delete")] public static bool Delete(dynamic arg) { return true; @@ -57,7 +57,7 @@ public static bool Delete(dynamic arg) /// /// expression /// Undefined - [Unary("void ")] + [Unary("void")] public static Undefined Void(dynamic arg) { return new Undefined(); @@ -71,7 +71,7 @@ public static Undefined Void(dynamic arg) /// /// An expression representing the object or primitive whose type is to be returned. /// string - [Unary("typeof ")] + [Unary("typeof")] public static string TypeOf(object operand) { return string.Empty; @@ -84,7 +84,7 @@ public static string TypeOf(object operand) /// /// An expression representing the object or primitive whose type is to be returned. /// string - [Unary("typeof ")] + [Unary("typeof")] public static string TypeOf(Func operand) { return string.Empty; @@ -97,7 +97,7 @@ public static string TypeOf(Func operand) /// /// An expression representing the object or primitive whose type is to be returned. /// string - [GenericUnary("typeof ")] + [GenericUnary("typeof")] public static string TypeOf() { return string.Empty; @@ -112,7 +112,7 @@ public static string TypeOf() /// Constructor to test against. /// The object to test. /// bool - [GenericBinary(" instanceof ")] + [GenericBinary("instanceof")] public static bool InstanceOf(dynamic obj) { return true; diff --git a/CSharpToJavaScript/CSTOJS.cs b/CSharpToJavaScript/CSTOJS.cs index 68685446..5bc132db 100644 --- a/CSharpToJavaScript/CSTOJS.cs +++ b/CSharpToJavaScript/CSTOJS.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis; using System.Linq; using CSharpToJavaScript.Utils; +using System.Collections.Immutable; namespace CSharpToJavaScript; @@ -49,80 +50,81 @@ public static FileData[] Translate(FileData[] files, MetadataReference[]? refere trees[0] = AddGlobalUsings(trees[0]); + CSharpCompilation compilation = CSharpCompilation + .Create("HelloWorld") + .AddReferences(references) + .AddSyntaxTrees(trees); + for (int i = 0; i < files.Length; i++) { if (files[i].OptionsForFile.TranslateFile == false) continue; - if (files[i].OptionsForFile.NormalizeWhitespace) - trees[i] = trees[i].GetRoot().NormalizeWhitespace().SyntaxTree; + SemanticModel _model = compilation.GetSemanticModel(trees[i]); - if (files[i].OptionsForFile.KeepBraceOnTheSameLine) + ImmutableArray diagnostics = _model.GetDiagnostics(); + for (int j = 0; j < diagnostics.Length; j++) { - //Mostly deleted whitespaces, still TODO? - SyntaxToken[] allBraces = trees[i].GetRoot().DescendantTokens().Where((e) => e.IsKind(SyntaxKind.OpenBraceToken)).ToArray(); - - List allTriviaToDelete = new(); + if (files[i].OptionsForFile.Debug) + Log.WarningLine(diagnostics[j].ToString()); - for (int j = 0; j < allBraces.Length; j++) + //Print an error if compilation fails. + if (diagnostics[j].Severity == DiagnosticSeverity.Error) { - if (allBraces[j].HasLeadingTrivia) - { - SyntaxTriviaList _lt = allBraces[j].LeadingTrivia; - for (int y = 0; y < _lt.Count; y++) - { - allTriviaToDelete.Add(_lt[y]); - } - } + if (files[i].OptionsForFile.DisableCompilationErrors == false) + Log.ErrorLine(diagnostics[i].ToString()); } - //Is this the right way to delete trivia? - trees[i] = trees[i].GetRoot().ReplaceTrivia(allTriviaToDelete, (o, r) => SyntaxFactory.ElasticMarker).SyntaxTree; + } - allBraces = trees[i].GetRoot().DescendantTokens().Where((e) => e.IsKind(SyntaxKind.OpenBraceToken)).ToArray(); + SyntaxNode _root = trees[i].GetRoot(); - List allTriviaToReplace = new(); + WithSemanticRewriter _withSemanticRewriter = new(_model, files[i].OptionsForFile); + WithoutSemanticRewriter _withoutSemanticRewriter = new(files[i].OptionsForFile); + + StringBuilderWalker _stringBuilderWalker = new(); - for (int j = 0; j < allBraces.Length; j++) - { - SyntaxToken _token = allBraces[j].GetPreviousToken(); - if (_token.HasTrailingTrivia) - { - SyntaxTrivia _trivia = _token.TrailingTrivia.Where((e) => e.IsKind(SyntaxKind.EndOfLineTrivia)).FirstOrDefault(); - if (!_trivia.IsKind(SyntaxKind.None)) - { - allTriviaToReplace.Add(_trivia); - } - } - } - trees[i] = trees[i].GetRoot().ReplaceTrivia(allTriviaToReplace, (o, r) => SyntaxFactory.Space).SyntaxTree; - } - } + SyntaxNode newRoot1 = _withSemanticRewriter.Visit(_root); + if (_root != newRoot1) + _root = newRoot1; - CSharpCompilation compilation = CSharpCompilation - .Create("HelloWorld") - .AddReferences(references) - .AddSyntaxTrees(trees); + _root = _root.ReplaceNodes(_withSemanticRewriter.ReplaceNodes.Keys, (o, r) => + { + return _withSemanticRewriter.ReplaceNodes[o]; + }); - for (int i = 0; i < files.Length; i++) - { - if (files[i].OptionsForFile.TranslateFile == false) - continue; + if (files[i].OptionsForFile.Debug) + files[i].Debug_WithSemanticRewriter = _root.ToFullString(); - Walker _walker = new(files[i].OptionsForFile, compilation.GetSemanticModel(trees[i])); + SyntaxNode newRoot2 = _withoutSemanticRewriter.Visit(_root); + if (_root != newRoot2) + _root = newRoot2; - _walker.JSSB.Append(files[i].OptionsForFile.AddSBAtTheTop); + if (files[i].OptionsForFile.Debug) + files[i].Debug_WithoutSemanticRewriter = _root.ToFullString(); + + if (files[i].OptionsForFile.NormalizeWhitespace) + _root = _root.NormalizeWhitespace(); - _walker.Visit(trees[i].GetRoot()); + if (files[i].OptionsForFile.KeepBraceOnTheSameLine) + { + KeepBraceOnTheSameLineRewriter _keepBraceOnTheSameLineRewriter = new(); + + SyntaxNode newRoot3 = _keepBraceOnTheSameLineRewriter.Visit(_root); + if (_root != newRoot3) + _root = newRoot3; + } - _walker.JSSB.Append(files[i].OptionsForFile.AddSBAtTheBottom); + _stringBuilderWalker.JSSB.Append(files[i].OptionsForFile.AddSBAtTheTop); + _stringBuilderWalker.Visit(_root); + _stringBuilderWalker.JSSB.Append(files[i].OptionsForFile.AddSBAtTheBottom); - files[i].TranslatedStr = _walker.JSSB.ToString(); + files[i].TranslatedStr = _stringBuilderWalker.JSSB.ToString(); } return files; } - private static MetadataReference[] GetReferences(CSTOJSOptions options) + public static MetadataReference[] GetReferences(CSTOJSOptions options) { HashSet assemblyMetadata = new(); @@ -200,7 +202,7 @@ private static MetadataReference[] GetReferences(CSTOJSOptions options) } Log.InfoLine($"---"); } - + MetadataReference[] references = new MetadataReference[assemblyMetadata.Count]; int i = 0; foreach (MetadataReference metadata in assemblyMetadata) @@ -218,11 +220,11 @@ private static MetadataReference[] GetReferences(CSTOJSOptions options) } Log.InfoLine($"+++"); } - + return references; } - private static SyntaxTree AddGlobalUsings(SyntaxTree tree) + public static SyntaxTree AddGlobalUsings(SyntaxTree tree) { CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); UsingDirectiveSyntax[] oldUsing = root.Usings.ToArray(); @@ -397,9 +399,20 @@ public class FileData /// CS input string. /// public string SourceStr { get; set; } = string.Empty; - + /// /// JS translated string. /// public string TranslatedStr { get; set; } = string.Empty; -} \ No newline at end of file + + + /// + /// Debug string. + /// + public string Debug_WithSemanticRewriter { get; set; } = string.Empty; + + /// + /// Debug string. + /// + public string Debug_WithoutSemanticRewriter { get; set; } = string.Empty; +} diff --git a/CSharpToJavaScript/StringBuilderWalker.cs b/CSharpToJavaScript/StringBuilderWalker.cs new file mode 100644 index 00000000..f3e13be7 --- /dev/null +++ b/CSharpToJavaScript/StringBuilderWalker.cs @@ -0,0 +1,725 @@ +using CSharpToJavaScript.Utils; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Text; +using System; + +namespace CSharpToJavaScript; + +internal class StringBuilderWalker : CSharpSyntaxWalker +{ + public StringBuilder JSSB { get; set; } = new(512); + + public StringBuilderWalker() : base(SyntaxWalkerDepth.Trivia) + { + + } + +#if DEBUG + public override void Visit(SyntaxNode? node) + { + if (node != null) + Log.InfoLine($"kind: {node.Kind()} \n\t{node.ToString()}"); + + base.Visit(node); + } +#endif + + public override void VisitTrivia(SyntaxTrivia trivia) + { + switch (trivia.Kind()) + { + case SyntaxKind.SingleLineCommentTrivia: + { + string _full = trivia.ToString(); + + //special syntax. + //for writing js code //...\\ + if (_full.EndsWith(@"\\")) + JSSB.Append(_full.AsSpan(2, _full.Length - 4)); + else + JSSB.Append(_full); + return; + } + case SyntaxKind.MultiLineCommentTrivia: + case SyntaxKind.WhitespaceTrivia: + case SyntaxKind.EndOfLineTrivia: + case SyntaxKind.SkippedTokensTrivia: + { + string _full = trivia.ToFullString(); + JSSB.Append(_full); + return; + } + // Todo? how? convert to jsdoc? + case SyntaxKind.SingleLineDocumentationCommentTrivia: + case SyntaxKind.MultiLineDocumentationCommentTrivia: + { + //JSSB.Append("/**"); + string _full = trivia.ToFullString(); + JSSB.Append(_full); + //JSSB.AppendLine(""); + return; + } + default: + Log.ErrorLine($"Trivia : {trivia.Kind()}"); + break; + } + + base.VisitTrivia(trivia); + } + + public override void VisitToken(SyntaxToken token) + { + switch (token.Kind()) + { + //TODO? + case SyntaxKind.IdentifierToken: + { + VisitLeadingTrivia(token); + + JSSB.Append(token.Text.Replace("DollarSign_", "$")); + + VisitTrailingTrivia(token); + return; + } + case SyntaxKind.InKeyword: + case SyntaxKind.StaticKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.ReturnKeyword: + case SyntaxKind.ClassKeyword: + case SyntaxKind.OpenParenToken: + case SyntaxKind.CloseParenToken: + case SyntaxKind.SemicolonToken: + case SyntaxKind.CloseBraceToken: + case SyntaxKind.DotToken: + case SyntaxKind.EqualsToken: + case SyntaxKind.StringLiteralToken: + case SyntaxKind.ForKeyword: + case SyntaxKind.IfKeyword: + case SyntaxKind.GreaterThanEqualsToken: + case SyntaxKind.PlusPlusToken: + case SyntaxKind.PlusToken: + case SyntaxKind.LessThanToken: + case SyntaxKind.NumericLiteralToken: + case SyntaxKind.CommaToken: + case SyntaxKind.NewKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.MinusToken: + case SyntaxKind.MinusMinusToken: + case SyntaxKind.SlashToken: + case SyntaxKind.AsteriskToken: + case SyntaxKind.NullKeyword: + case SyntaxKind.BreakKeyword: + case SyntaxKind.CloseBracketToken: + case SyntaxKind.OpenBracketToken: + case SyntaxKind.EqualsGreaterThanToken: + case SyntaxKind.AwaitKeyword: + case SyntaxKind.AsyncKeyword: + case SyntaxKind.ElseKeyword: + case SyntaxKind.SwitchKeyword: + case SyntaxKind.CaseKeyword: + case SyntaxKind.ColonToken: + case SyntaxKind.DefaultKeyword: + case SyntaxKind.BarBarToken: + case SyntaxKind.ExclamationToken: + case SyntaxKind.ContinueKeyword: + case SyntaxKind.GreaterThanToken: + case SyntaxKind.AmpersandAmpersandToken: + case SyntaxKind.PlusEqualsToken: + case SyntaxKind.MinusEqualsToken: + case SyntaxKind.AsteriskEqualsToken: + case SyntaxKind.SlashEqualsToken: + case SyntaxKind.WhileKeyword: + case SyntaxKind.InterpolatedStringTextToken: + case SyntaxKind.QuestionToken: + case SyntaxKind.LessThanEqualsToken: + case SyntaxKind.ConstKeyword: + case SyntaxKind.PercentToken: + case SyntaxKind.QuestionQuestionToken: + case SyntaxKind.TildeToken: + case SyntaxKind.AmpersandToken: + case SyntaxKind.GreaterThanGreaterThanToken: + case SyntaxKind.LessThanLessThanToken: + case SyntaxKind.GreaterThanGreaterThanEqualsToken: + case SyntaxKind.LessThanLessThanEqualsToken: + case SyntaxKind.CaretEqualsToken: + case SyntaxKind.BarEqualsToken: + case SyntaxKind.AmpersandEqualsToken: + case SyntaxKind.BarToken: + case SyntaxKind.DoKeyword: + case SyntaxKind.ThrowStatement: + case SyntaxKind.CatchKeyword: + case SyntaxKind.TryKeyword: + case SyntaxKind.ThrowKeyword: + case SyntaxKind.FinallyKeyword: + case SyntaxKind.CaretToken: + case SyntaxKind.CharacterLiteralToken: + case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: + case SyntaxKind.PercentEqualsToken: + case SyntaxKind.QuestionQuestionEqualsToken: + case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken: + case SyntaxKind.TypeOfKeyword: + case SyntaxKind.ExclamationEqualsToken: + case SyntaxKind.EqualsEqualsToken: + case SyntaxKind.EndOfFileToken: + case SyntaxKind.OpenBraceToken: + { + VisitLeadingTrivia(token); + + JSSB.Append(token.Text); + + VisitTrailingTrivia(token); + return; + } + default: + Log.ErrorLine($"Token : {token.Kind()}"); + break; + } + + base.VisitToken(token); + } + + public override void VisitCompilationUnit(CompilationUnitSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.ClassDeclaration: + VisitClassDeclaration((ClassDeclarationSyntax)asNode); + break; + case SyntaxKind.GlobalStatement: + VisitGlobalStatement((GlobalStatementSyntax)asNode); + break; + case SyntaxKind.NamespaceDeclaration: + VisitNamespaceDeclaration((NamespaceDeclarationSyntax)asNode); + break; + case SyntaxKind.FileScopedNamespaceDeclaration: + VisitFileScopedNamespaceDeclaration((FileScopedNamespaceDeclarationSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.EndOfFileToken: + VisitToken(asToken); + break; + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } + public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.QualifiedName: + case SyntaxKind.IdentifierName: + break; + case SyntaxKind.ClassDeclaration: + VisitClassDeclaration((ClassDeclarationSyntax)asNode); + break; + case SyntaxKind.EnumDeclaration: + VisitEnumDeclaration((EnumDeclarationSyntax)asNode); + break; + case SyntaxKind.NamespaceDeclaration: + VisitNamespaceDeclaration((NamespaceDeclarationSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + //Todo? make a scope??? {...} + //OpenBraceToken and CloseBraceToken + case SyntaxKind.OpenBraceToken: + case SyntaxKind.CloseBraceToken: + case SyntaxKind.NamespaceKeyword: + break; + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } + public override void VisitFileScopedNamespaceDeclaration(FileScopedNamespaceDeclarationSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.QualifiedName: + case SyntaxKind.IdentifierName: + break; + case SyntaxKind.ClassDeclaration: + VisitClassDeclaration((ClassDeclarationSyntax)asNode); + break; + case SyntaxKind.EnumDeclaration: + VisitEnumDeclaration((EnumDeclarationSyntax)asNode); + break; + case SyntaxKind.NamespaceDeclaration: + VisitNamespaceDeclaration((NamespaceDeclarationSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.SemicolonToken: + case SyntaxKind.NamespaceKeyword: + break; + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } + + public override void VisitInvocationExpression(InvocationExpressionSyntax node) + { + if (node.Expression.HasAnnotation(BinaryAttribute.Annotation)) + { + VisitArgument(node.ArgumentList.Arguments[0]); + + if (!node.ArgumentList.Arguments[0].HasTrailingTrivia) + JSSB.Append(' '); + + JSSB.Append(node.Expression.ToString()); + + VisitTrailingTrivia(node.ArgumentList.Arguments.GetSeparator(0)); + + VisitArgument(node.ArgumentList.Arguments[1]); + return; + } + if (node.Expression.HasAnnotation(UnaryAttribute.Annotation)) + { + JSSB.Append(node.Expression.ToString()); + + if (!node.Expression.HasTrailingTrivia) + JSSB.Append(' '); + + VisitArgument(node.ArgumentList.Arguments[0]); + return; + } + base.VisitInvocationExpression(node); + } + public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node) + { + if (!node.Identifier.HasAnnotation(WithoutSemanticRewriter.StaticConstructor)) + base.VisitConstructorDeclaration(node); + else + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.ParameterList: + { + SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); + for (int _i = 0; _i < _syntaxTrivias.Count; _i++) + { + VisitTrivia(_syntaxTrivias[_i]); + } + _syntaxTrivias = asNode.GetTrailingTrivia(); + for (int _i = 0; _i < _syntaxTrivias.Count; _i++) + { + VisitTrivia(_syntaxTrivias[_i]); + } + break; + } + case SyntaxKind.Block: + VisitBlock((BlockSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.IdentifierToken: + { + VisitToken(asToken); + break; + } + default: + Log.ErrorLine($"asToken : {kind}"); + + break; + } + } + } + } + } + + + + + + //Can't do in "WithoutSemanticRewriter". Throws an error: + //An exception of type 'System.ArgumentException' occurred in Microsoft.CodeAnalysis.CSharp.dll but was not handled in user code: 'colonToken' + //Code: + /* + public override SyntaxNode? VisitBaseList(BaseListSyntax node) + { + node = (BaseListSyntax)base.VisitBaseList(node)!; + + node = node.ReplaceToken(node.ColonToken, SyntaxFactory.Token(SyntaxKind.None)); + + return node; + } + */ + public override void VisitBaseList(BaseListSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.SimpleBaseType: + VisitSimpleBaseType((SimpleBaseTypeSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.ColonToken: + { + VisitLeadingTrivia(asToken); + JSSB.Append("extends"); + VisitTrailingTrivia(asToken); + break; + } + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } + + //Can't replace a token. Same as VisitBaseList + //see "tokenInList" + //https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.syntaxnodeextensions.replacetoken?view=roslyn-dotnet-4.13.0#microsoft-codeanalysis-syntaxnodeextensions-replacetoken-1(-0-microsoft-codeanalysis-syntaxtoken-system-collections-generic-ienumerable((microsoft-codeanalysis-syntaxtoken))) + //"The token to be replaced. This must be a direct element of a SyntaxTokenList (such as a modifier in a list of modifiers), and a descendant of the root node. If the token is not part of a SyntaxTokenList, an InvalidOperationException will be thrown." + //But it throws a 'System.ArgumentException', not an 'InvalidOperationException': + //An exception of type 'System.ArgumentException' occurred in Microsoft.CodeAnalysis.CSharp.dll but was not handled in user code: 'stringStartToken' + //Code: + /* + public override SyntaxNode? VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax node) + { + node = (InterpolatedStringExpressionSyntax)base.VisitInterpolatedStringExpression(node)!; + node = node.ReplaceToken(node.StringStartToken, SyntaxFactory.Token(SyntaxKind.SingleQuoteToken)); + node = node.ReplaceToken(node.StringEndToken, SyntaxFactory.Token(SyntaxKind.SingleQuoteToken)); + return node; + } + */ + public override void VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.InterpolatedStringText: + VisitInterpolatedStringText((InterpolatedStringTextSyntax)asNode); + break; + case SyntaxKind.Interpolation: + { + JSSB.Append('$'); + VisitInterpolation((InterpolationSyntax)asNode); + break; + } + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.InterpolatedStringStartToken: + case SyntaxKind.InterpolatedStringEndToken: + JSSB.Append('`'); + break; + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } + public override void VisitInitializerExpression(InitializerExpressionSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.IdentifierName: + VisitIdentifierName((IdentifierNameSyntax)asNode); + break; + case SyntaxKind.ArgListExpression: + case SyntaxKind.NumericLiteralExpression: + case SyntaxKind.StringLiteralExpression: + case SyntaxKind.Utf8StringLiteralExpression: + case SyntaxKind.CharacterLiteralExpression: + case SyntaxKind.TrueLiteralExpression: + case SyntaxKind.FalseLiteralExpression: + case SyntaxKind.NullLiteralExpression: + case SyntaxKind.DefaultLiteralExpression: + VisitLiteralExpression((LiteralExpressionSyntax)asNode); + break; + case SyntaxKind.ObjectInitializerExpression: + case SyntaxKind.CollectionInitializerExpression: + case SyntaxKind.ArrayInitializerExpression: + case SyntaxKind.ComplexElementInitializerExpression: + case SyntaxKind.WithInitializerExpression: + VisitInitializerExpression((InitializerExpressionSyntax)asNode); + break; + case SyntaxKind.ObjectCreationExpression: + VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); + break; + case SyntaxKind.SimpleAssignmentExpression: + case SyntaxKind.AddAssignmentExpression: + case SyntaxKind.SubtractAssignmentExpression: + case SyntaxKind.MultiplyAssignmentExpression: + case SyntaxKind.DivideAssignmentExpression: + case SyntaxKind.ModuloAssignmentExpression: + case SyntaxKind.AndAssignmentExpression: + case SyntaxKind.ExclusiveOrAssignmentExpression: + case SyntaxKind.OrAssignmentExpression: + case SyntaxKind.LeftShiftAssignmentExpression: + case SyntaxKind.RightShiftAssignmentExpression: + case SyntaxKind.UnsignedRightShiftAssignmentExpression: + case SyntaxKind.CoalesceAssignmentExpression: + { + AssignmentExpressionSyntax _expr = (AssignmentExpressionSyntax)asNode; + Visit(_expr.Left); + + VisitLeadingTrivia(_expr.OperatorToken); + JSSB.Append(':'); + VisitTrailingTrivia(_expr.OperatorToken); + + Visit(_expr.Right); + break; + } + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.OpenBraceToken: + case SyntaxKind.CloseBraceToken: + { + VisitToken(asToken); + break; + } + case SyntaxKind.CommaToken: + VisitToken(asToken); + break; + default: + Log.ErrorLine($"asToken : {kind}"); + + break; + } + } + } + } + + //TODO? + //Try replace with "SyntaxFactory.InitializerExpression(SyntaxKind.ArrayInitializerExpression, SyntaxFactory.SeparatedList(enumMembers)))))))).WithTrailingTrivia(node.CloseBraceToken.TrailingTrivia);" + public override void VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.AnonymousObjectMemberDeclarator: + VisitAnonymousObjectMemberDeclarator((AnonymousObjectMemberDeclaratorSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.CommaToken: + case SyntaxKind.OpenBraceToken: + case SyntaxKind.CloseBraceToken: + VisitToken(asToken); + break; + case SyntaxKind.NewKeyword: + break; + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } + public override void VisitNameEquals(NameEqualsSyntax node) + { + ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); + + for (int i = 0; i < nodesAndTokens.Count; i++) + { + SyntaxNode? asNode = nodesAndTokens[i].AsNode(); + + if (asNode != null) + { + SyntaxKind kind = asNode.Kind(); + + switch (kind) + { + case SyntaxKind.IdentifierName: + VisitIdentifierName((IdentifierNameSyntax)asNode); + break; + default: + Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); + break; + } + } + else + { + SyntaxToken asToken = nodesAndTokens[i].AsToken(); + SyntaxKind kind = asToken.Kind(); + + switch (kind) + { + case SyntaxKind.EqualsToken: + { + VisitLeadingTrivia(asToken); + JSSB.Append(':'); + VisitTrailingTrivia(asToken); + break; + } + default: + Log.ErrorLine($"asToken : {kind}"); + break; + } + } + } + } +} diff --git a/CSharpToJavaScript/Utils/Attributes.cs b/CSharpToJavaScript/Utils/Attributes.cs index b7ad2ec2..3610e491 100644 --- a/CSharpToJavaScript/Utils/Attributes.cs +++ b/CSharpToJavaScript/Utils/Attributes.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.CodeAnalysis; +using System; namespace CSharpToJavaScript.Utils; @@ -76,6 +77,7 @@ public string Convert(string str) [AttributeUsage(AttributeTargets.All)] public class BinaryAttribute : Attribute { + public static SyntaxAnnotation Annotation { get; } = new(nameof(BinaryAttribute)); public string Value { get; init; } public BinaryAttribute(string value) { @@ -100,6 +102,7 @@ public GenericBinaryAttribute(string value) [AttributeUsage(AttributeTargets.All)] public class UnaryAttribute : Attribute { + public static SyntaxAnnotation Annotation { get; } = new(nameof(UnaryAttribute)); public string Value { get; init; } public UnaryAttribute(string value) { @@ -125,8 +128,8 @@ public GenericUnaryAttribute(string value) [AttributeUsage(AttributeTargets.All)] public class ToObjectAttribute : Attribute { - + public static SyntaxAnnotation Annotation { get; } = new(nameof(ToObjectAttribute)); } [AttributeUsage(AttributeTargets.Method)] -public class GenericAsArgument : Attribute { } \ No newline at end of file +public class GenericAsArgumentAttribute : Attribute { } \ No newline at end of file diff --git a/CSharpToJavaScript/Utils/NETAPI.cs b/CSharpToJavaScript/Utils/NETAPI.cs index 6554b5cc..63bd18c5 100644 --- a/CSharpToJavaScript/Utils/NETAPI.cs +++ b/CSharpToJavaScript/Utils/NETAPI.cs @@ -6,7 +6,7 @@ internal class NETAPI { - private readonly TypeName[] _TypeNames = new TypeName[8]; + private readonly TypeName[] _TypeNames = new TypeName[9]; public NETAPI() { @@ -38,6 +38,7 @@ public NETAPI() _TypeNames[2].Name = nameof(System.Collections.Generic.List); _TypeNames[2].JSName = "Array"; + _TypeNames[2].SymbolNames.Add(".ctor", "Array"); _TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List.Sort), "sort"); _TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List.FindLast), "findLast"); _TypeNames[2].SymbolNames.Add(nameof(System.Collections.Generic.List.Count), "length"); @@ -60,7 +61,7 @@ public NETAPI() // _TypeNames[4] = new(); _TypeNames[4].Name = nameof(System.String); - _TypeNames[4].JSName = "string"; + _TypeNames[4].JSName = "String"; _TypeNames[4].SymbolNames.Add(nameof(string.Contains), "includes"); _TypeNames[4].SymbolNames.Add(nameof(string.Length), "length"); @@ -73,6 +74,7 @@ public NETAPI() _TypeNames[4].SymbolNames.Add(nameof(string.ToUpper), "toUpperCase"); _TypeNames[4].SymbolNames.Add(nameof(string.ToLower), "toLowerCase"); _TypeNames[4].SymbolNames.Add(nameof(string.EndsWith), "endsWith"); + _TypeNames[4].SymbolNames.Add(nameof(string.Empty), "raw``"); // // @@ -104,6 +106,13 @@ public NETAPI() _TypeNames[7].SymbolNames.Add(nameof(System.Math.Exp), "exp"); _TypeNames[7].SymbolNames.Add(nameof(System.Math.Abs), "abs"); _TypeNames[7].SymbolNames.Add(nameof(System.Math.Max), "max"); + + // + // + // + _TypeNames[8] = new(); + _TypeNames[8].Name = nameof(System.Object); + _TypeNames[8].JSName = "Object"; } public string? ReturnJSString(string typeName, string? symbolName = null) diff --git a/CSharpToJavaScript/Walker.cs b/CSharpToJavaScript/Walker.cs deleted file mode 100644 index ea6969b4..00000000 --- a/CSharpToJavaScript/Walker.cs +++ /dev/null @@ -1,6761 +0,0 @@ -using CSharpToJavaScript.Utils; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Globalization; -using System.Linq; -using System.Text; - - -namespace CSharpToJavaScript; - -//Useful links: -//https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/syntax-analysis -//https://roslynquoter.azurewebsites.net/ -//https://sourceroslyn.io/ -//https://sharplab.io/ - -internal class Walker : CSharpSyntaxWalker -{ - public StringBuilder JSSB { get; set; } = new(); - - private readonly NETAPI _NETAPI = new(); - - private readonly CSTOJSOptions _Options; - private readonly SemanticModel _Model; - - private SyntaxNode? _SNBaseConstructorInitializerNode = null; - private SyntaxNode? _SNPropertyType = null; - private SyntaxNode? _SNAdditionalArgument = null; - - private ITypeSymbol? _CurrentClassSymbol = null; - - private string _NameSpaceStr = string.Empty; - - private List _Properties = new(); - - private bool _PropertyStatic = false; - private bool _ConstKeyword = false; - private bool _IgnoreArrayType = false; - private bool _IgnoreAsParenthesis = false; - private bool _IgnoreTailingDot = false; - private bool _GlobalStatement = false; - private bool _ThisIsUsed = false; - private bool _IsArrayInitializer = false; - private bool _GenericAsArgument = false; - - private int _EnumMembers = 0; - - private string[] _AttributeDatasForInvocation = new string[3] { string.Empty, string.Empty, string.Empty }; - - public Walker(CSTOJSOptions options, SemanticModel model) : base(SyntaxWalkerDepth.Trivia) - { - _Options = options; - _Model = model; - } - - public override void VisitTrivia(SyntaxTrivia trivia) - { - switch (trivia.Kind()) - { - case SyntaxKind.SingleLineCommentTrivia: - { - string _full = trivia.ToString(); - - //special syntax. - //for writing js code //...\\ - if (_full.EndsWith(@"\\")) - JSSB.Append(_full.AsSpan(2, _full.Length - 4)); - else - JSSB.Append(_full); - return; - } - case SyntaxKind.MultiLineCommentTrivia: - case SyntaxKind.WhitespaceTrivia: - { - string _full = trivia.ToFullString(); - JSSB.Append(_full); - return; - } - case SyntaxKind.EndOfLineTrivia: - { - string _full = trivia.ToFullString(); - JSSB.Append(_full); - return; - } - // Todo? how? convert to jsdoc? - case SyntaxKind.SingleLineDocumentationCommentTrivia: - case SyntaxKind.MultiLineDocumentationCommentTrivia: - { - //JSSB.Append("/**"); - string _full = trivia.ToFullString(); - JSSB.Append(_full); - //JSSB.AppendLine(""); - return; - } - //TODO??? - case SyntaxKind.SkippedTokensTrivia: - { - string _full = trivia.ToFullString(); - JSSB.Append(_full); - return; - } - default: - Log.ErrorLine($"Trivia : {trivia.Kind()}"); - break; - } - - base.VisitTrivia(trivia); - } - - public override void VisitToken(SyntaxToken token) - { - switch (token.Kind()) - { - //TODO? - case SyntaxKind.IdentifierToken: - { - VisitLeadingTrivia(token); - - JSSB.Append(token.Text.Replace("DollarSign_", "$")); - - VisitTrailingTrivia(token); - return; - } - case SyntaxKind.InKeyword: - case SyntaxKind.StaticKeyword: - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - case SyntaxKind.ReturnKeyword: - case SyntaxKind.ClassKeyword: - case SyntaxKind.OpenParenToken: - case SyntaxKind.CloseParenToken: - case SyntaxKind.SemicolonToken: - case SyntaxKind.CloseBraceToken: - case SyntaxKind.DotToken: - case SyntaxKind.EqualsToken: - case SyntaxKind.StringLiteralToken: - case SyntaxKind.ForKeyword: - case SyntaxKind.IfKeyword: - case SyntaxKind.GreaterThanEqualsToken: - case SyntaxKind.PlusPlusToken: - case SyntaxKind.PlusToken: - case SyntaxKind.LessThanToken: - case SyntaxKind.NumericLiteralToken: - case SyntaxKind.CommaToken: - case SyntaxKind.NewKeyword: - case SyntaxKind.ThisKeyword: - case SyntaxKind.MinusToken: - case SyntaxKind.MinusMinusToken: - case SyntaxKind.SlashToken: - case SyntaxKind.AsteriskToken: - case SyntaxKind.NullKeyword: - case SyntaxKind.BreakKeyword: - case SyntaxKind.CloseBracketToken: - case SyntaxKind.OpenBracketToken: - case SyntaxKind.EqualsGreaterThanToken: - case SyntaxKind.AwaitKeyword: - case SyntaxKind.AsyncKeyword: - case SyntaxKind.ElseKeyword: - case SyntaxKind.SwitchKeyword: - case SyntaxKind.CaseKeyword: - case SyntaxKind.ColonToken: - case SyntaxKind.DefaultKeyword: - case SyntaxKind.BarBarToken: - case SyntaxKind.ExclamationToken: - case SyntaxKind.ContinueKeyword: - case SyntaxKind.GreaterThanToken: - case SyntaxKind.AmpersandAmpersandToken: - case SyntaxKind.PlusEqualsToken: - case SyntaxKind.MinusEqualsToken: - case SyntaxKind.AsteriskEqualsToken: - case SyntaxKind.SlashEqualsToken: - case SyntaxKind.WhileKeyword: - case SyntaxKind.InterpolatedStringTextToken: - case SyntaxKind.QuestionToken: - case SyntaxKind.LessThanEqualsToken: - case SyntaxKind.ConstKeyword: - case SyntaxKind.PercentToken: - case SyntaxKind.QuestionQuestionToken: - case SyntaxKind.TildeToken: - case SyntaxKind.AmpersandToken: - case SyntaxKind.GreaterThanGreaterThanToken: - case SyntaxKind.LessThanLessThanToken: - case SyntaxKind.GreaterThanGreaterThanEqualsToken: - case SyntaxKind.LessThanLessThanEqualsToken: - case SyntaxKind.CaretEqualsToken: - case SyntaxKind.BarEqualsToken: - case SyntaxKind.AmpersandEqualsToken: - case SyntaxKind.BarToken: - case SyntaxKind.DoKeyword: - case SyntaxKind.ThrowStatement: - case SyntaxKind.CatchKeyword: - case SyntaxKind.TryKeyword: - case SyntaxKind.ThrowKeyword: - case SyntaxKind.FinallyKeyword: - case SyntaxKind.CaretToken: - case SyntaxKind.CharacterLiteralToken: - case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: - case SyntaxKind.PercentEqualsToken: - case SyntaxKind.QuestionQuestionEqualsToken: - case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken: - case SyntaxKind.TypeOfKeyword: - case SyntaxKind.ExclamationEqualsToken: - case SyntaxKind.EqualsEqualsToken: - { - VisitLeadingTrivia(token); - - JSSB.Append(token.Text); - - VisitTrailingTrivia(token); - return; - } - case SyntaxKind.EndOfFileToken: - { - VisitLeadingTrivia(token); - - JSSB.Append(token.Text); - - VisitTrailingTrivia(token); - - ImmutableArray diagnostics = _Model.GetDiagnostics(); - for (int i = 0; i < diagnostics.Length; i++) - { - if (_Options.Debug) - Log.WarningLine(diagnostics[i].ToString()); - - //print an error if compilation fails - if (diagnostics[i].Severity == DiagnosticSeverity.Error) - { - if(_Options.DisableCompilationErrors == false) - Log.ErrorLine(diagnostics[i].ToString()); - } - } - return; - } - case SyntaxKind.OpenBraceToken: - { - if(!_Options.KeepBraceOnTheSameLine) - VisitLeadingTrivia(token); - - JSSB.Append(token.Text); - - VisitTrailingTrivia(token); - return; - } - default: - Log.ErrorLine($"Token : {token.Kind()}"); - break; - } - - base.VisitToken(token); - } - public override void VisitClassDeclaration(ClassDeclarationSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.DestructorDeclaration: - case SyntaxKind.IndexerDeclaration: - case SyntaxKind.DelegateDeclaration: - case SyntaxKind.EventFieldDeclaration: - case SyntaxKind.TypeParameterConstraintClause: - case SyntaxKind.EventDeclaration: - case SyntaxKind.StructDeclaration: - case SyntaxKind.OperatorDeclaration: - case SyntaxKind.ConversionOperatorDeclaration: - case SyntaxKind.AttributeList: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.TypeParameterList: - { - SyntaxTriviaList _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - break; - } - case SyntaxKind.ClassDeclaration: - VisitClassDeclaration((ClassDeclarationSyntax)asNode); - break; - case SyntaxKind.BaseList: - { - BaseListSyntax _baseList = (BaseListSyntax)asNode; - VisitBaseList(_baseList); - break; - } - case SyntaxKind.FieldDeclaration: - VisitFieldDeclaration((FieldDeclarationSyntax)asNode); - break; - case SyntaxKind.ConstructorDeclaration: - VisitConstructorDeclaration((ConstructorDeclarationSyntax)asNode); - break; - case SyntaxKind.MethodDeclaration: - VisitMethodDeclaration((MethodDeclarationSyntax)asNode); - break; - case SyntaxKind.PropertyDeclaration: - VisitPropertyDeclaration((PropertyDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.SealedKeyword: - case SyntaxKind.UnsafeKeyword: - case SyntaxKind.PartialKeyword: - case SyntaxKind.StaticKeyword: - break; - case SyntaxKind.InternalKeyword: - case SyntaxKind.PublicKeyword: - VisitLeadingTrivia(asToken); - break; - case SyntaxKind.OpenBraceToken: - case SyntaxKind.CloseBraceToken: - case SyntaxKind.ClassKeyword: - VisitToken(asToken); - break; - case SyntaxKind.IdentifierToken: - { - _CurrentClassSymbol = _Model.GetDeclaredSymbol(node); - - VisitToken(asToken); - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - - - //clear properties - if (_Options.MakePropertiesEnumerable) - { - _Properties.Clear(); - } - } - - public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.AttributeList: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.BaseConstructorInitializer: - { - _SNBaseConstructorInitializerNode = asNode; - SyntaxTriviaList _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - break; - } - case SyntaxKind.ParameterList: - VisitParameterList((ParameterListSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.StaticKeyword: - { - VisitToken(asToken); - - JSSB.AppendLine(); - - for (int j = 0; j < nodesAndTokens.Count; j++) - { - asNode = nodesAndTokens[j].AsNode(); - if (asNode != null) - { - if (asNode.IsKind(SyntaxKind.Block)) - { - VisitBlock((BlockSyntax)asNode); - break; - } - } - } - return; - } - case SyntaxKind.PublicKeyword: - VisitLeadingTrivia(asToken); - break; - case SyntaxKind.IdentifierToken: - { - VisitLeadingTrivia(asToken); - JSSB.Append("constructor"); - VisitTrailingTrivia(asToken); - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - - break; - } - } - } - } - - public override void VisitParameter(ParameterSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.AttributeList: - case SyntaxKind.ArrayType: - case SyntaxKind.NullableType: - case SyntaxKind.GenericName: - case SyntaxKind.IdentifierName: - case SyntaxKind.PredefinedType: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.EqualsValueClause: - { - VisitEqualsValueClause((EqualsValueClauseSyntax)asNode); - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OutKeyword: - case SyntaxKind.RefKeyword: - VisitLeadingTrivia(asToken); - break; - case SyntaxKind.IdentifierToken: - { - VisitToken(asToken); - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitCatchDeclaration(CatchDeclarationSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierName: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenParenToken: - case SyntaxKind.CloseParenToken: - case SyntaxKind.IdentifierToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitBlock(BlockSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.UsingStatement: - case SyntaxKind.LockStatement: - case SyntaxKind.FixedStatement: - case SyntaxKind.UnsafeStatement: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.ExpressionStatement: - VisitExpressionStatement((ExpressionStatementSyntax)asNode); - break; - case SyntaxKind.ForEachStatement: - VisitForEachStatement((ForEachStatementSyntax)asNode); - break; - case SyntaxKind.LocalDeclarationStatement: - VisitLocalDeclarationStatement((LocalDeclarationStatementSyntax)asNode); - break; - case SyntaxKind.IfStatement: - VisitIfStatement((IfStatementSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - case SyntaxKind.EmptyStatement: - VisitEmptyStatement((EmptyStatementSyntax)asNode); - break; - case SyntaxKind.TryStatement: - VisitTryStatement((TryStatementSyntax)asNode); - break; - case SyntaxKind.ThrowStatement: - VisitThrowStatement((ThrowStatementSyntax)asNode); - break; - case SyntaxKind.DoStatement: - VisitDoStatement((DoStatementSyntax)asNode); - break; - case SyntaxKind.ReturnStatement: - VisitReturnStatement((ReturnStatementSyntax)asNode); - break; - case SyntaxKind.ForStatement: - VisitForStatement((ForStatementSyntax)asNode); - break; - case SyntaxKind.BreakStatement: - VisitBreakStatement((BreakStatementSyntax)asNode); - break; - case SyntaxKind.SwitchStatement: - VisitSwitchStatement((SwitchStatementSyntax)asNode); - break; - case SyntaxKind.ContinueStatement: - VisitContinueStatement((ContinueStatementSyntax)asNode); - break; - case SyntaxKind.WhileStatement: - VisitWhileStatement((WhileStatementSyntax)asNode); - break; - case SyntaxKind.LocalFunctionStatement: - VisitLocalFunctionStatement((LocalFunctionStatementSyntax)asNode); - break; - case SyntaxKind.LabeledStatement: - VisitLabeledStatement((LabeledStatementSyntax)asNode); - break; - case SyntaxKind.ForEachVariableStatement: - VisitForEachVariableStatement((ForEachVariableStatementSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.CloseBraceToken: - VisitToken(asToken); - break; - case SyntaxKind.OpenBraceToken: - { - VisitToken(asToken); - if (_SNBaseConstructorInitializerNode != null) - { - SyntaxTriviaList _syntaxTrivias = asToken.LeadingTrivia; - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - JSSB.Append("\tsuper"); - Visit(((ConstructorInitializerSyntax)_SNBaseConstructorInitializerNode).ArgumentList); - //Todo! - //JSSB.Append(";"); - _SNBaseConstructorInitializerNode = null; - } - - if (_Options.MakePropertiesEnumerable) - { - for (int j = 0; j < _Properties.Count; j++) - { - SyntaxTriviaList _syntaxTrivias = _Properties[j].SNGet.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - JSSB.Append($"Object.defineProperty(this, '{_Properties[j].Name}', {{ enumerable: true,"); - if (_Properties[j].SNGet != null) - { - BlockSyntax? _body = ((AccessorDeclarationSyntax)_Properties[j].SNGet).Body; - - if (_body != null) - { - JSSB.Append($"get: function ()"); - - _syntaxTrivias = _Properties[j].SNGet.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - VisitBlock(_body); - } - else - { - if (_PropertyStatic == true) - JSSB.Append($"get: function () {{ return this._{_Properties[j].Name}_; }}"); - else - JSSB.Append($"get: function () {{ return this.#_{_Properties[j].Name}_; }}"); - - _syntaxTrivias = _Properties[j].SNGet.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - - JSSB.Append(","); - } - if (_Properties[j].SNSet != null) - { - BlockSyntax? _body = ((AccessorDeclarationSyntax)_Properties[j].SNSet).Body; - - if (_body != null) - { - if (_Properties[j].SNSet.Parent != null) - { - if (_Properties[j].SNSet.Parent.Parent != null) - { - _syntaxTrivias = _Properties[j].SNSet.Parent.Parent.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - Log.ErrorLine("_Properties[j].SNSet.Parent.Parent is null"); - - } - else - Log.ErrorLine("_Properties[j].SNSet.Parent is null"); - - - if (_PropertyStatic == true) - { - JSSB.Append($"static "); - _PropertyStatic = false; - } - JSSB.Append($"set: function (value)"); - - _syntaxTrivias = _Properties[j].SNSet.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - VisitBlock(_body); - } - else - { - JSSB.AppendLine(); - - if (_Properties[j].SNSet.Parent != null) - { - if (_Properties[j].SNSet.Parent.Parent != null) - { - _syntaxTrivias = _Properties[j].SNSet.Parent.Parent.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - Log.ErrorLine("_Properties[j].SNSet.Parent.Parent is null"); - - } - else - Log.ErrorLine("_Properties[j].SNSet.Parent is null"); - - if (_PropertyStatic == true) - { - JSSB.Append($"static "); - JSSB.Append($"set: function (value) {{ this._{_Properties[j].Name}_ = value; }}"); - _PropertyStatic = false; - } - else - JSSB.Append($"set: function (value) {{ this.#_{_Properties[j].Name}_ = value; }}"); - - if (_Properties[j].SNSet.Parent != null) - { - _syntaxTrivias = _Properties[j].SNSet.Parent.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - Log.ErrorLine("_Properties[j].SNSet.Parent is null"); - } - } - JSSB.AppendLine("} );"); - } - } - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.VariableDeclaration: - VisitVariableDeclaration((VariableDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.ConstKeyword: - { - _ConstKeyword = true; - VisitToken(asToken); - break; - } - case SyntaxKind.SemicolonToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitExpressionStatement(ExpressionStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.CoalesceExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.AnonymousObjectCreationExpression: - VisitAnonymousObjectCreationExpression((AnonymousObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedLambdaExpression: - VisitParenthesizedLambdaExpression((ParenthesizedLambdaExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleAssignmentExpression: - case SyntaxKind.AddAssignmentExpression: - case SyntaxKind.SubtractAssignmentExpression: - case SyntaxKind.MultiplyAssignmentExpression: - case SyntaxKind.DivideAssignmentExpression: - case SyntaxKind.ModuloAssignmentExpression: - case SyntaxKind.AndAssignmentExpression: - case SyntaxKind.ExclusiveOrAssignmentExpression: - case SyntaxKind.OrAssignmentExpression: - case SyntaxKind.LeftShiftAssignmentExpression: - case SyntaxKind.RightShiftAssignmentExpression: - case SyntaxKind.UnsignedRightShiftAssignmentExpression: - case SyntaxKind.CoalesceAssignmentExpression: - VisitAssignmentExpression((AssignmentExpressionSyntax)asNode); - break; - case SyntaxKind.ConditionalAccessExpression: - VisitConditionalAccessExpression((ConditionalAccessExpressionSyntax)asNode); - break; - case SyntaxKind.PostIncrementExpression: - case SyntaxKind.PostDecrementExpression: - case SyntaxKind.SuppressNullableWarningExpression: - VisitPostfixUnaryExpression((PostfixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.AwaitExpression: - VisitAwaitExpression((AwaitExpressionSyntax)asNode); - break; - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.ConditionalExpression: - VisitConditionalExpression((ConditionalExpressionSyntax)asNode); - break; - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.SemicolonToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitArgument(ArgumentSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.NameColon: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.AwaitExpression: - VisitAwaitExpression((AwaitExpressionSyntax)asNode); - break; - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.CoalesceExpression: - case SyntaxKind.AsExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.ImplicitObjectCreationExpression: - VisitImplicitObjectCreationExpression((ImplicitObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.AnonymousObjectCreationExpression: - VisitAnonymousObjectCreationExpression((AnonymousObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - { - //??? - bool _l = _ThisIsUsed; - _ThisIsUsed = false; - VisitIdentifierName((IdentifierNameSyntax)asNode); - _ThisIsUsed = _l; - break; - } - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - { - //Literal expressions cannot have this.. so mark it as used! - bool _l = _ThisIsUsed; - _ThisIsUsed = true; - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - _ThisIsUsed = _l; - break; - } - case SyntaxKind.PostIncrementExpression: - case SyntaxKind.PostDecrementExpression: - case SyntaxKind.SuppressNullableWarningExpression: - VisitPostfixUnaryExpression((PostfixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleAssignmentExpression: - case SyntaxKind.AddAssignmentExpression: - case SyntaxKind.SubtractAssignmentExpression: - case SyntaxKind.MultiplyAssignmentExpression: - case SyntaxKind.DivideAssignmentExpression: - case SyntaxKind.ModuloAssignmentExpression: - case SyntaxKind.AndAssignmentExpression: - case SyntaxKind.ExclusiveOrAssignmentExpression: - case SyntaxKind.OrAssignmentExpression: - case SyntaxKind.LeftShiftAssignmentExpression: - case SyntaxKind.RightShiftAssignmentExpression: - case SyntaxKind.UnsignedRightShiftAssignmentExpression: - case SyntaxKind.CoalesceAssignmentExpression: - VisitAssignmentExpression((AssignmentExpressionSyntax)asNode); - break; - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.TypeOfExpression: - VisitTypeOfExpression((TypeOfExpressionSyntax)asNode); - break; - case SyntaxKind.ConditionalExpression: - VisitConditionalExpression((ConditionalExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleLambdaExpression: - VisitSimpleLambdaExpression((SimpleLambdaExpressionSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedLambdaExpression: - VisitParenthesizedLambdaExpression((ParenthesizedLambdaExpressionSyntax)asNode); - break; - case SyntaxKind.InterpolatedStringExpression: - VisitInterpolatedStringExpression((InterpolatedStringExpressionSyntax)asNode); - break; - case SyntaxKind.CastExpression: - VisitCastExpression((CastExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitMemberAccessExpression(MemberAccessExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - _ThisIsUsed = false; - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.BaseExpression: - VisitBaseExpression((BaseExpressionSyntax)asNode); - break; - case SyntaxKind.GenericName: - VisitGenericName((GenericNameSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - { - IdentifierNameSyntax identifierName = (IdentifierNameSyntax)asNode; - VisitIdentifierName(identifierName); - break; - } - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.PredefinedType: - { - //TODO! other types! - // - - //this is string.Empty - JSSB.Append("\"\""); - SyntaxTriviaList _syntaxTrivias = nodesAndTokens[nodesAndTokens.Count - 1].GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - return; - } - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.MemberBindingExpression: - VisitMemberBindingExpression((MemberBindingExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.DotToken: - { - if (_IgnoreTailingDot) - _IgnoreTailingDot = false; - else - VisitToken(asToken); - - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.AnonymousObjectMemberDeclarator: - VisitAnonymousObjectMemberDeclarator((AnonymousObjectMemberDeclaratorSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.CommaToken: - case SyntaxKind.OpenBraceToken: - case SyntaxKind.CloseBraceToken: - VisitToken(asToken); - break; - case SyntaxKind.NewKeyword: - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitEnumDeclaration(EnumDeclarationSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.AttributeList: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.EnumMemberDeclaration: - VisitEnumMemberDeclaration((EnumMemberDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.PrivateKeyword: - case SyntaxKind.PublicKeyword: - VisitLeadingTrivia(asToken); - break; - case SyntaxKind.EnumKeyword: - { - VisitLeadingTrivia(asToken); - JSSB.Append("const"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.IdentifierToken: - { - VisitLeadingTrivia(asToken); - VisitToken(asToken.WithoutTrivia()); - JSSB.Append(" = "); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.CommaToken: - case SyntaxKind.OpenBraceToken: - VisitToken(asToken); - break; - case SyntaxKind.CloseBraceToken: - { - VisitToken(asToken); - _EnumMembers = 0; - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.EqualsValueClause: - { - JSSB.Append(": "); - ExpressionSyntax _value = ((EqualsValueClauseSyntax)asNode).Value; - if(_value is LiteralExpressionSyntax) - VisitLiteralExpression((LiteralExpressionSyntax)_value); - else - Log.ErrorLine($"asNode : _value is {_value.Kind()}\n|{asNode.ToFullString()}|"); - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierToken: - { - if (nodesAndTokens.Count == 1) - { - VisitLeadingTrivia(asToken); - VisitToken(asToken.WithoutTrivia()); - JSSB.Append($" : {_EnumMembers++}"); - VisitTrailingTrivia(asToken); - } - else - VisitToken(asToken); - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitNameEquals(NameEqualsSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.EqualsToken: - { - VisitLeadingTrivia(asToken); - JSSB.Append(':'); - VisitTrailingTrivia(asToken); - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitMethodDeclaration(MethodDeclarationSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.NullableType: - case SyntaxKind.TypeParameterList: - case SyntaxKind.TypeParameterConstraintClause: - case SyntaxKind.AttributeList: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.IdentifierName: - case SyntaxKind.GenericName: - case SyntaxKind.PredefinedType: - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - break; - } - //case SyntaxKind.IdentifierName: - // VisitIdentifierName((IdentifierNameSyntax)asNode); - // break; - case SyntaxKind.ParameterList: - VisitParameterList((ParameterListSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.AbstractKeyword: - case SyntaxKind.SealedKeyword: - case SyntaxKind.NewKeyword: - case SyntaxKind.OverrideKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.VirtualKeyword: - case SyntaxKind.PartialKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.PublicKeyword: - VisitLeadingTrivia(asToken); - break; - case SyntaxKind.StaticKeyword: - case SyntaxKind.AsyncKeyword: - case SyntaxKind.IdentifierToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitFieldDeclaration(FieldDeclarationSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.AttributeList: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.VariableDeclaration: - VisitVariableDeclaration((VariableDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.StaticKeyword: - case SyntaxKind.SemicolonToken: - VisitToken(asToken); - break; - case SyntaxKind.ReadOnlyKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - VisitLeadingTrivia(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - FieldDeclarationSyntax? field = null; - - bool hasDefault = false; - - SyntaxNode? defaultValue = nodesAndTokens.FirstOrDefault(n => n.IsKind(SyntaxKind.EqualsValueClause)).AsNode(); - if (defaultValue != default) - hasDefault = true; - - if(nodesAndTokens.Any(n => n.IsKind(SyntaxKind.StaticKeyword))) - _PropertyStatic = true; - - for (int i = nodesAndTokens.Count - 1; i >= 0; i--) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - if (kind == SyntaxKind.AccessorList) - { - string _getSetStr = asNode.ToString().Trim().Replace(" ", ""); - - if (_getSetStr == "{get;set;}" || _getSetStr == "{get;}") - { - IEnumerable key = from n in nodesAndTokens - where n.IsNode - where n.AsNode().IsKind(SyntaxKind.PredefinedType) - select n; - - string _indentifier = "_" + nodesAndTokens[i - 1].AsToken().ToString() + "_"; - - if (!_PropertyStatic) - _indentifier = "#" + _indentifier; - - if (!key.Any()) - { - key = from n in nodesAndTokens - where n.IsNode - where n.AsNode().IsKind(SyntaxKind.IdentifierName) - select n; - - if (!key.Any()) - { - key = from n in nodesAndTokens - where n.IsNode - where n.AsNode().IsKind(SyntaxKind.GenericName) - select n; - } - - if (!key.Any()) - { - key = from n in nodesAndTokens - where n.IsNode - where n.AsNode().IsKind(SyntaxKind.NullableType) - select n; - } - - _SNPropertyType = key.FirstOrDefault().AsNode(); - - // - // - //TODO! change this mess! - if (hasDefault) - { - field = SyntaxFactory.FieldDeclaration( - SyntaxFactory.VariableDeclaration(SyntaxFactory.IdentifierName(key.First().ToString())) - .WithVariables( - SyntaxFactory.SingletonSeparatedList( - SyntaxFactory.VariableDeclarator( - SyntaxFactory.Identifier(_indentifier)) - .WithInitializer(defaultValue as EqualsValueClauseSyntax)))) - .WithModifiers( - SyntaxFactory.TokenList(new[] - { - SyntaxFactory.Token(SyntaxKind.PrivateKeyword) - })) - .WithLeadingTrivia(node.GetLeadingTrivia()) - .WithTrailingTrivia(node.GetTrailingTrivia()); - } - else - { - field = SyntaxFactory.FieldDeclaration( - SyntaxFactory.VariableDeclaration(SyntaxFactory.IdentifierName(key.First().ToString())) - .WithVariables( - SyntaxFactory.SingletonSeparatedList( - SyntaxFactory.VariableDeclarator( - SyntaxFactory.Identifier(_indentifier))))) - .WithModifiers( - SyntaxFactory.TokenList(new[] - { - SyntaxFactory.Token(SyntaxKind.PrivateKeyword) - })) - .WithLeadingTrivia(node.GetLeadingTrivia()) - .WithTrailingTrivia(node.GetTrailingTrivia()); - } - } - else - { - _SNPropertyType = key.First().AsNode(); - - key = key.First().ChildNodesAndTokens(); - - if (hasDefault) - { - field = SyntaxFactory.FieldDeclaration( - SyntaxFactory.VariableDeclaration( - SyntaxFactory.PredefinedType(SyntaxFactory.Token(key.First().Kind()))) - .WithVariables( - SyntaxFactory.SingletonSeparatedList( - SyntaxFactory.VariableDeclarator( - SyntaxFactory.Identifier(_indentifier)) - .WithInitializer(defaultValue as EqualsValueClauseSyntax)))) - .WithModifiers( - SyntaxFactory.TokenList(new[] - { - SyntaxFactory.Token(SyntaxKind.PrivateKeyword) - })) - .WithLeadingTrivia(node.GetLeadingTrivia()) - .WithTrailingTrivia(node.GetTrailingTrivia()); - } - else - { - field = SyntaxFactory.FieldDeclaration( - SyntaxFactory.VariableDeclaration( - SyntaxFactory.PredefinedType(SyntaxFactory.Token(key.First().Kind()))) - .WithVariables( - SyntaxFactory.SingletonSeparatedList( - SyntaxFactory.VariableDeclarator( - SyntaxFactory.Identifier(_indentifier))))) - .WithModifiers( - SyntaxFactory.TokenList(new[] - { - SyntaxFactory.Token(SyntaxKind.PrivateKeyword) - })) - .WithLeadingTrivia(node.GetLeadingTrivia()) - .WithTrailingTrivia(node.GetTrailingTrivia()); - } - } - - break; - } - } - } - - } - - if (field != null) - { - VisitFieldDeclaration(field); - _SNPropertyType = null; - } - - //main for loop for property - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.EqualsValueClause: - case SyntaxKind.AttributeList: - case SyntaxKind.PredefinedType: - case SyntaxKind.IdentifierName: - case SyntaxKind.NullableType: - case SyntaxKind.GenericName: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.AccessorList: - VisitAccessorList((AccessorListSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierToken: - { - if (_Options.MakePropertiesEnumerable) - _Properties.Add(new() { Name = asToken.Text }); - break; - } - case SyntaxKind.AbstractKeyword: - case SyntaxKind.RequiredKeyword: - case SyntaxKind.SemicolonToken: - VisitTrailingTrivia(asToken); - break; - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - VisitLeadingTrivia(asToken); - break; - case SyntaxKind.StaticKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitAccessorList(AccessorListSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.GetAccessorDeclaration: - { - if (_Options.MakePropertiesEnumerable) - { - _Properties[_Properties.Count - 1].SNGet = asNode; - break; - } - IEnumerable c = asNode.Ancestors(); - - IEnumerable a = from b in c - where b.IsKind(SyntaxKind.PropertyDeclaration) - select b; - IEnumerable d2 = from e in a.First().ChildNodesAndTokens() - where e.IsKind(SyntaxKind.IdentifierToken) - select e; - - dynamic? d3 = null; - if (d2.Count() >= 2) - { - //Delete this? TODO - d2 = from e in a.First().DescendantNodesAndTokens() - where e.IsKind(SyntaxKind.IdentifierName) - select e; - d3 = d2.First().ChildNodesAndTokens().First().AsToken(); - }else - d3 = d2.First().AsToken(); - - BlockSyntax? _body = ((AccessorDeclarationSyntax)asNode).Body; - - if (_body != null) - { - //SyntaxTriviaList _syntaxTrivias = asNode.Parent!.Parent!.GetLeadingTrivia(); - /* Todo! Why there is already "/t/t" in JSSB???? - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - */ - - JSSB.Append($"get {d3.Text}()"); - - SyntaxTriviaList _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - VisitBlock(_body); - } - else - { - //JSSB.Append($"\n"); - - //SyntaxTriviaList _syntaxTrivias = asNode.Parent.Parent.GetLeadingTrivia(); - /* Todo! Why there is already "/t/t" in JSSB???? - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - }*/ - - if (_PropertyStatic == true) - { - JSSB.Append($"get {d3.Text}() {{ return this._{d3.Text}_; }}"); - } - else - JSSB.Append($"get {d3.Text}() {{ return this.#_{d3.Text}_; }}"); - - SyntaxTriviaList _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - - break; - } - case SyntaxKind.SetAccessorDeclaration: - { - if (_Options.MakePropertiesEnumerable) - { - _Properties[_Properties.Count - 1].SNSet = asNode; - break; - } - - IEnumerable c = asNode.Ancestors(); - - IEnumerable a = from b in c - where b.IsKind(SyntaxKind.PropertyDeclaration) - select b; - IEnumerable d2 = from e in a.First().ChildNodesAndTokens() - where e.IsKind(SyntaxKind.IdentifierToken) - select e; - - SyntaxToken d3 = d2.First().AsToken(); - - BlockSyntax? _body = ((AccessorDeclarationSyntax)asNode).Body; - - if (_body != null) - { - SyntaxTriviaList _syntaxTrivias; - - if (asNode.Parent != null) - { - if (asNode.Parent.Parent != null) - { - _syntaxTrivias = asNode.Parent.Parent.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - Log.ErrorLine("asNode.Parent.Parent is null"); - - } - else - Log.ErrorLine("asNode.Parent is null"); - - - if (_PropertyStatic == true) - { - JSSB.Append($"static "); - _PropertyStatic = false; - } - JSSB.Append($"set {d3.Text}(value)"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - VisitBlock(_body); - } - else - { - JSSB.AppendLine(); - - SyntaxTriviaList _syntaxTrivias; - - if (asNode.Parent != null) - { - if (asNode.Parent.Parent != null) - { - _syntaxTrivias = asNode.Parent.Parent.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - Log.ErrorLine("asNode.Parent.Parent is null"); - - } - else - Log.ErrorLine("asNode.Parent is null"); - - if (_PropertyStatic == true) - { - JSSB.Append($"static "); - JSSB.Append($"set {d3.Text}(value) {{ this._{d3.Text}_ = value; }}"); - _PropertyStatic = false; - }else - JSSB.Append($"set {d3.Text}(value) {{ this.#_{d3.Text}_ = value; }}"); - - if (asNode.Parent != null) - { - _syntaxTrivias = asNode.Parent.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - Log.ErrorLine("asNode.Parent is null"); - } - - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenBraceToken: - case SyntaxKind.CloseBraceToken: - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitBaseList(BaseListSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.SimpleBaseType: - VisitSimpleBaseType((SimpleBaseTypeSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.ColonToken: - { - VisitLeadingTrivia(asToken); - JSSB.Append("extends"); - VisitTrailingTrivia(asToken); - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitVariableDeclaration(VariableDeclarationSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.RefType: - case SyntaxKind.ArrayType: - case SyntaxKind.NullableType: - case SyntaxKind.PredefinedType: - case SyntaxKind.IdentifierName: - case SyntaxKind.GenericName: - { - if (node.Parent.IsKind(SyntaxKind.LocalDeclarationStatement) || - node.Parent.IsKind(SyntaxKind.ForStatement)) - { - if (_ConstKeyword == true) - _ConstKeyword = false; - else - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - if (_Options.UseVarOverLet) - JSSB.Append("var"); - else - JSSB.Append("let"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - } - break; - } - case SyntaxKind.VariableDeclarator: - VisitVariableDeclarator((VariableDeclaratorSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.CommaToken: - case SyntaxKind.SemicolonToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitPredefinedType(PredefinedTypeSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.PredefinedType: - VisitPredefinedType((PredefinedTypeSyntax)asNode); - break; - case SyntaxKind.VariableDeclarator: - VisitVariableDeclarator((VariableDeclaratorSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - /*TODO! - case SyntaxKind.IntKeyword: - { - JSSB.Append("Number"); - break; - }*/ - //case SyntaxKind.BoolKeyword: - case SyntaxKind.ObjectKeyword: - JSSB.Append("Object"); - break; - case SyntaxKind.SemicolonToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitVariableDeclarator(VariableDeclaratorSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.EqualsValueClause: - VisitEqualsValueClause((EqualsValueClauseSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitForEachStatement(ForEachStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - case SyntaxKind.ExpressionStatement: - VisitExpressionStatement((ExpressionStatementSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - case SyntaxKind.GenericName: - case SyntaxKind.PredefinedType: - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - if (_Options.UseVarOverLet) - JSSB.Append("var"); - else - JSSB.Append("let"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - break; - } - case SyntaxKind.IdentifierName: - { - IdentifierNameSyntax? _ins = asNode as IdentifierNameSyntax; - if (_ins != null) - { - if (_ins.IsVar) - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - if (_Options.UseVarOverLet) - JSSB.Append("var"); - else - JSSB.Append("let"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - { - if (IdentifierToken(asNode) == false) - { - VisitIdentifierName(_ins); - } - } - } - else - { - Log.ErrorLine($"_ins is null"); - } - - break; - } - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - - case SyntaxKind.IdentifierToken: - { - VisitLeadingTrivia(asToken); - JSSB.Append($"{asToken.Text}"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.ForEachKeyword: - { - VisitLeadingTrivia(asToken); - JSSB.Append("for"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.InKeyword: - { - VisitLeadingTrivia(asToken); - JSSB.Append("of"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.CloseParenToken: - case SyntaxKind.OpenParenToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - - public override void VisitArrayCreationExpression(ArrayCreationExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ArrayType: - { - //Todo? - //Check if third element is ArrayInitializerExpression - if (nodesAndTokens.Count >= 3) - _IgnoreArrayType = true; - VisitArrayType((ArrayTypeSyntax)asNode); - _IgnoreArrayType = false; - break; - } - case SyntaxKind.ArrayInitializerExpression: - { - _IsArrayInitializer = true; - VisitInitializerExpression((InitializerExpressionSyntax)asNode); - _IsArrayInitializer = false; - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.NewKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitArrayType(ArrayTypeSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.NullableType: - case SyntaxKind.PredefinedType: - case SyntaxKind.IdentifierName: - JSSB.Append("Array"); - break; - case SyntaxKind.ArrayRankSpecifier: - VisitArrayRankSpecifier((ArrayRankSpecifierSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitArrayRankSpecifier(ArrayRankSpecifierSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.CoalesceExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - //Todo? - case SyntaxKind.OmittedArraySizeExpression: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenBracketToken: - { - if (_IgnoreArrayType == false) - { - VisitLeadingTrivia(asToken); - JSSB.Append('('); - VisitTrailingTrivia(asToken); - } - break; - } - case SyntaxKind.CloseBracketToken: - { - if (_IgnoreArrayType == false) - { - VisitLeadingTrivia(asToken); - JSSB.Append(')'); - VisitTrailingTrivia(asToken); - } - break; - } - case SyntaxKind.CommaToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitInitializerExpression(InitializerExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectInitializerExpression: - case SyntaxKind.CollectionInitializerExpression: - case SyntaxKind.ArrayInitializerExpression: - case SyntaxKind.ComplexElementInitializerExpression: - case SyntaxKind.WithInitializerExpression: - VisitInitializerExpression((InitializerExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleAssignmentExpression: - case SyntaxKind.AddAssignmentExpression: - case SyntaxKind.SubtractAssignmentExpression: - case SyntaxKind.MultiplyAssignmentExpression: - case SyntaxKind.DivideAssignmentExpression: - case SyntaxKind.ModuloAssignmentExpression: - case SyntaxKind.AndAssignmentExpression: - case SyntaxKind.ExclusiveOrAssignmentExpression: - case SyntaxKind.OrAssignmentExpression: - case SyntaxKind.LeftShiftAssignmentExpression: - case SyntaxKind.RightShiftAssignmentExpression: - case SyntaxKind.UnsignedRightShiftAssignmentExpression: - case SyntaxKind.CoalesceAssignmentExpression: - { - //TODO? - //Ignore if _IsArrayInitializer is true? - AssignmentExpressionSyntax _expr = (AssignmentExpressionSyntax)asNode; - Visit(_expr.Left); - - VisitLeadingTrivia(_expr.OperatorToken); - JSSB.Append(':'); - VisitTrailingTrivia(_expr.OperatorToken); - - Visit(_expr.Right); - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenBraceToken: - { - if (_IsArrayInitializer) - { - VisitLeadingTrivia(asToken); - JSSB.Append('('); - VisitTrailingTrivia(asToken); - } - else - { - //TODO formating? - //Ignore leading trivia? - VisitToken(asToken); - } - break; - } - case SyntaxKind.CloseBraceToken: - { - if (_IsArrayInitializer) - { - VisitLeadingTrivia(asToken); - JSSB.Append(')'); - VisitTrailingTrivia(asToken); - } - else - VisitToken(asToken); - break; - } - case SyntaxKind.CommaToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - - break; - } - } - } - } - - public override void VisitLiteralExpression(LiteralExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.NumericLiteralToken: - { - string _value = asToken.Text; - - _value = _value.Replace("_",""); - - if (_value.EndsWith('f') || - _value.EndsWith('d') || - _value.EndsWith('m') || - _value.EndsWith('u') || - _value.EndsWith('l') || - _value.EndsWith('F') || - _value.EndsWith('D') || - _value.EndsWith('M') || - _value.EndsWith('U') || - _value.EndsWith('L')) - _value = _value.Remove(_value.Length - 1); - - if (_value.Length > 10) - { - NumberStyles _styles = NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent | NumberStyles.AllowCurrencySymbol; - double _d = double.Parse(_value.Replace('.', ','), _styles); - - if (_value.StartsWith('-')) - { - //TODO? BigInt? - if (_d <= -9007199254740991) - { - Log.WarningLine($"Number: {_d} is smaller then Number.MIN_SAFE_INTEGER(-9007199254740991) clamping!"); - _value = "Number.MIN_SAFE_INTEGER"; - } - } - else - { - if (_d >= 9007199254740991) - { - Log.WarningLine($"Number: {_d} is larger then Number.MAX_SAFE_INTEGER(9007199254740991) clamping!"); - _value = "Number.MAX_SAFE_INTEGER"; - } - } - } - - _value = _value.Replace(',', '.'); - - VisitLeadingTrivia(asToken); - - JSSB.Append(_value); - - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - case SyntaxKind.StringLiteralToken: - case SyntaxKind.CharacterLiteralToken: - case SyntaxKind.NullKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.InterpolatedStringText: - VisitInterpolatedStringText((InterpolatedStringTextSyntax)asNode); - break; - case SyntaxKind.Interpolation: - { - _ThisIsUsed = false; - JSSB.Append('$'); - VisitInterpolation((InterpolationSyntax)asNode); - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.InterpolatedStringStartToken: - case SyntaxKind.InterpolatedStringEndToken: - JSSB.Append('`'); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitParenthesizedExpression(ParenthesizedExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - if (nodesAndTokens[1].IsKind(SyntaxKind.AsExpression) || nodesAndTokens[1].IsKind(SyntaxKind.CastExpression)) - _IgnoreAsParenthesis = true; - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.CoalesceExpression: - case SyntaxKind.AsExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.PostIncrementExpression: - case SyntaxKind.PostDecrementExpression: - case SyntaxKind.SuppressNullableWarningExpression: - VisitPostfixUnaryExpression((PostfixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleAssignmentExpression: - case SyntaxKind.AddAssignmentExpression: - case SyntaxKind.SubtractAssignmentExpression: - case SyntaxKind.MultiplyAssignmentExpression: - case SyntaxKind.DivideAssignmentExpression: - case SyntaxKind.ModuloAssignmentExpression: - case SyntaxKind.AndAssignmentExpression: - case SyntaxKind.ExclusiveOrAssignmentExpression: - case SyntaxKind.OrAssignmentExpression: - case SyntaxKind.LeftShiftAssignmentExpression: - case SyntaxKind.RightShiftAssignmentExpression: - case SyntaxKind.UnsignedRightShiftAssignmentExpression: - case SyntaxKind.CoalesceAssignmentExpression: - VisitAssignmentExpression((AssignmentExpressionSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.TypeOfExpression: - VisitTypeOfExpression((TypeOfExpressionSyntax)asNode); - break; - case SyntaxKind.ConditionalExpression: - VisitConditionalExpression((ConditionalExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedLambdaExpression: - VisitParenthesizedLambdaExpression((ParenthesizedLambdaExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.AnonymousObjectCreationExpression: - VisitAnonymousObjectCreationExpression((AnonymousObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.CastExpression: - VisitCastExpression((CastExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenParenToken: - { - if (_IgnoreAsParenthesis) - { - VisitLeadingTrivia(asToken); - VisitTrailingTrivia(asToken); - } - else - VisitToken(asToken); - break; - } - case SyntaxKind.CloseParenToken: - { - if (!_IgnoreAsParenthesis) - VisitToken(asToken); - - break; - } - //case SyntaxKind.StringLiteralToken: - //VisitToken(asToken); - //break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - - _IgnoreAsParenthesis = false; - } - - public override void VisitCastExpression(CastExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - bool skipTokens = false; - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (skipTokens) - { - if (asNode != null) - continue; - - if (nodesAndTokens[i].AsToken().Kind() == SyntaxKind.CloseParenToken) - skipTokens = false; - - continue; - } - - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.NullableType: - case SyntaxKind.PredefinedType: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.ImplicitObjectCreationExpression: - VisitImplicitObjectCreationExpression((ImplicitObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenParenToken: - { - skipTokens = true; - break; - } - case SyntaxKind.CloseParenToken: - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ArgumentList: - VisitArgumentList((ArgumentListSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.NewKeyword: - { - VisitToken(asToken); - - - VariableDeclarationSyntax? _vds = node.Ancestors().FirstOrDefault(e => e.IsKind(SyntaxKind.VariableDeclaration)) as VariableDeclarationSyntax; - - SymbolInfo? symbolInfo = null; - ISymbol? iSymbol = null; - SyntaxNode? syntaxNode = null; - - if (_vds == null) - { - AssignmentExpressionSyntax? _aes = node.Ancestors().FirstOrDefault(e => e.IsKind(SyntaxKind.SimpleAssignmentExpression)) as AssignmentExpressionSyntax; - - if (_aes == null) - { - //Todo! - //Triggered with "Method(new());" - //See also test "TestPassValueToMethod" with CustomClass - JSSB.Append(" Object"); - Log.WarningLine($"_aes is null"); - break; - } - - symbolInfo = _Model.GetSymbolInfo(_aes.Left); - - ClassDeclarationSyntax? classD = node.Ancestors().First(n => n.IsKind(SyntaxKind.ClassDeclaration)) as ClassDeclarationSyntax; - - if (classD == null) - { - Log.ErrorLine($"classD is null"); - break; - } - - IEnumerable? classesD = null; - - if (classD.Parent != null) - { - classesD = from n in classD.Parent.DescendantNodes() - where n.IsKind(SyntaxKind.ClassDeclaration) - select n as ClassDeclarationSyntax; - } - else - { - Log.ErrorLine($"classD.Parent is null"); - } - - List mem = new(); - - if (classesD != null) - { - foreach (ClassDeclarationSyntax item in classesD) - { - mem.AddRange(item.Members.ToList()); - } - } - - for (int j = 0; j < mem.Count; j++) - { - SyntaxToken? _sT = null; - if (mem[j] is MethodDeclarationSyntax m) - { - _sT = m.Identifier; - } - - if (mem[j] is PropertyDeclarationSyntax p) - { - _sT = p.Identifier; - syntaxNode = p.Type; - } - - if (mem[j] is FieldDeclarationSyntax f) - { - IEnumerable d3 = from e in f.DescendantTokens() - where e.IsKind(SyntaxKind.IdentifierToken) - select e; - _sT = d3.Last(); - } - - if (_sT != null && _aes.Left.ToString() == _sT?.Text) - { - //Todo? - //VariableDeclarationSyntax s = item.DescendantNodes().First(e => e.IsKind(SyntaxKind.VariableDeclaration)) as VariableDeclarationSyntax; - //syntaxNode = s.Type; - if (syntaxNode != null) - { - symbolInfo = _Model.GetSymbolInfo(syntaxNode); - break; - } - else - { - Log.ErrorLine("syntaxNode is null"); - break; - } - } - } - } - else - { - if (_SNPropertyType != null) - symbolInfo = _Model.GetSymbolInfo(_SNPropertyType); - else - symbolInfo = _Model.GetSymbolInfo(_vds.Type); - - syntaxNode = _vds.Type; - } - - - if (symbolInfo?.CandidateSymbols.Length >= 1) - iSymbol = symbolInfo?.CandidateSymbols[0]; - else - iSymbol = symbolInfo?.Symbol; - - if (iSymbol != null && iSymbol.Kind != SymbolKind.ErrorType) - { - string? _containingNamespace = iSymbol.ContainingNamespace.ToString(); - if (_containingNamespace == null) - { - Log.ErrorLine("_containingNamespace is null"); - _containingNamespace = string.Empty; - } - - if (_containingNamespace.Contains(nameof(CSharpToJavaScript))) - { - string _text = string.Empty; - SyntaxToken _identifier = new(); - if (syntaxNode is IdentifierNameSyntax ins) - { - _text = ins.Identifier.Text; - _identifier = ins.Identifier; - } - - if (syntaxNode is GenericNameSyntax gns) - { - _text = gns.Identifier.Text; - _identifier = gns.Identifier; - } - - ImmutableArray _attributeDatas = iSymbol.GetAttributes(); - - //Check this! TODO! - if(iSymbol.ContainingType != null) - _attributeDatas.AddRange(iSymbol.ContainingType.GetAttributes()); - - foreach (AttributeData _attr in _attributeDatas) - { - if (_attr.AttributeClass != null) - { - if (_attr.AttributeClass.Name == nameof(ToAttribute)) - { - ToAttribute _attrLocal = new(ToAttribute.Default); - if (_attr.ConstructorArguments[0].Value is string _str) - { - _attrLocal = new(_str); - } - else - { - Log.ErrorLine("_attr.ConstructorArguments[0].Value is not a string"); - } - - JSSB.Append($" {_attrLocal.Convert(_text)}"); - break; - } - } - else - { - Log.ErrorLine("_attr.AttributeClass is null"); - break; - } - } - break; - } - - if (_containingNamespace.Contains(_NameSpaceStr)) - { - if (syntaxNode.IsKind(SyntaxKind.GenericName)) - { - JSSB.Append($" {((GenericNameSyntax)syntaxNode).Identifier.ToString()}"); - } - else - { - if (syntaxNode != null) - JSSB.Append($" {syntaxNode.ToString()}"); - else - Log.ErrorLine("syntaxNode is null"); - } - break; - } - - //TODO? - //Hitting with "object"! - //See also Test "TestFieldsDefaultValue" with 'object' 'new()' - if (syntaxNode.IsKind(SyntaxKind.PredefinedType)) - { - JSSB.Append(" Object"); - break; - } - - if (CustomCSNamesToJS(syntaxNode) == false) - { - JSSB.Append(' '); - if (syntaxNode != null) - { - if (BuiltInTypesGenerics(syntaxNode.WithoutLeadingTrivia(), iSymbol) == false) - { - Log.WarningLine($"TODO : {syntaxNode} ||| USE 'CustomCSNamesToJS' TO CONVERT."); - } - } - else - Log.ErrorLine("syntaxNode is null"); - } - - } - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - bool translateAsObject = false; - - SymbolInfo? symbolInfo = null; - - if (_SNPropertyType != null) - symbolInfo = _Model.GetSymbolInfo(_SNPropertyType); - else - symbolInfo = _Model.GetSymbolInfo(nodesAndTokens[1].AsNode()); - - ISymbol? symbol = null; - - if (symbolInfo?.CandidateSymbols.Length >= 1) - symbol = symbolInfo?.CandidateSymbols[0]; - else - symbol = symbolInfo?.Symbol; - - if (symbol != null) - { - AttributeData[] attributeData = symbol.GetAttributes().ToArray(); - for (int i = 0; i < attributeData.Length; i++) - { - if (attributeData[i].ToString().EndsWith(nameof(ToObjectAttribute))) - { - translateAsObject = true; - break; - } - } - } - if (translateAsObject) - { - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ObjectInitializerExpression: - VisitInitializerExpression((InitializerExpressionSyntax)asNode); - break; - case SyntaxKind.ArgumentList: - { - SyntaxTriviaList _syntaxTrivias = asNode.GetTrailingTrivia(); - - //Ignore the first one! - //we keep trailing trivia with "=" - //example cs: - //MutationObserverInit a =|1|new MutationObserverInit()|2|{... - //example js: - //let a =|1|{... - //We keep |1| one but ignore |2| otherwise, we get double whitespace - //if there is a new line, for example |3|=newline, then: - //let a =|1||3| - //{... - if (_syntaxTrivias.Count > 1) - { - for (int _i = 1; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - break; - } - case SyntaxKind.IdentifierName: - break; - default: - Log.ErrorLine($"translateAsObject: asNode: {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - } - } - else - { - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ObjectInitializerExpression: - { - Log.WarningLine($"'ObjectInitializerExpression' Ignored! Please use constructor for '{nodesAndTokens[1].ToString()}'"); - //Todo? How? JS does not have object initializer... - break; - } - case SyntaxKind.ArgumentList: - VisitArgumentList((ArgumentListSyntax)asNode); - break; - case SyntaxKind.PredefinedType: - VisitPredefinedType((PredefinedTypeSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.GenericName: - VisitGenericName((GenericNameSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.NewKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - } - - public override void VisitThisExpression(ThisExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - _ThisIsUsed = true; - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.ThisKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitBaseExpression(BaseExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.BaseKeyword: - { - VisitLeadingTrivia(asToken); - JSSB.Append($"super"); - - //This is not used with super keyword. - //Treat super as this. - _ThisIsUsed = true; - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitTypeArgumentList(TypeArgumentListSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.GenericName: - case SyntaxKind.PredefinedType: - case SyntaxKind.IdentifierName: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.CommaToken: - case SyntaxKind.GreaterThanToken: - case SyntaxKind.LessThanToken: - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitGenericName(GenericNameSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.TypeArgumentList: - { - if (_AttributeDatasForInvocation[0] != string.Empty) - { - _AttributeDatasForInvocation[2] = ((TypeArgumentListSyntax)asNode).Arguments[0].ToString(); - } - else if (_GenericAsArgument) - { - _SNAdditionalArgument = ((TypeArgumentListSyntax)asNode).Arguments[0]; - _GenericAsArgument = false; - } - else - VisitTypeArgumentList((TypeArgumentListSyntax)asNode); - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierToken: - { - if (IsRightAttribute(node, asToken)) - break; - - if (IdentifierToken(node) == false) - { - base.VisitGenericName(node); - } - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - public override void VisitIdentifierName(IdentifierNameSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierToken: - { - if (IsRightAttribute(node, asToken)) - break; - - if (IdentifierToken(node) == false) - { - base.VisitIdentifierName(node); - } - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - - //TODO! - //Request right attribute! - private bool IsRightAttribute(T identifier, SyntaxToken asToken) where T : SimpleNameSyntax - { - SymbolInfo? _symbolInfo = null; - - if (_SNPropertyType != null) - _symbolInfo = _Model.GetSymbolInfo(_SNPropertyType); - else - _symbolInfo = _Model.GetSymbolInfo(identifier); - - ISymbol? _symbol = null; - - if (_symbolInfo?.CandidateSymbols.Length >= 1) - _symbol = _symbolInfo?.CandidateSymbols[0]; - else - _symbol = _symbolInfo?.Symbol; - - if (_symbol != null) - { - CheckParentAttributes: - AttributeData[] _attributeData = _symbol.GetAttributes().ToArray(); - for (int j = 0; j < _attributeData.Length; j++) - { - if (_attributeData[j].AttributeClass != null) - { - if (_attributeData[j].AttributeClass!.Name == nameof(GenericAsArgument)) - { - _GenericAsArgument = true; - } - - if (_attributeData[j].AttributeClass!.Name == nameof(BinaryAttribute) || - _attributeData[j].AttributeClass!.Name == nameof(UnaryAttribute) || - _attributeData[j].AttributeClass!.Name == nameof(GenericBinaryAttribute) || - _attributeData[j].AttributeClass!.Name == nameof(GenericUnaryAttribute)) - { - _AttributeDatasForInvocation[0] = _attributeData[j].AttributeClass!.Name; - _AttributeDatasForInvocation[1] = _attributeData[j].ConstructorArguments[0].Value.ToString(); - - return true; - } - - if (_attributeData[j].AttributeClass!.Name == nameof(ValueAttribute)) - { - SyntaxTriviaList _syntaxTrivias = identifier.GetLeadingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - JSSB.Append($"{_attributeData[j].ConstructorArguments[0].Value}"); - - _syntaxTrivias = identifier.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - return true; - } - - if (_attributeData[j].AttributeClass!.Name == nameof(ToAttribute)) - { - ToAttribute _toAttr = new(_attributeData[j].ConstructorArguments[0].Value.ToString()); - - if (_toAttr.To == ToAttribute.NoneWithLeadingDotRemoved) - JSSB.Remove(JSSB.Length - 1, 1); - - if (_toAttr.To == ToAttribute.NoneWithTrailingDotRemoved) - _IgnoreTailingDot = true; - - SyntaxTriviaList _syntaxTrivias = identifier.GetLeadingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - JSSB.Append($"{_toAttr.Convert(identifier.Identifier.Text)}"); - - _syntaxTrivias = identifier.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - return true; - } - } - } - if (_symbol.ContainingType != null) - { - _symbol = _symbol.ContainingType; - goto CheckParentAttributes; - } - } - - return false; - } - - public override void VisitAssignmentExpression(AssignmentExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - //TODO! - _ThisIsUsed = false; - - base.VisitAssignmentExpression(node); - //TODO! - _ThisIsUsed = false; - - } - - public override void VisitAttribute(AttributeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAttribute(node); - } - public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitArrowExpressionClause(node); - } - public override void VisitArgumentList(ArgumentListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitArgumentList(node); - } - public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAccessorDeclaration(node); - } - public override void VisitAliasQualifiedName(AliasQualifiedNameSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAliasQualifiedName(node); - } - public override void VisitAllowsConstraintClause(AllowsConstraintClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAllowsConstraintClause(node); - } - public override void VisitAnonymousMethodExpression(AnonymousMethodExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAnonymousMethodExpression(node); - } - public override void VisitAnonymousObjectMemberDeclarator(AnonymousObjectMemberDeclaratorSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.InterpolatedStringExpression: - VisitInterpolatedStringExpression((InterpolatedStringExpressionSyntax)asNode); - break; - case SyntaxKind.PointerMemberAccessExpression: - case SyntaxKind.SimpleMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleAssignmentExpression: - { - AssignmentExpressionSyntax _expr = (AssignmentExpressionSyntax)asNode; - Visit(_expr.Left); - - VisitLeadingTrivia(_expr.OperatorToken); - JSSB.Append(':'); - VisitTrailingTrivia(_expr.OperatorToken); - - Visit(_expr.Right); - break; - } - case SyntaxKind.NameEquals: - VisitNameEquals((NameEqualsSyntax)asNode); - break; - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.AnonymousObjectCreationExpression: - VisitAnonymousObjectCreationExpression((AnonymousObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.CoalesceExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitAttributeArgument(AttributeArgumentSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAttributeArgument(node); - } - public override void VisitAttributeArgumentList(AttributeArgumentListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAttributeArgumentList(node); - } - public override void VisitAttributeList(AttributeListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAttributeList(node); - } - public override void VisitAttributeTargetSpecifier(AttributeTargetSpecifierSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAttributeTargetSpecifier(node); - } - public override void VisitAwaitExpression(AwaitExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitAwaitExpression(node); - } - public override void VisitBadDirectiveTrivia(BadDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitBadDirectiveTrivia(node); - } - public override void VisitBinaryExpression(BinaryExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - bool ignoreNext = false; - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - if (ignoreNext) - { - //TODO! Ignore trailing trivia if the second token is the 'as' keyword. - //removing whitespace before the 'as' keyword - JSSB.Remove(JSSB.Length - 1, 1); - - ignoreNext = false; - continue; - } - - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - case SyntaxKind.AnonymousObjectCreationExpression: - VisitAnonymousObjectCreationExpression((AnonymousObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.TypeOfExpression: - VisitTypeOfExpression((TypeOfExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.CastExpression: - VisitCastExpression((CastExpressionSyntax)asNode); - break; - case SyntaxKind.AwaitExpression: - VisitAwaitExpression((AwaitExpressionSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.CoalesceExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IsKeyword: - { - VisitLeadingTrivia(asToken); - JSSB.Append("instanceof"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.MinusToken: - case SyntaxKind.SlashToken: - case SyntaxKind.PercentToken: - case SyntaxKind.AmpersandAmpersandToken: - case SyntaxKind.GreaterThanGreaterThanToken: - case SyntaxKind.BarToken: - case SyntaxKind.BarBarToken: - case SyntaxKind.LessThanEqualsToken: - case SyntaxKind.QuestionQuestionToken: - case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: - case SyntaxKind.AsteriskToken: - case SyntaxKind.PlusToken: - case SyntaxKind.LessThanLessThanToken: - case SyntaxKind.GreaterThanToken: - case SyntaxKind.GreaterThanEqualsToken: - case SyntaxKind.AmpersandToken: - case SyntaxKind.CaretToken: - case SyntaxKind.EqualsEqualsToken: - case SyntaxKind.ExclamationEqualsToken: - case SyntaxKind.LessThanToken: - VisitToken(asToken); - break; - case SyntaxKind.AsKeyword: - { - ignoreNext = true; - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitBinaryPattern(BinaryPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitBinaryPattern(node); - } - public override void VisitBracketedArgumentList(BracketedArgumentListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitBracketedArgumentList(node); - } - public override void VisitBracketedParameterList(BracketedParameterListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitBracketedParameterList(node); - } - public override void VisitBreakStatement(BreakStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitBreakStatement(node); - } - public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCasePatternSwitchLabel(node); - } - public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCaseSwitchLabel(node); - } - public override void VisitCatchClause(CatchClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCatchClause(node); - } - public override void VisitCatchFilterClause(CatchFilterClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCatchFilterClause(node); - } - public override void VisitCheckedExpression(CheckedExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCheckedExpression(node); - } - public override void VisitCheckedStatement(CheckedStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCheckedStatement(node); - } - public override void VisitClassOrStructConstraint(ClassOrStructConstraintSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitClassOrStructConstraint(node); - } - public override void VisitCollectionExpression(CollectionExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCollectionExpression(node); - } - public override void VisitCompilationUnit(CompilationUnitSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.AttributeList: - case SyntaxKind.ExternAliasDirective: - case SyntaxKind.UsingDirective: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.ClassDeclaration: - VisitClassDeclaration((ClassDeclarationSyntax)asNode); - break; - case SyntaxKind.GlobalStatement: - { - _GlobalStatement = true; - VisitGlobalStatement((GlobalStatementSyntax)asNode); - _GlobalStatement = false; - break; - } - case SyntaxKind.NamespaceDeclaration: - VisitNamespaceDeclaration((NamespaceDeclarationSyntax)asNode); - break; - case SyntaxKind.FileScopedNamespaceDeclaration: - VisitFileScopedNamespaceDeclaration((FileScopedNamespaceDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.EndOfFileToken: - { - VisitToken(asToken); - - if (_Options.Debug) - { - JSSB.Append("/*"); - JSSB.Append(node.ToFullString().Replace("*/", "")); - JSSB.Append("*/"); - } - - break; - } - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitConditionalAccessExpression(ConditionalAccessExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConditionalAccessExpression(node); - } - public override void VisitConditionalExpression(ConditionalExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConditionalExpression(node); - } - public override void VisitConstantPattern(ConstantPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConstantPattern(node); - } - public override void VisitConstructorConstraint(ConstructorConstraintSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConstructorConstraint(node); - } - public override void VisitConstructorInitializer(ConstructorInitializerSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConstructorInitializer(node); - } - public override void VisitContinueStatement(ContinueStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitContinueStatement(node); - } - public override void VisitConversionOperatorDeclaration(ConversionOperatorDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConversionOperatorDeclaration(node); - } - public override void VisitConversionOperatorMemberCref(ConversionOperatorMemberCrefSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitConversionOperatorMemberCref(node); - } - public override void VisitCrefBracketedParameterList(CrefBracketedParameterListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCrefBracketedParameterList(node); - } - public override void VisitCrefParameter(CrefParameterSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCrefParameter(node); - } - public override void VisitCrefParameterList(CrefParameterListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitCrefParameterList(node); - } - - public override void VisitDeclarationExpression(DeclarationExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDeclarationExpression(node); - } - public override void VisitDeclarationPattern(DeclarationPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDeclarationPattern(node); - } - public override void VisitDefaultConstraint(DefaultConstraintSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDefaultConstraint(node); - } - public override void VisitDefaultExpression(DefaultExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDefaultExpression(node); - } - public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDefaultSwitchLabel(node); - } - public override void VisitDefineDirectiveTrivia(DefineDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDefineDirectiveTrivia(node); - } - - public override void VisitDelegateDeclaration(DelegateDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDelegateDeclaration(node); - } - public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDestructorDeclaration(node); - } - public override void VisitDiscardDesignation(DiscardDesignationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDiscardDesignation(node); - } - public override void VisitDiscardPattern(DiscardPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDiscardPattern(node); - } - public override void VisitDocumentationCommentTrivia(DocumentationCommentTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDocumentationCommentTrivia(node); - } - public override void VisitDoStatement(DoStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitDoStatement(node); - } - public override void VisitElementAccessExpression(ElementAccessExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitElementAccessExpression(node); - } - public override void VisitElementBindingExpression(ElementBindingExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitElementBindingExpression(node); - } - public override void VisitElifDirectiveTrivia(ElifDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitElifDirectiveTrivia(node); - } - public override void VisitElseClause(ElseClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitElseClause(node); - } - public override void VisitElseDirectiveTrivia(ElseDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitElseDirectiveTrivia(node); - } - public override void VisitEmptyStatement(EmptyStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitEmptyStatement(node); - } - public override void VisitEndIfDirectiveTrivia(EndIfDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitEndIfDirectiveTrivia(node); - } - public override void VisitEndRegionDirectiveTrivia(EndRegionDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitEndRegionDirectiveTrivia(node); - } - public override void VisitEqualsValueClause(EqualsValueClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitEqualsValueClause(node); - } - public override void VisitErrorDirectiveTrivia(ErrorDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitErrorDirectiveTrivia(node); - } - public override void VisitEventDeclaration(EventDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitEventDeclaration(node); - } - public override void VisitEventFieldDeclaration(EventFieldDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitEventFieldDeclaration(node); - } - - public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitExplicitInterfaceSpecifier(node); - } - public override void VisitExpressionColon(ExpressionColonSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitExpressionColon(node); - } - public override void VisitExpressionElement(ExpressionElementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitExpressionElement(node); - } - public override void VisitExternAliasDirective(ExternAliasDirectiveSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitExternAliasDirective(node); - } - public override void VisitFileScopedNamespaceDeclaration(FileScopedNamespaceDeclarationSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.DelegateDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.StructDeclaration: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.QualifiedName: - case SyntaxKind.IdentifierName: - { - _NameSpaceStr = node.Name.ToString(); - break; - } - case SyntaxKind.ClassDeclaration: - VisitClassDeclaration((ClassDeclarationSyntax)asNode); - break; - case SyntaxKind.EnumDeclaration: - VisitEnumDeclaration((EnumDeclarationSyntax)asNode); - break; - case SyntaxKind.NamespaceDeclaration: - VisitNamespaceDeclaration((NamespaceDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.SemicolonToken: - case SyntaxKind.NamespaceKeyword: - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitFinallyClause(FinallyClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFinallyClause(node); - } - public override void VisitFixedStatement(FixedStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFixedStatement(node); - } - public override void VisitForEachVariableStatement(ForEachVariableStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.IfStatement: - VisitIfStatement((IfStatementSyntax)asNode); - break; - case SyntaxKind.ThisExpression: - VisitThisExpression((ThisExpressionSyntax)asNode); - break; - case SyntaxKind.ExpressionStatement: - VisitExpressionStatement((ExpressionStatementSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - case SyntaxKind.GenericName: - case SyntaxKind.PredefinedType: - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - if (_Options.UseVarOverLet) - JSSB.Append("var"); - else - JSSB.Append("let"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - break; - } - case SyntaxKind.IdentifierName: - { - IdentifierNameSyntax? _ins = asNode as IdentifierNameSyntax; - if (_ins != null) - { - if (_ins.IsVar) - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - if (_Options.UseVarOverLet) - JSSB.Append("var"); - else - JSSB.Append("let"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - } - else - { - if (IdentifierToken(asNode) == false) - { - VisitIdentifierName(_ins); - } - } - } - else - { - Log.ErrorLine($"_ins is null"); - } - - break; - } - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - - case SyntaxKind.IdentifierToken: - { - VisitLeadingTrivia(asToken); - JSSB.Append($"{asToken.Text}"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.ForEachKeyword: - { - VisitLeadingTrivia(asToken); - JSSB.Append("for"); - VisitTrailingTrivia(asToken); - break; - } - case SyntaxKind.InKeyword: - case SyntaxKind.CloseParenToken: - case SyntaxKind.OpenParenToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitForStatement(ForStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitForStatement(node); - } - public override void VisitFromClause(FromClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFromClause(node); - } - public override void VisitFunctionPointerCallingConvention(FunctionPointerCallingConventionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFunctionPointerCallingConvention(node); - } - public override void VisitFunctionPointerParameter(FunctionPointerParameterSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFunctionPointerParameter(node); - } - public override void VisitFunctionPointerParameterList(FunctionPointerParameterListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFunctionPointerParameterList(node); - } - public override void VisitFunctionPointerType(FunctionPointerTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFunctionPointerType(node); - } - public override void VisitFunctionPointerUnmanagedCallingConvention(FunctionPointerUnmanagedCallingConventionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFunctionPointerUnmanagedCallingConvention(node); - } - public override void VisitFunctionPointerUnmanagedCallingConventionList(FunctionPointerUnmanagedCallingConventionListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitFunctionPointerUnmanagedCallingConventionList(node); - } - public override void VisitGlobalStatement(GlobalStatementSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.LocalFunctionStatement: - VisitLocalFunctionStatement((LocalFunctionStatementSyntax)asNode); - break; - case SyntaxKind.ExpressionStatement: - VisitExpressionStatement((ExpressionStatementSyntax)asNode); - break; - case SyntaxKind.LocalDeclarationStatement: - VisitLocalDeclarationStatement((LocalDeclarationStatementSyntax)asNode); - break; - case SyntaxKind.TryStatement: - VisitTryStatement((TryStatementSyntax)asNode); - break; - case SyntaxKind.IfStatement: - VisitIfStatement((IfStatementSyntax)asNode); - break; - case SyntaxKind.ForStatement: - VisitForStatement((ForStatementSyntax)asNode); - break; - case SyntaxKind.ReturnStatement: - VisitReturnStatement((ReturnStatementSyntax)asNode); - break; - case SyntaxKind.LabeledStatement: - VisitLabeledStatement((LabeledStatementSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - case SyntaxKind.WhileStatement: - VisitWhileStatement((WhileStatementSyntax)asNode); - break; - case SyntaxKind.DoStatement: - VisitDoStatement((DoStatementSyntax)asNode); - break; - case SyntaxKind.EmptyStatement: - VisitEmptyStatement((EmptyStatementSyntax)asNode); - break; - case SyntaxKind.ThrowStatement: - VisitThrowStatement((ThrowStatementSyntax)asNode); - break; - case SyntaxKind.ContinueStatement: - VisitContinueStatement((ContinueStatementSyntax)asNode); - break; - case SyntaxKind.ForEachStatement: - VisitForEachStatement((ForEachStatementSyntax)asNode); - break; - case SyntaxKind.BreakStatement: - VisitBreakStatement((BreakStatementSyntax)asNode); - break; - case SyntaxKind.ForEachVariableStatement: - VisitForEachVariableStatement((ForEachVariableStatementSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitGotoStatement(GotoStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitGotoStatement(node); - } - public override void VisitGroupClause(GroupClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitGroupClause(node); - } - public override void VisitIfDirectiveTrivia(IfDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitIfDirectiveTrivia(node); - } - public override void VisitIfStatement(IfStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - { - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - } - case SyntaxKind.EmptyStatement: - VisitEmptyStatement((EmptyStatementSyntax)asNode); - break; - case SyntaxKind.IfStatement: - VisitIfStatement((IfStatementSyntax)asNode); - break; - case SyntaxKind.ThrowStatement: - VisitThrowStatement((ThrowStatementSyntax)asNode); - break; - case SyntaxKind.BreakStatement: - VisitBreakStatement((BreakStatementSyntax)asNode); - break; - case SyntaxKind.ReturnStatement: - VisitReturnStatement((ReturnStatementSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.InvocationExpression: - VisitInvocationExpression((InvocationExpressionSyntax)asNode); - break; - case SyntaxKind.ContinueStatement: - VisitContinueStatement((ContinueStatementSyntax)asNode); - break; - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - case SyntaxKind.ElseClause: - VisitElseClause((ElseClauseSyntax)asNode); - break; - case SyntaxKind.ExpressionStatement: - VisitExpressionStatement((ExpressionStatementSyntax)asNode); - break; - case SyntaxKind.LogicalNotExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.RightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.ExclusiveOrExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.IsExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.CoalesceExpression: - VisitBinaryExpression((BinaryExpressionSyntax)asNode); - break; - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.CloseParenToken: - case SyntaxKind.OpenParenToken: - case SyntaxKind.IfKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitImplicitArrayCreationExpression(ImplicitArrayCreationExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitImplicitArrayCreationExpression(node); - } - public override void VisitImplicitElementAccess(ImplicitElementAccessSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitImplicitElementAccess(node); - } - public override void VisitImplicitStackAllocArrayCreationExpression(ImplicitStackAllocArrayCreationExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitImplicitStackAllocArrayCreationExpression(node); - } - public override void VisitIncompleteMember(IncompleteMemberSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitIncompleteMember(node); - } - public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitIndexerDeclaration(node); - } - public override void VisitIndexerMemberCref(IndexerMemberCrefSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitIndexerMemberCref(node); - } - public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitInterfaceDeclaration(node); - } - public override void VisitInterpolatedStringText(InterpolatedStringTextSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitInterpolatedStringText(node); - } - public override void VisitInterpolation(InterpolationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitInterpolation(node); - } - public override void VisitInterpolationAlignmentClause(InterpolationAlignmentClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitInterpolationAlignmentClause(node); - } - public override void VisitInterpolationFormatClause(InterpolationFormatClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitInterpolationFormatClause(node); - } - public override void VisitInvocationExpression(InvocationExpressionSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - _ThisIsUsed = false; - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.GenericName: - VisitGenericName((GenericNameSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - { - IdentifierNameSyntax identifierName = (IdentifierNameSyntax)asNode; - VisitIdentifierName(identifierName); - break; - } - case SyntaxKind.ArgumentList: - { - ArgumentListSyntax _arguments = (ArgumentListSyntax)asNode; - - if (_AttributeDatasForInvocation[0] != string.Empty) - { - if (_AttributeDatasForInvocation[0] == nameof(BinaryAttribute)) - { - _AttributeDatasForInvocation[0] = string.Empty; - string _operator = _AttributeDatasForInvocation[1]; - - VisitArgument(_arguments.Arguments[0]); - - if (!_arguments.Arguments[0].HasTrailingTrivia) - JSSB.Append(' '); - - JSSB.Append(_operator); - VisitTrailingTrivia(_arguments.Arguments.GetSeparator(0)); - VisitArgument(_arguments.Arguments[1]); - - SyntaxTriviaList _syntaxTrivias = _arguments.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - goto BreakArgumentList; - } - - if (_AttributeDatasForInvocation[0] == nameof(UnaryAttribute)) - { - _AttributeDatasForInvocation[0] = string.Empty; - string _operator = _AttributeDatasForInvocation[1]; - - JSSB.Append(_operator); - VisitArgument(_arguments.Arguments[0]); - - goto BreakArgumentList; - } - - if (_AttributeDatasForInvocation[0] == nameof(GenericUnaryAttribute)) - { - _AttributeDatasForInvocation[0] = string.Empty; - string _operator = _AttributeDatasForInvocation[1]; - - JSSB.Append(_operator); - - //Generic - JSSB.Append(_AttributeDatasForInvocation[2]); - _AttributeDatasForInvocation[2] = string.Empty; - - goto BreakArgumentList; - } - - if (_AttributeDatasForInvocation[0] == nameof(GenericBinaryAttribute)) - { - _AttributeDatasForInvocation[0] = string.Empty; - string _operator = _AttributeDatasForInvocation[1]; - - VisitArgument(_arguments.Arguments[0]); - JSSB.Append(_operator); - - //Generic - JSSB.Append(_AttributeDatasForInvocation[2]); - _AttributeDatasForInvocation[2] = string.Empty; - - goto BreakArgumentList; - } - } - - VisitArgumentList(_arguments); - - if (_SNAdditionalArgument != null) - { - //TODO? - JSSB.Remove(JSSB.Length - 1, 1); - JSSB.Append(", "); - VisitIdentifierName((IdentifierNameSyntax)_SNAdditionalArgument); - JSSB.Append(")"); - _SNAdditionalArgument = null; - } - - BreakArgumentList: - break; - } - case SyntaxKind.ElementAccessExpression: - VisitElementAccessExpression((ElementAccessExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.TypeOfExpression: - VisitTypeOfExpression((TypeOfExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedExpression: - VisitParenthesizedExpression((ParenthesizedExpressionSyntax)asNode); - break; - case SyntaxKind.ParenthesizedLambdaExpression: - VisitParenthesizedLambdaExpression((ParenthesizedLambdaExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - - _ThisIsUsed = false; - } - public override void VisitIsPatternExpression(IsPatternExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitIsPatternExpression(node); - } - public override void VisitJoinClause(JoinClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitJoinClause(node); - } - public override void VisitJoinIntoClause(JoinIntoClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitJoinIntoClause(node); - } - public override void VisitLabeledStatement(LabeledStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLabeledStatement(node); - } - public override void VisitLetClause(LetClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLetClause(node); - } - public override void VisitLineDirectivePosition(LineDirectivePositionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLineDirectivePosition(node); - } - public override void VisitLineDirectiveTrivia(LineDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLineDirectiveTrivia(node); - } - public override void VisitLineSpanDirectiveTrivia(LineSpanDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLineSpanDirectiveTrivia(node); - } - public override void VisitListPattern(ListPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitListPattern(node); - } - public override void VisitLoadDirectiveTrivia(LoadDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLoadDirectiveTrivia(node); - } - public override void VisitLocalFunctionStatement(LocalFunctionStatementSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.Block: - VisitBlock((BlockSyntax)asNode); - break; - case SyntaxKind.ParameterList: - VisitParameterList((ParameterListSyntax)asNode); - break; - case SyntaxKind.IdentifierName: - case SyntaxKind.PredefinedType: - { - SyntaxTriviaList _syntaxTrivias = asNode.GetLeadingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - - JSSB.Append("function"); - - _syntaxTrivias = asNode.GetTrailingTrivia(); - for (int _i = 0; _i < _syntaxTrivias.Count; _i++) - { - VisitTrivia(_syntaxTrivias[_i]); - } - break; - } - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitLockStatement(LockStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitLockStatement(node); - } - public override void VisitMakeRefExpression(MakeRefExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitMakeRefExpression(node); - } - public override void VisitMemberBindingExpression(MemberBindingExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitMemberBindingExpression(node); - } - public override void VisitNameColon(NameColonSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitNameColon(node); - } - public override void VisitNameMemberCref(NameMemberCrefSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitNameMemberCref(node); - } - public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) - { - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.UsingDirective: - case SyntaxKind.DelegateDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.StructDeclaration: - { -#if DEBUG - Log.WarningLine($"\"{kind}\" not implemented or unlikely to be implemented. Ignoring! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{asNode.ToFullString()}|"); -#endif - break; - } - case SyntaxKind.QualifiedName: - case SyntaxKind.IdentifierName: - { - _NameSpaceStr = node.Name.ToString(); - break; - } - case SyntaxKind.ClassDeclaration: - VisitClassDeclaration((ClassDeclarationSyntax)asNode); - break; - case SyntaxKind.EnumDeclaration: - VisitEnumDeclaration((EnumDeclarationSyntax)asNode); - break; - case SyntaxKind.NamespaceDeclaration: - VisitNamespaceDeclaration((NamespaceDeclarationSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - //Todo? make a scope??? {...} - //OpenBraceToken and CloseBraceToken - case SyntaxKind.OpenBraceToken: - case SyntaxKind.CloseBraceToken: - case SyntaxKind.NamespaceKeyword: - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitNullableDirectiveTrivia(NullableDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitNullableDirectiveTrivia(node); - } - public override void VisitNullableType(NullableTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitNullableType(node); - } - public override void VisitOmittedArraySizeExpression(OmittedArraySizeExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitOmittedArraySizeExpression(node); - } - public override void VisitOmittedTypeArgument(OmittedTypeArgumentSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitOmittedTypeArgument(node); - } - public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitOperatorDeclaration(node); - } - - public override void VisitOperatorMemberCref(OperatorMemberCrefSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitOperatorMemberCref(node); - } - public override void VisitOrderByClause(OrderByClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitOrderByClause(node); - } - public override void VisitOrdering(OrderingSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitOrdering(node); - } - public override void VisitParameterList(ParameterListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitParameterList(node); - } - public override void VisitParenthesizedLambdaExpression(ParenthesizedLambdaExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitParenthesizedLambdaExpression(node); - } - public override void VisitParenthesizedPattern(ParenthesizedPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitParenthesizedPattern(node); - } - public override void VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitParenthesizedVariableDesignation(node); - } - public override void VisitPointerType(PointerTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPointerType(node); - } - public override void VisitPositionalPatternClause(PositionalPatternClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPositionalPatternClause(node); - } - public override void VisitPostfixUnaryExpression(PostfixUnaryExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPostfixUnaryExpression(node); - } - public override void VisitPragmaChecksumDirectiveTrivia(PragmaChecksumDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPragmaChecksumDirectiveTrivia(node); - } - public override void VisitPragmaWarningDirectiveTrivia(PragmaWarningDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPragmaWarningDirectiveTrivia(node); - } - public override void VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPrefixUnaryExpression(node); - } - public override void VisitPrimaryConstructorBaseType(PrimaryConstructorBaseTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPrimaryConstructorBaseType(node); - } - public override void VisitPropertyPatternClause(PropertyPatternClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitPropertyPatternClause(node); - } - public override void VisitQualifiedCref(QualifiedCrefSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitQualifiedCref(node); - } - public override void VisitQualifiedName(QualifiedNameSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitQualifiedName(node); - } - public override void VisitQueryBody(QueryBodySyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitQueryBody(node); - } - public override void VisitQueryContinuation(QueryContinuationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitQueryContinuation(node); - } - public override void VisitQueryExpression(QueryExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitQueryExpression(node); - } - public override void VisitRangeExpression(RangeExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRangeExpression(node); - } - public override void VisitRecordDeclaration(RecordDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRecordDeclaration(node); - } - public override void VisitRecursivePattern(RecursivePatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRecursivePattern(node); - } - public override void VisitReferenceDirectiveTrivia(ReferenceDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitReferenceDirectiveTrivia(node); - } - public override void VisitRefExpression(RefExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRefExpression(node); - } - public override void VisitRefStructConstraint(RefStructConstraintSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRefStructConstraint(node); - } - public override void VisitRefType(RefTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRefType(node); - } - public override void VisitRefTypeExpression(RefTypeExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRefTypeExpression(node); - } - public override void VisitRefValueExpression(RefValueExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRefValueExpression(node); - } - public override void VisitRegionDirectiveTrivia(RegionDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRegionDirectiveTrivia(node); - } - public override void VisitRelationalPattern(RelationalPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitRelationalPattern(node); - } - public override void VisitReturnStatement(ReturnStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - case SyntaxKind.ArgListExpression: - case SyntaxKind.NumericLiteralExpression: - case SyntaxKind.StringLiteralExpression: - case SyntaxKind.Utf8StringLiteralExpression: - case SyntaxKind.CharacterLiteralExpression: - case SyntaxKind.TrueLiteralExpression: - case SyntaxKind.FalseLiteralExpression: - case SyntaxKind.NullLiteralExpression: - case SyntaxKind.DefaultLiteralExpression: - VisitLiteralExpression((LiteralExpressionSyntax)asNode); - break; - case SyntaxKind.SimpleMemberAccessExpression: - case SyntaxKind.PointerMemberAccessExpression: - VisitMemberAccessExpression((MemberAccessExpressionSyntax)asNode); - break; - case SyntaxKind.UnaryPlusExpression: - case SyntaxKind.UnaryMinusExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - case SyntaxKind.AddressOfExpression: - case SyntaxKind.PointerIndirectionExpression: - case SyntaxKind.IndexExpression: - VisitPrefixUnaryExpression((PrefixUnaryExpressionSyntax)asNode); - break; - case SyntaxKind.ObjectCreationExpression: - VisitObjectCreationExpression((ObjectCreationExpressionSyntax)asNode); - break; - case SyntaxKind.ImplicitObjectCreationExpression: - VisitImplicitObjectCreationExpression((ImplicitObjectCreationExpressionSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.ReturnKeyword: - case SyntaxKind.SemicolonToken: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitScopedType(ScopedTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitScopedType(node); - } - public override void VisitSelectClause(SelectClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSelectClause(node); - } - public override void VisitShebangDirectiveTrivia(ShebangDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitShebangDirectiveTrivia(node); - } - public override void VisitSimpleBaseType(SimpleBaseTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSimpleBaseType(node); - } - public override void VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSimpleLambdaExpression(node); - } - public override void VisitSingleVariableDesignation(SingleVariableDesignationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSingleVariableDesignation(node); - } - public override void VisitSizeOfExpression(SizeOfExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSizeOfExpression(node); - } - public override void VisitSkippedTokensTrivia(SkippedTokensTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSkippedTokensTrivia(node); - } - public override void VisitSlicePattern(SlicePatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSlicePattern(node); - } - public override void VisitSpreadElement(SpreadElementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSpreadElement(node); - } - public override void VisitStackAllocArrayCreationExpression(StackAllocArrayCreationExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitStackAllocArrayCreationExpression(node); - } - public override void VisitStructDeclaration(StructDeclarationSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitStructDeclaration(node); - } - public override void VisitSubpattern(SubpatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSubpattern(node); - } - public override void VisitSwitchExpression(SwitchExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSwitchExpression(node); - } - public override void VisitSwitchExpressionArm(SwitchExpressionArmSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSwitchExpressionArm(node); - } - public override void VisitSwitchSection(SwitchSectionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSwitchSection(node); - } - public override void VisitSwitchStatement(SwitchStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitSwitchStatement(node); - } - public override void VisitThrowExpression(ThrowExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitThrowExpression(node); - } - public override void VisitThrowStatement(ThrowStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitThrowStatement(node); - } - public override void VisitTryStatement(TryStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTryStatement(node); - } - public override void VisitTupleElement(TupleElementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTupleElement(node); - } - public override void VisitTupleExpression(TupleExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTupleExpression(node); - } - public override void VisitTupleType(TupleTypeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTupleType(node); - } - public override void VisitTypeConstraint(TypeConstraintSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTypeConstraint(node); - } - public override void VisitTypeCref(TypeCrefSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTypeCref(node); - } - public override void VisitTypeOfExpression(TypeOfExpressionSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - - ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens(); - - for (int i = 0; i < nodesAndTokens.Count; i++) - { - SyntaxNode? asNode = nodesAndTokens[i].AsNode(); - - if (asNode != null) - { - SyntaxKind kind = asNode.Kind(); - - switch (kind) - { - case SyntaxKind.IdentifierName: - VisitIdentifierName((IdentifierNameSyntax)asNode); - break; - default: - Log.ErrorLine($"asNode : {kind}\n|{asNode.ToFullString()}|"); - break; - } - } - else - { - SyntaxToken asToken = nodesAndTokens[i].AsToken(); - SyntaxKind kind = asToken.Kind(); - - switch (kind) - { - case SyntaxKind.OpenParenToken: - case SyntaxKind.CloseParenToken: - case SyntaxKind.TypeOfKeyword: - VisitToken(asToken); - break; - default: - Log.ErrorLine($"asToken : {kind}"); - break; - } - } - } - } - public override void VisitTypeParameter(TypeParameterSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTypeParameter(node); - } - public override void VisitTypeParameterConstraintClause(TypeParameterConstraintClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTypeParameterConstraintClause(node); - } - public override void VisitTypeParameterList(TypeParameterListSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTypeParameterList(node); - } - public override void VisitTypePattern(TypePatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitTypePattern(node); - } - public override void VisitUnaryPattern(UnaryPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitUnaryPattern(node); - } - public override void VisitUndefDirectiveTrivia(UndefDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitUndefDirectiveTrivia(node); - } - public override void VisitUnsafeStatement(UnsafeStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitUnsafeStatement(node); - } - public override void VisitUsingDirective(UsingDirectiveSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitUsingDirective(node); - } - public override void VisitUsingStatement(UsingStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitUsingStatement(node); - } - public override void VisitVarPattern(VarPatternSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitVarPattern(node); - } - public override void VisitWarningDirectiveTrivia(WarningDirectiveTriviaSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitWarningDirectiveTrivia(node); - } - public override void VisitWhenClause(WhenClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitWhenClause(node); - } - public override void VisitWhereClause(WhereClauseSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitWhereClause(node); - } - public override void VisitWhileStatement(WhileStatementSyntax node) - { - if (_Options.Debug) - { - JSSB.Append("/*"); - string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries); - JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]); - JSSB.AppendLine("*/"); - } - -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitWhileStatement(node); - } - public override void VisitWithExpression(WithExpressionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitWithExpression(node); - } - public override void VisitXmlCDataSection(XmlCDataSectionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlCDataSection(node); - } - public override void VisitXmlComment(XmlCommentSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlComment(node); - } - public override void VisitXmlCrefAttribute(XmlCrefAttributeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlCrefAttribute(node); - } - public override void VisitXmlElement(XmlElementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlElement(node); - } - public override void VisitXmlElementEndTag(XmlElementEndTagSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlElementEndTag(node); - } - public override void VisitXmlElementStartTag(XmlElementStartTagSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlElementStartTag(node); - } - public override void VisitXmlEmptyElement(XmlEmptyElementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlEmptyElement(node); - } - - public override void VisitXmlName(XmlNameSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlName(node); - } - public override void VisitXmlNameAttribute(XmlNameAttributeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlNameAttribute(node); - } - public override void VisitXmlPrefix(XmlPrefixSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlPrefix(node); - } - public override void VisitXmlProcessingInstruction(XmlProcessingInstructionSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlProcessingInstruction(node); - } - public override void VisitXmlText(XmlTextSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlText(node); - } - public override void VisitXmlTextAttribute(XmlTextAttributeSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitXmlTextAttribute(node); - } - public override void VisitYieldStatement(YieldStatementSyntax node) - { -#if DEBUG - Log.WarningLine($"Not implemented or unlikely to be implemented. Calling base! (FullSpan: {node.FullSpan}|Location{node.GetLocation().GetLineSpan()})\n|{node.ToFullString()}|"); -#endif - base.VisitYieldStatement(node); - } - - - - public bool IdentifierToken(SyntaxNode node) - { - string text = string.Empty; - SyntaxToken identifier = new(); - - if (node is IdentifierNameSyntax ins) - { - text = ins.Identifier.Text; - identifier = ins.Identifier; - } - - if (node is GenericNameSyntax gns) - { - text = gns.Identifier.Text; - identifier = gns.Identifier; - } - - SymbolInfo? symbolInfo = null; - - try - { - if (_SNPropertyType != null) - symbolInfo = _Model.GetSymbolInfo(_SNPropertyType); - else - symbolInfo = _Model.GetSymbolInfo(node); - } - catch (Exception e) - { - symbolInfo = null; - /* - ImmutableArray diags = _Model.GetDeclarationDiagnostics(); - foreach (Diagnostic item in diags) - { - Log.WarningLine(item.ToString()); - } - */ - Log.WarningLine(e.ToString()); - //throw; - } - - ISymbol? iSymbol = null; - - if (symbolInfo?.CandidateSymbols.Length >= 1) - iSymbol = symbolInfo?.CandidateSymbols[0]; - else - iSymbol = symbolInfo?.Symbol; - - if (iSymbol != null && - iSymbol.Kind != SymbolKind.ErrorType && - iSymbol.Kind != SymbolKind.DynamicType && - iSymbol.Kind != SymbolKind.Namespace) - { - string? _containingNamespace = iSymbol.ContainingNamespace.ToString(); - if (_containingNamespace == null) - { - Log.ErrorLine("_containingNamespace is null"); - _containingNamespace = string.Empty; - } - - if (_GlobalStatement || _containingNamespace.Contains(_NameSpaceStr)) - { - if (iSymbol.Kind == SymbolKind.Parameter || - iSymbol.Kind == SymbolKind.Local) - { - return false; - } - } - - if (_GlobalStatement) - { - if (iSymbol.Kind == SymbolKind.Method && - ((IMethodSymbol)iSymbol).MethodKind == MethodKind.LocalFunction) - return false; - } - - if (_containingNamespace.Contains(_NameSpaceStr) && !_GlobalStatement) - { - if (!_ThisIsUsed) - { - //see "Test_This" for example. - if (node.Parent is MemberAccessExpressionSyntax member) - { - ISymbol? _iSymbolParent = _Model.GetSymbolInfo(member.Expression).Symbol; - - if (_iSymbolParent != null && (_iSymbolParent.Kind == SymbolKind.Local || - _iSymbolParent.Kind == SymbolKind.Method)) - return false; - } - - if (iSymbol != null && !iSymbol.IsStatic) - { - if (((iSymbol.Kind == SymbolKind.Method && - ((IMethodSymbol)iSymbol).MethodKind == MethodKind.Ordinary)) || - iSymbol.Kind == SymbolKind.Property || - iSymbol.Kind == SymbolKind.Field) - { - ITypeSymbol? _base = _CurrentClassSymbol; - string? _type = iSymbol.ContainingType?.ToString(); - if (_type != null) - { - while (_base != null) - { - if (_type.EndsWith(_base.ToString())) - { - VisitLeadingTrivia(identifier); - - JSSB.Append($"this."); - VisitToken(identifier.WithoutTrivia()); - - VisitTrailingTrivia(identifier); - - _ThisIsUsed = true; - - return true; - } - _base = _base.BaseType; - } - } - } - } - } - - return false; - } - } - - if (iSymbol != null && iSymbol.ContainingType != null && iSymbol.ContainingType.IsAnonymousType == true) - { - if (CustomCSNamesToJS(node) == false) - { - VisitLeadingTrivia(identifier); - JSSB.Append(text); - VisitTrailingTrivia(identifier); - } - return true; - } - - if (CustomCSNamesToJS(node) == false) - { - if (BuiltInTypesGenerics(node, iSymbol) == false) - { - return false; - } - } - - // - // - //Adding trivia after a IdentifierToken. - if (node is IdentifierNameSyntax _identifierName) - { - VisitTrailingTrivia(_identifierName.Identifier); - } - else if (node is GenericNameSyntax _genericName) - { - VisitTrailingTrivia(_genericName.Identifier); - } - - return true; - } - - private bool CustomCSNamesToJS(SyntaxNode? node) - { - if (node is IdentifierNameSyntax _identifierName) - { - if (_Options.CustomCSNamesToJS.TryGetValue(_identifierName.Identifier.Text, out string? _value)) - { - VisitLeadingTrivia(_identifierName.Identifier); - JSSB.Append(_value); - return true; - } - } - else if (node is GenericNameSyntax _genericName) - { - if (_Options.CustomCSNamesToJS.TryGetValue(_genericName.Identifier.Text, out string? _value)) - { - VisitLeadingTrivia(_genericName.Identifier); - JSSB.Append(_value); - return true; - } - } - - return false; - } - - private bool BuiltInTypesGenerics(SyntaxNode nodeL, ISymbol? symbol) - { - IdentifierNameSyntax? node = nodeL as IdentifierNameSyntax; - - if (symbol == null) - { - Log.WarningLine($"node: \"{node}\", symbol is null. USE \"CustomCSNamesToJS\"!"); - return false; - } - if (symbol.Name == "dynamic") - { - //Hitting with "AllInOneNoPreprocessor-v6.cs" - Log.WarningLine($"node: \"{node}\", symbol is \"dynamic\"."); - return false; - } - - ISymbol typeSymbol = symbol; - - if (typeSymbol.Kind != SymbolKind.NamedType) - { - typeSymbol = symbol.ContainingSymbol; - - if (typeSymbol.Kind != SymbolKind.NamedType) - { - Log.WarningLine($"node: \"{node}\", typeSymbol is \"{typeSymbol.Kind}\". USE \"CustomCSNamesToJS\"!"); - return false; - } - } - - if (nodeL is IdentifierNameSyntax _identifierName) - { - VisitLeadingTrivia(_identifierName.Identifier); - } - else if (nodeL is GenericNameSyntax _genericName) - { - VisitLeadingTrivia(_genericName.Identifier); - } - - string typeName = typeSymbol.Name; - - string? jsStr = _NETAPI.ReturnJSString(typeName); - if (jsStr == null) - { - Log.WarningLine($"typeSymbol: \"{typeSymbol}\" Is not supported! USE \"CustomCSNamesToJS\""); - return false; - } - else - { - if (typeName == symbol.Name) - { - JSSB.Append($"{jsStr}"); - return true; - } - jsStr = _NETAPI.ReturnJSString(typeName, symbol.Name); - if (jsStr == null) - { - Log.WarningLine($"node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\""); - return false; - } - else - { - JSSB.Append($"{jsStr}"); - return true; - } - } - } -} - -internal class Prop -{ - public string Name = string.Empty; - public SyntaxNode? SNGet = null; - public SyntaxNode? SNSet = null; -} \ No newline at end of file diff --git a/CSharpToJavaScript/WithSemanticRewriter.cs b/CSharpToJavaScript/WithSemanticRewriter.cs new file mode 100644 index 00000000..81f3d572 --- /dev/null +++ b/CSharpToJavaScript/WithSemanticRewriter.cs @@ -0,0 +1,600 @@ +using CSharpToJavaScript.Utils; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace CSharpToJavaScript; + +internal class WithSemanticRewriter : CSharpSyntaxRewriter +{ + private readonly NETAPI _NETAPI = new(); + + private readonly SemanticModel _Model; + private readonly CSTOJSOptions _Options; + + private ITypeSymbol? _CurrentClassSymbol = null; + + private bool _NoneWithTrailingDotRemoved = false; + + public Dictionary ReplaceNodes = new(); + + public WithSemanticRewriter(SemanticModel semanticModel, CSTOJSOptions options) + { + _Model = semanticModel; + _Options = options; + } + +#if DEBUG + public override SyntaxNode? Visit(SyntaxNode? node) + { + if (node != null) + Log.InfoLine($"kind: {node.Kind()} \n\t{node.ToString()}"); + + return base.Visit(node); + } +#endif + + public override SyntaxNode? VisitClassDeclaration(ClassDeclarationSyntax node) + { + _CurrentClassSymbol = _Model.GetDeclaredSymbol(node); + + node = (ClassDeclarationSyntax)base.VisitClassDeclaration(node)!; + + return node; + } + public override SyntaxNode? VisitMemberAccessExpression(MemberAccessExpressionSyntax node) + { + node = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!; + + if (_NoneWithTrailingDotRemoved) + { + SyntaxNode _node = node.Name; + if (ReplaceNodes.ContainsKey(_node)) + _node = ReplaceNodes[_node]; + + ReplaceNodes.Add(node, _node); + _NoneWithTrailingDotRemoved = false; + } + + if (node.Expression is IdentifierNameSyntax syntax) + { + if (TryReplaceIdentifierWithThis(syntax)) + return node; + } + return node; + } + public override SyntaxNode? VisitElementAccessExpression(ElementAccessExpressionSyntax node) + { + node = (ElementAccessExpressionSyntax)base.VisitElementAccessExpression(node)!; + + if (node.Expression is IdentifierNameSyntax) + { + if (TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Expression)) + return node; + } + + return node; + } + public override SyntaxNode? VisitInterpolation(InterpolationSyntax node) + { + if (node.Expression is IdentifierNameSyntax) + { + if (TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Expression)) + return node; + } + node = (InterpolationSyntax)base.VisitInterpolation(node)!; + + return node; + } + public override SyntaxNode? VisitArgument(ArgumentSyntax node) + { + if (node.Expression is IdentifierNameSyntax) + { + if (TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Expression)) + return node; + } + node = (ArgumentSyntax)base.VisitArgument(node)!; + + return node; + } + public override SyntaxNode? VisitInvocationExpression(InvocationExpressionSyntax node) + { + node = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!; + + if (node.Expression is IdentifierNameSyntax || + node.Expression is GenericNameSyntax) + { + ISymbol? symbol = TryGetISymbol(node.Expression); + + if (symbol != null) + { + if (TryReplaceIdentifierWithThis((SimpleNameSyntax)node.Expression)) + return node; + + ImmutableArray _attributeData = symbol.GetAttributes(); + for (int i = 0; i < _attributeData.Length; i++) + { + if (_attributeData[i].AttributeClass != null) + { + if (_attributeData[i].AttributeClass!.Name == nameof(BinaryAttribute)) + { + IdentifierNameSyntax _identifier = SyntaxFactory.IdentifierName(_attributeData[i].ConstructorArguments[0].Value.ToString()) + .WithAdditionalAnnotations(BinaryAttribute.Annotation) + .WithLeadingTrivia(node.Expression.GetLeadingTrivia()) + .WithTrailingTrivia(node.Expression.GetTrailingTrivia()); + + if (ReplaceNodes.ContainsKey(node.Expression)) + ReplaceNodes[node.Expression] = _identifier; + else + ReplaceNodes.Add(node.Expression, _identifier); + + return node; + } + if (_attributeData[i].AttributeClass!.Name == nameof(UnaryAttribute)) + { + IdentifierNameSyntax _identifier = SyntaxFactory.IdentifierName(_attributeData[i].ConstructorArguments[0].Value.ToString()) + .WithAdditionalAnnotations(UnaryAttribute.Annotation) + .WithLeadingTrivia(node.Expression.GetLeadingTrivia()) + .WithTrailingTrivia(node.Expression.GetTrailingTrivia()); + + if (ReplaceNodes.ContainsKey(node.Expression)) + ReplaceNodes[node.Expression] = _identifier; + else + ReplaceNodes.Add(node.Expression, _identifier); + + return node; + } + if (_attributeData[i].AttributeClass!.Name == nameof(GenericUnaryAttribute)) + { + TypeSyntax _arg = ((GenericNameSyntax)node.Expression).TypeArgumentList.Arguments[0]; + + //Check if the generic is contained in ReplaceNodes. + //If yes, then use the replaced node. + //The same applies to GenericBinaryAttribute. + if (ReplaceNodes.ContainsKey(_arg)) + _arg = (TypeSyntax)ReplaceNodes[_arg]; + + //Replace GenericName with IdentifierName from an attribute. + IdentifierNameSyntax _identifier = SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(_attributeData[i].ConstructorArguments[0].Value.ToString())) + .WithAdditionalAnnotations(UnaryAttribute.Annotation) + .WithLeadingTrivia(node.Expression.GetLeadingTrivia()) + .WithTrailingTrivia(node.Expression.GetTrailingTrivia()); + + if (ReplaceNodes.ContainsKey(node.Expression)) + ReplaceNodes[node.Expression] = _identifier; + else + ReplaceNodes.Add(node.Expression, _identifier); + + ReplaceNodes.Add(node.ArgumentList, node.ArgumentList + .AddArguments(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(_arg.ToString())))); + + return node; + } + if (_attributeData[i].AttributeClass!.Name == nameof(GenericBinaryAttribute)) + { + TypeSyntax _arg = ((GenericNameSyntax)node.Expression).TypeArgumentList.Arguments[0]; + + if (ReplaceNodes.ContainsKey(_arg)) + _arg = (TypeSyntax)ReplaceNodes[_arg]; + + IdentifierNameSyntax _identifier = SyntaxFactory.IdentifierName(_attributeData[i].ConstructorArguments[0].Value.ToString()) + .WithAdditionalAnnotations(BinaryAttribute.Annotation) + .WithLeadingTrivia(node.Expression.GetLeadingTrivia()) + .WithTrailingTrivia(node.Expression.GetTrailingTrivia()); + + if (ReplaceNodes.ContainsKey(node.Expression)) + ReplaceNodes[node.Expression] = _identifier; + else + ReplaceNodes.Add(node.Expression, _identifier); + + ReplaceNodes.Add(node.ArgumentList, node.ArgumentList + .AddArguments(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(_arg.ToString()))) + .NormalizeWhitespace()); + + return node; + } + } + } + } + } + + if (node.Expression is MemberAccessExpressionSyntax member) + { + ISymbol? symbol = TryGetISymbol(member); + + if (symbol != null) + { + ImmutableArray _attributeData = symbol.GetAttributes(); + for (int i = 0; i < _attributeData.Length; i++) + { + if (_attributeData[i].AttributeClass != null) + { + if (_attributeData[i].AttributeClass!.Name == nameof(GenericAsArgumentAttribute)) + { + TypeSyntax _arg = ((GenericNameSyntax)member.Name).TypeArgumentList.Arguments[0]; + + if (ReplaceNodes.ContainsKey(_arg)) + _arg = (TypeSyntax)ReplaceNodes[_arg]; + + ReplaceNodes.Add(node.ArgumentList, node.ArgumentList + .AddArguments(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(_arg.ToString()))) + .NormalizeWhitespace()); + + return node; + } + } + } + } + } + + return node; + } + public override SyntaxNode? VisitBinaryExpression(BinaryExpressionSyntax node) + { + if (node.Left is IdentifierNameSyntax) + { + TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Left); + } + if (node.Right is IdentifierNameSyntax) + { + TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Right); + } + node = (BinaryExpressionSyntax)base.VisitBinaryExpression(node)!; + + return node; + } + public override SyntaxNode? VisitAssignmentExpression(AssignmentExpressionSyntax node) + { + if (node.Left is IdentifierNameSyntax) + { + TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Left); + } + if (node.Right is IdentifierNameSyntax) + { + TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Right); + } + node = (AssignmentExpressionSyntax)base.VisitAssignmentExpression(node)!; + + return node; + } + public override SyntaxNode? VisitReturnStatement(ReturnStatementSyntax node) + { + if (node.Expression is IdentifierNameSyntax) + { + TryReplaceIdentifierWithThis((IdentifierNameSyntax)node.Expression); + } + node = (ReturnStatementSyntax)base.VisitReturnStatement(node)!; + + return node; + } + public override SyntaxNode? VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node) + { + if (node.Operand is IdentifierNameSyntax syntax) + { + TryReplaceIdentifierWithThis(syntax); + } + + node = (PrefixUnaryExpressionSyntax)base.VisitPrefixUnaryExpression(node)!; + + return node; + } + public override SyntaxNode? VisitIfStatement(IfStatementSyntax node) + { + if (node.Condition is IdentifierNameSyntax syntax) + { + TryReplaceIdentifierWithThis(syntax); + } + + node = (IfStatementSyntax)base.VisitIfStatement(node)!; + + return node; + } + public override SyntaxNode? VisitCastExpression(CastExpressionSyntax node) + { + if (node.Expression is IdentifierNameSyntax syntax) + { + TryReplaceIdentifierWithThis(syntax); + } + + node = (CastExpressionSyntax)base.VisitCastExpression(node)!; + + return node; + } + public override SyntaxNode? VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) + { + node = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!; + + ISymbol? symbol = TryGetISymbol(node.Type); + + if (symbol != null) + { + ImmutableArray _attributeData = symbol.GetAttributes(); + for (int i = 0; i < _attributeData.Length; i++) + { + if (_attributeData[i].AttributeClass != null) + { + if (_attributeData[i].AttributeClass!.Name == nameof(ToObjectAttribute)) + { + ReplaceNodes.Add(node.Type, node.Type.WithAdditionalAnnotations(ToObjectAttribute.Annotation)); + break; + } + } + } + } + + return node; + } + public override SyntaxNode? VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node) + { + node = (ImplicitObjectCreationExpressionSyntax)base.VisitImplicitObjectCreationExpression(node)!; + + ISymbol? symbol = TryGetISymbol(node); + + if (symbol != null) + { + ArgumentListSyntax _args = node.ArgumentList; + InitializerExpressionSyntax? _initializer = node.Initializer; + + if (ReplaceNodes.ContainsKey(_args)) + _args = (ArgumentListSyntax)ReplaceNodes[_args]; + if (_initializer != null && ReplaceNodes.ContainsKey(_initializer)) + _initializer = (InitializerExpressionSyntax)ReplaceNodes[_initializer]; + + + SimpleNameSyntax _type = SyntaxFactory.IdentifierName(symbol.ContainingType.Name).WithLeadingTrivia(SyntaxFactory.Whitespace(" ")); + //Check if type needs to be replaced + VisitSimpleName(_type, symbol); + //if yes, use replaced node! + if (ReplaceNodes.ContainsKey(_type)) + _type = (SimpleNameSyntax)ReplaceNodes[_type]; + + ReplaceNodes.Add(node, SyntaxFactory.ObjectCreationExpression(node.NewKeyword, + _type, + _args, + _initializer)); + } + + return node; + } + + public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node) + { + VisitSimpleName(node, TryGetISymbol(node)); + return node; + } + public override SyntaxNode? VisitGenericName(GenericNameSyntax node) + { + node = (GenericNameSyntax)base.VisitGenericName(node)!; + VisitSimpleName(node, TryGetISymbol(node)); + return node; + } + public override SyntaxNode? VisitPredefinedType(PredefinedTypeSyntax node) + { + ISymbol? symbol = TryGetISymbol(node); + + if (symbol != null) + { + if (BuiltInTypesGenerics(node, symbol, out string str)) + { + ReplaceNodes.Add(node, SyntaxFactory.IdentifierName(str).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia())); + return node; + } + } + return node; + } + + private bool TryReplaceIdentifierWithThis(SimpleNameSyntax identifier) + { + ISymbol? symbol = TryGetISymbol(identifier); + + if (symbol != null && !symbol.IsStatic) + { + if (((symbol.Kind == SymbolKind.Method && + ((IMethodSymbol)symbol).MethodKind == MethodKind.Ordinary)) || + symbol.Kind == SymbolKind.Property || + symbol.Kind == SymbolKind.Field) + { + ITypeSymbol? _base = _CurrentClassSymbol; + + while (_base != null) + { + ImmutableArray _members = _base.GetMembers(); + + for (int i = 0; i < _members.Length; i++) + { + if (_members[i].Name == identifier.Identifier.Text) + { + MemberAccessExpressionSyntax _member = SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.ThisExpression(), identifier.WithoutTrivia()) + .WithLeadingTrivia(identifier.GetLeadingTrivia()) + .WithTrailingTrivia(identifier.GetTrailingTrivia()); + + ReplaceNodes.Add(identifier, _member); + + return true; + } + } + _base = _base.BaseType; + } + + } + } + + return false; + } + private void VisitSimpleName(SimpleNameSyntax identifier, ISymbol? symbol) + { + ISymbol? oldSymbol = symbol; + + if (symbol != null) + { + CheckParentAttributes: + + ImmutableArray _attributeData = symbol.GetAttributes(); + for (int i = 0; i < _attributeData.Length; i++) + { + if (_attributeData[i].AttributeClass != null) + { + if (_attributeData[i].AttributeClass!.Name == nameof(ValueAttribute)) + { + string _v = _attributeData[i].ConstructorArguments[0].Value.ToString(); + + ReplaceNodes.Add(identifier, SyntaxFactory.IdentifierName(_v).WithLeadingTrivia(identifier.Identifier.LeadingTrivia).WithTrailingTrivia(identifier.Identifier.TrailingTrivia)); + return; + } + + if (_attributeData[i].AttributeClass!.Name == nameof(ToAttribute)) + { + ToAttribute _toAttr = new(_attributeData[i].ConstructorArguments[0].Value.ToString()); + + if (_toAttr.To == ToAttribute.NoneWithLeadingDotRemoved) + { + SyntaxNode? _mae = identifier.Parent; + if (_mae == null) + { + Log.ErrorLine($"Parent of {identifier} is null"); + return; + } + if (_mae is not MemberAccessExpressionSyntax) + { + Log.ErrorLine($"Parent of {identifier} is {_mae.GetType()}. Should be MemberAccessExpressionSyntax"); + return; + } + + //Check if node is in ReplaceNodes. + //If yes, then use replaced node. + SyntaxNode _node = ((MemberAccessExpressionSyntax)_mae).Expression; + if (ReplaceNodes.ContainsKey(_node)) + _node = ReplaceNodes[_node]; + + ReplaceNodes.Add(identifier.Parent, _node); + return; + } + + if (_toAttr.To == ToAttribute.NoneWithTrailingDotRemoved) + { + SyntaxNode? _mae = identifier.Parent; + if (_mae == null) + { + Log.ErrorLine($"Parent of {identifier} is null"); + return; + } + if (_mae is not MemberAccessExpressionSyntax) + { + Log.ErrorLine($"Parent of {identifier} is {_mae.GetType()}. Should be MemberAccessExpressionSyntax"); + return; + } + + //Delay adding to ReplaceNodes until the full MemberAccessExpressionSyntax is processed. + _NoneWithTrailingDotRemoved = true; + return; + } + + ReplaceNodes.Add(identifier, SyntaxFactory.IdentifierName(_toAttr.Convert(identifier.Identifier.Text)).WithLeadingTrivia(identifier.Identifier.LeadingTrivia).WithTrailingTrivia(identifier.Identifier.TrailingTrivia)); + return; + } + } + } + if (symbol.ContainingType != null) + { + symbol = symbol.ContainingType; + goto CheckParentAttributes; + } + } + + symbol = oldSymbol; + + if (_Options.CustomCSNamesToJS.TryGetValue(identifier.Identifier.Text, out string? _value)) + { + ReplaceNodes.Add(identifier, SyntaxFactory.IdentifierName(_value)); + return; + } + + if (BuiltInTypesGenerics(identifier, symbol, out string str)) + { + ReplaceNodes.Add(identifier, SyntaxFactory.IdentifierName(str).WithLeadingTrivia(identifier.Identifier.LeadingTrivia).WithTrailingTrivia(identifier.Identifier.TrailingTrivia)); + return; + } + } + private bool BuiltInTypesGenerics(TypeSyntax node, ISymbol? symbol, out string str) + { + str = string.Empty; + + if (symbol == null) + { + Log.WarningLine($"node: \"{node}\", symbol is null. USE \"CustomCSNamesToJS\"!"); + return false; + } + if (symbol.Name == "dynamic") + { + //Hitting with "AllInOneNoPreprocessor-v6.cs" + Log.WarningLine($"node: \"{node}\", symbol is \"dynamic\"."); + return false; + } + + ISymbol typeSymbol = symbol; + + if (typeSymbol.Kind != SymbolKind.NamedType) + { + typeSymbol = symbol.ContainingSymbol; + if (typeSymbol == null) + { + Log.WarningLine($"node: \"{node}\", typeSymbol is null. USE \"CustomCSNamesToJS\"!"); + return false; + } + + if (typeSymbol.Kind != SymbolKind.NamedType) + { + Log.WarningLine($"node: \"{node}\", typeSymbol is \"{typeSymbol.Kind}\". USE \"CustomCSNamesToJS\"!"); + return false; + } + } + + string typeName = typeSymbol.Name; + + string? jsStr = _NETAPI.ReturnJSString(typeName); + if (jsStr == null) + { + Log.WarningLine($"typeSymbol: \"{typeSymbol}\" Is not supported! USE \"CustomCSNamesToJS\""); + return false; + } + else + { + if (typeName == symbol.Name) + { + str = jsStr; + return true; + } + jsStr = _NETAPI.ReturnJSString(typeName, symbol.Name); + if (jsStr == null) + { + Log.WarningLine($"node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", symbolName: \"{symbol.Name}\", Is not supported! USE \"CustomCSNamesToJS\""); + return false; + } + else + { + str = jsStr; + return true; + } + } + } + private ISymbol? TryGetISymbol(SyntaxNode node) + { + ISymbol? symbol = null; + + SymbolInfo? symbolInfo = _Model.GetSymbolInfo(node); + + if (symbolInfo == null) + return symbol; + + if (symbolInfo?.CandidateSymbols.Length >= 1) + symbol = symbolInfo?.CandidateSymbols[0]; + else + symbol = symbolInfo?.Symbol; + + return symbol; + } +} diff --git a/CSharpToJavaScript/WithoutSemanticRewriter.cs b/CSharpToJavaScript/WithoutSemanticRewriter.cs new file mode 100644 index 00000000..91bb4811 --- /dev/null +++ b/CSharpToJavaScript/WithoutSemanticRewriter.cs @@ -0,0 +1,611 @@ +using CSharpToJavaScript.Utils; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; +using System.Globalization; + +namespace CSharpToJavaScript; + +internal class WithoutSemanticRewriter : CSharpSyntaxRewriter +{ + private readonly CSTOJSOptions _Options; + public static SyntaxAnnotation StaticConstructor { get; set; } = new("StaticConstructor"); + + public WithoutSemanticRewriter(CSTOJSOptions options) + { + _Options = options; + } + +#if DEBUG + public override SyntaxNode? Visit(SyntaxNode? node) + { + if (node != null) + { + Log.InfoLine($"kind: {node.Kind()} \n\t{node.ToString()}"); + return base.Visit(node); + } + else + return null; + } +#endif + public override SyntaxNode? VisitClassDeclaration(ClassDeclarationSyntax node) + { + node = (ClassDeclarationSyntax)base.VisitClassDeclaration(node)!; + + if (node.Modifiers.Count >= 1) + { + node = node.ReplaceToken(node.Keyword, node.Keyword.WithLeadingTrivia(node.Modifiers[0].LeadingTrivia).WithTrailingTrivia(node.Modifiers[0].TrailingTrivia)); + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + } + + for (int i = 0; i < node.Members.Count; i++) + { + //properties need to be handled in VisitClassDeclaration + if (node.Members[i].IsKind(SyntaxKind.PropertyDeclaration)) + { + PropertyDeclarationSyntax _prop = (PropertyDeclarationSyntax)node.Members[i]; + + SyntaxToken? _static = TryGetStaticModifier(_prop.Modifiers); + + if (_prop.AccessorList != null) + { + //TODO! do MakePropertiesEnumerable + //in seperate rewriter before WithoutSemanticRewriter + int _constructorIndex = -1; + string _enumProp = $"Object.defineProperty(this, '{_prop.Identifier}', {{ enumerable: true, "; + + if (_Options.MakePropertiesEnumerable) + { + for (int j = 0; j < node.Members.Count; j++) + { + if (node.Members[j] is ConstructorDeclarationSyntax) + { + _constructorIndex = j; + break; + } + } + } + + int _indexToInsert = i + 1; + + //TODO! + //somehow without ToString. + string _getSetStr = _prop.AccessorList.ToString().Trim().Replace(" ", ""); + if (_getSetStr == "{get;set;}" || _getSetStr == "{get;}") + { + string _fieldIdentifier = $"#_{_prop.Identifier}_"; + + FieldDeclarationSyntax _field = SyntaxFactory.FieldDeclaration( + SyntaxFactory.VariableDeclaration(SyntaxFactory.IdentifierName(""), + SyntaxFactory.SingletonSeparatedList( + SyntaxFactory.VariableDeclarator( + SyntaxFactory.Identifier(_fieldIdentifier)) + .WithInitializer(_prop.Initializer)))) + .WithLeadingTrivia(_prop.GetLeadingTrivia()) + .WithTrailingTrivia(_prop.GetTrailingTrivia()); + + if (_static != null) + _field = _field.WithoutLeadingTrivia().WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + + node = node.ReplaceNode(node.Members[i], _field); + + if (_getSetStr.Contains("get;")) + { + if (_Options.MakePropertiesEnumerable) + { + _enumProp += $"get: function() {{ return this.{_fieldIdentifier}; }}"; + } + else + { + MethodDeclarationSyntax _getM = SyntaxFactory.MethodDeclaration( + SyntaxFactory.IdentifierName("get "), _prop.Identifier.WithoutTrivia()) + .WithBody( + SyntaxFactory.Block( + SyntaxFactory.ReturnStatement( + SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.IdentifierName("this"), SyntaxFactory.IdentifierName(_fieldIdentifier)) + ).NormalizeWhitespace())) + .WithLeadingTrivia(_prop.GetLeadingTrivia()) + .WithTrailingTrivia(_prop.GetTrailingTrivia()); + + if (_static != null) + _getM = _getM.WithoutLeadingTrivia().WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + + node = node.WithMembers(node.Members.Insert(_indexToInsert++, _getM)); + } + } + if (_getSetStr.Contains("get;") && _getSetStr.Contains("set;")) + { + if (_Options.MakePropertiesEnumerable) + { + _enumProp += $", set: function (value) {{ this.{_fieldIdentifier} = value; }} }}"; + } + else + { + MethodDeclarationSyntax _setM = SyntaxFactory.MethodDeclaration( + SyntaxFactory.IdentifierName("set "), _prop.Identifier.WithoutTrivia()) + .WithParameterList( + SyntaxFactory.ParameterList( + SyntaxFactory.SingletonSeparatedList( + SyntaxFactory.Parameter(SyntaxFactory.Identifier("value"))))) + .WithBody( + SyntaxFactory.Block(SyntaxFactory.ExpressionStatement( + SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, + SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.IdentifierName("this"), SyntaxFactory.IdentifierName(_fieldIdentifier)), + SyntaxFactory.IdentifierName("value")).NormalizeWhitespace()))) + .WithLeadingTrivia(_prop.GetLeadingTrivia()) + .WithTrailingTrivia(_prop.GetTrailingTrivia()); + + if (_static != null) + _setM = _setM.WithoutLeadingTrivia().WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + + node = node.WithMembers(node.Members.Insert(_indexToInsert++, _setM)); + } + } + + if (_constructorIndex == -1) + { + Log.WarningLine($"Constructor is 'null' for: {node.Identifier}. MakePropertiesEnumerable is ignored!"); + + } + else + { + _enumProp += ")"; + + ConstructorDeclarationSyntax _constr = (ConstructorDeclarationSyntax)node.Members[_constructorIndex]; + + node = node.ReplaceNode(_constr.Body, + _constr.Body.WithStatements(_constr.Body.Statements.Insert(0, + SyntaxFactory.ExpressionStatement( + SyntaxFactory.IdentifierName(_enumProp)) + .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed))).WithLeadingTrivia(_constr.Body.GetLeadingTrivia()).WithTrailingTrivia(_constr.Body.GetTrailingTrivia())); + } + } + else + { + for (int j = 0; j < _prop.AccessorList.Accessors.Count; j++) + { + if (_prop.AccessorList.Accessors[j].Keyword.Text == "get") + { + MethodDeclarationSyntax _getM = SyntaxFactory.MethodDeclaration( + SyntaxFactory.IdentifierName("get ") + .WithLeadingTrivia(_prop.GetLeadingTrivia()), _prop.Identifier.WithoutTrivia()) + .WithTrailingTrivia(_prop.AccessorList.Accessors[j].Keyword.TrailingTrivia) + .WithBody(_prop.AccessorList.Accessors[j].Body) + .WithLeadingTrivia(_prop.GetLeadingTrivia()) + .WithTrailingTrivia(_prop.AccessorList.Accessors[j].GetTrailingTrivia()); + + if (_static != null) + _getM = _getM.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + + node = node.WithMembers(node.Members.Insert(_indexToInsert++, _getM)); + } + if (_prop.AccessorList.Accessors[j].Keyword.Text == "set") + { + MethodDeclarationSyntax _setM = SyntaxFactory.MethodDeclaration( + SyntaxFactory.IdentifierName("set ") + .WithLeadingTrivia(_prop.GetLeadingTrivia()), _prop.Identifier.WithoutTrivia()) + .WithParameterList( + SyntaxFactory.ParameterList( + SyntaxFactory.SingletonSeparatedList( + SyntaxFactory.Parameter(SyntaxFactory.Identifier("value"))))) + .WithTrailingTrivia(_prop.AccessorList.Accessors[j].Keyword.TrailingTrivia) + .WithBody(_prop.AccessorList.Accessors[j].Body) + .WithLeadingTrivia(_prop.GetLeadingTrivia()) + .WithTrailingTrivia(_prop.AccessorList.Accessors[j].GetTrailingTrivia()); + + if (_static != null) + _setM = _setM.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + + node = node.WithMembers(node.Members.Insert(_indexToInsert++, _setM)); + } + } + + node = node.RemoveNode(node.Members[i], SyntaxRemoveOptions.KeepNoTrivia); + } + } + } + } + + return node; + } + public override SyntaxNode? VisitConstructorDeclaration(ConstructorDeclarationSyntax node) + { + node = (ConstructorDeclarationSyntax)base.VisitConstructorDeclaration(node)!; + + SyntaxToken? staticModifier = TryGetStaticModifier(node.Modifiers); + if (staticModifier == null) + node = node.ReplaceToken(node.Identifier, SyntaxFactory.Identifier("constructor").WithLeadingTrivia(node.Identifier.LeadingTrivia)); + else + node = node.ReplaceToken(node.Identifier, SyntaxFactory.Identifier("static").WithLeadingTrivia(node.Identifier.LeadingTrivia).WithAdditionalAnnotations(StaticConstructor)); + + if (node.Modifiers.Count >= 1) + { + node = node.ReplaceToken(node.Identifier, node.Identifier.WithLeadingTrivia(node.Modifiers[0].LeadingTrivia)); + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + } + + if (node.Initializer != null) + { + ArgumentListSyntax _args = node.Initializer.ArgumentList.WithoutTrailingTrivia(); + node = node.RemoveNode(node.Initializer, SyntaxRemoveOptions.KeepTrailingTrivia); + + ExpressionStatementSyntax _super = SyntaxFactory.ExpressionStatement( + SyntaxFactory.InvocationExpression(SyntaxFactory.IdentifierName("super"), _args)); + + if (node.Body.Statements.Count > 0) + _super = _super.WithLeadingTrivia(node.Body.Statements[0].GetLeadingTrivia()).WithTrailingTrivia(node.Body.Statements[0].GetTrailingTrivia()); + + node = node.ReplaceNode(node.Body, node.Body.WithStatements(node.Body.Statements.Insert(0, _super))); + } + + return node; + } + public override SyntaxNode? VisitFieldDeclaration(FieldDeclarationSyntax node) + { + node = (FieldDeclarationSyntax)base.VisitFieldDeclaration(node)!; + + if (node.Modifiers.Count >= 1) + { + SyntaxToken? _static = TryGetStaticModifier(node.Modifiers); + if (_static == null) + { + node = node.ReplaceNode(node.Declaration.Type, node.Declaration.Type.WithLeadingTrivia(node.Modifiers[0].LeadingTrivia).WithTrailingTrivia(node.Modifiers[0].TrailingTrivia)); + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + } + else + { + //Clear modifiers first. + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + //Add static modifier. + node = node.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + } + } + + node = node.WithDeclaration(node.Declaration.WithType(SyntaxFactory.IdentifierName("")).WithLeadingTrivia(node.Declaration.Type.GetLeadingTrivia())); + + return node; + } + public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node) + { + node = (MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!; + + node = node.ReplaceToken(node.Identifier, node.Identifier.WithLeadingTrivia(node.ReturnType.GetLeadingTrivia())); + node = node.ReplaceNode(node.ReturnType, SyntaxFactory.ParseTypeName("")); + + if (node.Modifiers.Count >= 1) + { + SyntaxToken? _static = TryGetStaticModifier(node.Modifiers); + SyntaxToken? _async = TryGetAsyncModifier(node.Modifiers); + + if (_static == null && _async == null) + { + node = node.ReplaceToken(node.Identifier, node.Identifier.WithLeadingTrivia(node.Modifiers[0].LeadingTrivia)); + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + } + else if(_async == null) + { + //Clear modifiers first. + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + //Add static modifier. + node = node.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + } + else if (_static == null) + { + //Clear modifiers first. + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + //Add async modifier. + node = node.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_async)); + } + else + { + //Clear modifiers first. + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + //clear leading trivia for async + _async = _async.Value.WithoutTrivia().WithTrailingTrivia(_async.Value.TrailingTrivia); + //Add static and async modifier. + node = node.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static, (SyntaxToken)_async)); + } + } + + return node; + } + public override SyntaxNode? VisitPropertyDeclaration(PropertyDeclarationSyntax node) + { + node = (PropertyDeclarationSyntax)base.VisitPropertyDeclaration(node)!; + + if (node.Modifiers.Count >= 1) + { + SyntaxToken? _static = TryGetStaticModifier(node.Modifiers); + if (_static == null) + { + node = node.ReplaceNode(node.Type, node.Type.WithLeadingTrivia(node.Modifiers[0].LeadingTrivia).WithTrailingTrivia(node.Modifiers[0].TrailingTrivia)); + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + } + else + { + //Clear modifiers first. + node = node.ReplaceTokens(node.Modifiers, (o, r) => SyntaxFactory.Token(SyntaxKind.None)); + //Add static modifier. + node = node.WithModifiers(SyntaxFactory.TokenList((SyntaxToken)_static)); + } + } + + node = node.ReplaceNode(node.Type, SyntaxFactory.IdentifierName("").WithLeadingTrivia(node.Type.GetLeadingTrivia())); + + return node; + } + public override SyntaxNode? VisitLocalFunctionStatement(LocalFunctionStatementSyntax node) + { + node = (LocalFunctionStatementSyntax)base.VisitLocalFunctionStatement(node)!; + + node = node.ReplaceNode(node.ReturnType, SyntaxFactory.IdentifierName("function").WithLeadingTrivia(node.ReturnType.GetLeadingTrivia()).WithTrailingTrivia(node.ReturnType.GetTrailingTrivia())); + + return node; + } + public override SyntaxNode? VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) + { + node = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!; + + if (node.Type.HasAnnotation(ToObjectAttribute.Annotation)) + { + SyntaxTriviaList trivias = node.ArgumentList.GetTrailingTrivia(); + trivias = trivias.AddRange(node.Initializer.GetLeadingTrivia()); + + return node.Initializer.WithLeadingTrivia(trivias); + } + return node; + } + public override SyntaxNode? VisitVariableDeclaration(VariableDeclarationSyntax node) + { + if (node.Parent is ForStatementSyntax || + node.Parent is LocalDeclarationStatementSyntax) + { + if (_Options.UseVarOverLet) + node = node.ReplaceNode(node.Type, SyntaxFactory.IdentifierName("var").WithLeadingTrivia(node.Type.GetLeadingTrivia()).WithTrailingTrivia(node.Type.GetTrailingTrivia())); + else + node = node.ReplaceNode(node.Type, SyntaxFactory.IdentifierName("let").WithLeadingTrivia(node.Type.GetLeadingTrivia()).WithTrailingTrivia(node.Type.GetTrailingTrivia())); + + } + + node = (VariableDeclarationSyntax)base.VisitVariableDeclaration(node)!; + + return node; + } + public override SyntaxNode? VisitBaseExpression(BaseExpressionSyntax node) + { + return SyntaxFactory.IdentifierName("super").WithLeadingTrivia(node.GetLeadingTrivia()); + } + public override SyntaxNode? VisitParameter(ParameterSyntax node) + { + node = (ParameterSyntax)base.VisitParameter(node)!; + + return SyntaxFactory.Parameter(attributeLists: node.AttributeLists, modifiers: node.Modifiers, type: null, identifier: node.Identifier, @default: node.Default); + } + public override SyntaxNode? VisitArrayCreationExpression(ArrayCreationExpressionSyntax node) + { + node = (ArrayCreationExpressionSyntax)base.VisitArrayCreationExpression(node)!; + + InitializerExpressionSyntax? initializer = node.Initializer; + ArgumentListSyntax arguments = SyntaxFactory.ArgumentList(); + + if (initializer != null) + { + List _list = new(); + for (int i = 0; i < initializer.Expressions.Count; i++) + { + _list.Add(SyntaxFactory.Argument(initializer.Expressions[i])); + } + arguments = arguments.WithArguments(SyntaxFactory.SeparatedList(_list)); + } + ObjectCreationExpressionSyntax obj = SyntaxFactory.ObjectCreationExpression(node.NewKeyword, SyntaxFactory.IdentifierName("Array"), argumentList: arguments, initializer: null); + + return obj; + } + public override SyntaxNode? VisitCastExpression(CastExpressionSyntax node) + { + return node.Expression; + } + public override SyntaxNode? VisitParenthesizedExpression(ParenthesizedExpressionSyntax node) + { + if (node.Expression.IsKind(SyntaxKind.AsExpression) || node.Expression.IsKind(SyntaxKind.CastExpression)) + { + node = (ParenthesizedExpressionSyntax)base.VisitParenthesizedExpression(node)!; + return node.Expression.WithLeadingTrivia(node.GetLeadingTrivia()); + } + else + { + node = (ParenthesizedExpressionSyntax)base.VisitParenthesizedExpression(node)!; + return node; + } + } + public override SyntaxNode? VisitBinaryExpression(BinaryExpressionSyntax node) + { + node = (BinaryExpressionSyntax)base.VisitBinaryExpression(node)!; + + if (node.OperatorToken.IsKind(SyntaxKind.AsKeyword)) + return node.Left.WithoutTrailingTrivia(); + + return node; + } + public override SyntaxNode? VisitLiteralExpression(LiteralExpressionSyntax node) + { + node = (LiteralExpressionSyntax)base.VisitLiteralExpression(node)!; + if (node.IsKind(SyntaxKind.NumericLiteralExpression)) + { + string _value = node.Token.Text; + + _value = _value.Replace("_", ""); + + if (_value.EndsWith('f') || + _value.EndsWith('d') || + _value.EndsWith('m') || + _value.EndsWith('u') || + _value.EndsWith('l') || + _value.EndsWith('F') || + _value.EndsWith('D') || + _value.EndsWith('M') || + _value.EndsWith('U') || + _value.EndsWith('L')) + _value = _value.Remove(_value.Length - 1); + + if (_value.Length > 10) + { + NumberStyles _styles = NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent | NumberStyles.AllowCurrencySymbol; + double _d = double.Parse(_value.Replace('.', ','), _styles); + + if (_value.StartsWith('-')) + { + //TODO? BigInt? + if (_d <= -9007199254740991) + { + Log.WarningLine($"Number: {_d} is smaller then Number.MIN_SAFE_INTEGER(-9007199254740991) clamping!"); + _value = "Number.MIN_SAFE_INTEGER"; + } + } + else + { + if (_d >= 9007199254740991) + { + Log.WarningLine($"Number: {_d} is larger then Number.MAX_SAFE_INTEGER(9007199254740991) clamping!"); + _value = "Number.MAX_SAFE_INTEGER"; + } + } + } + + _value = _value.Replace(',', '.'); + + if (node.Token.Text != _value) + { + //see source code for literal + //return Literal(SymbolDisplay.FormatLiteral(value, quote: true), value); + node = node.ReplaceToken(node.Token, SyntaxFactory.Literal(SymbolDisplay.FormatLiteral(_value, quote: false), _value).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia())); + } + } + return node; + } + public override SyntaxNode? VisitGenericName(GenericNameSyntax node) + { + return SyntaxFactory.IdentifierName(node.Identifier); + } + public override SyntaxNode? VisitEnumDeclaration(EnumDeclarationSyntax node) + { + node = (EnumDeclarationSyntax)base.VisitEnumDeclaration(node)!; + + List enumMembers = new(); + + for (int i = 0; i < node.Members.Count; i++) + { + enumMembers.Add(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, + SyntaxFactory.IdentifierName(node.Members[i].Identifier).WithLeadingTrivia(node.Members[i].Identifier.LeadingTrivia).WithTrailingTrivia(node.Members[i].Identifier.TrailingTrivia), + node.Members[i].EqualsValue == null ? SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression, SyntaxFactory.Literal(i)) : node.Members[i].EqualsValue.Value).NormalizeWhitespace()); + } + + GlobalStatementSyntax local = SyntaxFactory.GlobalStatement(SyntaxFactory.LocalDeclarationStatement( + SyntaxFactory.VariableDeclaration( + SyntaxFactory.IdentifierName("const").WithLeadingTrivia(node.EnumKeyword.LeadingTrivia).WithTrailingTrivia(node.EnumKeyword.TrailingTrivia), + SyntaxFactory.SingletonSeparatedList( + SyntaxFactory.VariableDeclarator(node.Identifier, + argumentList: null, + initializer: SyntaxFactory.EqualsValueClause(SyntaxFactory.Token(SyntaxKind.EqualsToken).WithLeadingTrivia(SyntaxFactory.Whitespace(" ")).WithTrailingTrivia(SyntaxFactory.Whitespace(" ")), + SyntaxFactory.InitializerExpression(SyntaxKind.ArrayInitializerExpression, SyntaxFactory.SeparatedList(enumMembers)))))))).WithTrailingTrivia(node.CloseBraceToken.TrailingTrivia); + + return local; + } + public override SyntaxNode? VisitAttributeList(AttributeListSyntax node) + { + return null; + } + public override SyntaxNode? VisitTypeParameterList(TypeParameterListSyntax node) + { + return null; + } + public override SyntaxNode? VisitUsingDirective(UsingDirectiveSyntax node) + { + return null; + } + public override SyntaxNode? VisitExternAliasDirective(ExternAliasDirectiveSyntax node) + { + return null; + } + public override SyntaxNode? VisitDelegateDeclaration(DelegateDeclarationSyntax node) + { + return null; + } + public override SyntaxNode? VisitStructDeclaration(StructDeclarationSyntax node) + { + return null; + } + public override SyntaxNode? VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) + { + return null; + } + + private static SyntaxToken? TryGetStaticModifier(SyntaxTokenList modifiers) + { + SyntaxToken? _static = null; + for (int i = 0; i < modifiers.Count; i++) + { + if (modifiers[i].Text == "static") + { + _static = SyntaxFactory.Token(SyntaxKind.StaticKeyword).WithLeadingTrivia(modifiers[0].LeadingTrivia).WithTrailingTrivia(modifiers[0].TrailingTrivia); + break; + } + } + return _static; + } + private static SyntaxToken? TryGetAsyncModifier(SyntaxTokenList modifiers) + { + SyntaxToken? async = null; + for (int i = 0; i < modifiers.Count; i++) + { + if (modifiers[i].Text == "async") + { + async = SyntaxFactory.Token(SyntaxKind.AsyncKeyword).WithLeadingTrivia(modifiers[0].LeadingTrivia).WithTrailingTrivia(modifiers[0].TrailingTrivia); + break; + } + } + return async; + } +} + +internal class KeepBraceOnTheSameLineRewriter : CSharpSyntaxRewriter +{ + private SyntaxToken? _ReplacedPreviousToken = null; + public override SyntaxToken VisitToken(SyntaxToken token) + { + if (token.IsKind(SyntaxKind.OpenBraceToken)) + { + if (_ReplacedPreviousToken != null) + { + _ReplacedPreviousToken = null; + token = token.WithLeadingTrivia(SyntaxFactory.Space); + return token; + } + } + + SyntaxToken _nextToken = token.GetNextToken(); + + if (_nextToken.IsKind(SyntaxKind.OpenBraceToken)) + { + if (token.HasTrailingTrivia) + { + SyntaxTriviaList trivias = token.TrailingTrivia; + + for (int i = 0; i < trivias.Count; i++) + { + if (trivias[i].IsKind(SyntaxKind.EndOfLineTrivia)) + { + token = token.WithoutTrivia().WithLeadingTrivia(token.LeadingTrivia); + _ReplacedPreviousToken = token; + return token; + } + } + } + } + return base.VisitToken(token); + } + +} \ No newline at end of file