Skip to content

Commit 40aa8e0

Browse files
Recompile into instructions 140 and 141;
Add metadata for method invocations and argument type 25;
1 parent 906e544 commit 40aa8e0

File tree

9 files changed

+189
-33
lines changed

9 files changed

+189
-33
lines changed

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/Level5CodeUnitConverter.cs

+37-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,33 @@ private void AddExpression(ScriptFile result, ExpressionSyntax expression, out i
471471
throw CreateException($"Invalid binary expression operation {(SyntaxTokenKind)binaryExpression.Operation.RawKind}.", expression.Location);
472472
}
473473

474+
if (binaryExpression is
475+
{
476+
Left: ValueExpressionSyntax { Value: VariableExpressionSyntax },
477+
Right: ValueExpressionSyntax
478+
{
479+
Value: LiteralExpressionSyntax
480+
{
481+
Literal: { RawKind: (int)SyntaxTokenKind.NumericLiteral, Text: "1" }
482+
}
483+
}
484+
})
485+
{
486+
switch (binaryExpression.Operation.RawKind)
487+
{
488+
case (int)SyntaxTokenKind.Plus:
489+
instructionType = 140;
490+
break;
491+
492+
case (int)SyntaxTokenKind.Minus:
493+
instructionType = 141;
494+
break;
495+
}
496+
}
497+
474498
AddExpression(result, binaryExpression.Left, out _);
475-
AddExpression(result, binaryExpression.Right, out _);
499+
if (instructionType is not 140 and not 141)
500+
AddExpression(result, binaryExpression.Right, out _);
476501
break;
477502

478503
case SwitchExpressionSyntax switchExpression:
@@ -513,7 +538,17 @@ private void AddExpression(ScriptFile result, ExpressionSyntax expression, out i
513538
instructionType = GetInstructionType(methodInvocation.Identifier, out bool isMethodTransfer);
514539

515540
if (isMethodTransfer)
516-
AddArgument(result, ScriptArgumentType.StringHash, methodInvocation.Identifier.Text);
541+
{
542+
int rawArgumentType = -1;
543+
var argumentType = ScriptArgumentType.StringHash;
544+
if (methodInvocation.Metadata != null)
545+
{
546+
rawArgumentType = GetNumericLiteral(methodInvocation.Metadata.Parameter);
547+
argumentType = ScriptArgumentType.String;
548+
}
549+
550+
AddArgument(result, argumentType, methodInvocation.Identifier.Text, rawArgumentType);
551+
}
517552

518553
if (methodInvocation.Parameters.ParameterList != null)
519554
foreach (var parameter in methodInvocation.Parameters.ParameterList.Elements)

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/Level5ScriptFileConverter.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,10 @@ private ArrayIndexerExpressionSyntax CreateArrayIndexerExpression(ScriptArgument
692692
private MethodInvocationExpressionSyntax CreateMethodInvocationExpression(ScriptInstruction instruction, ScriptFile script)
693693
{
694694
SyntaxToken identifier = CreateMethodNameIdentifier(instruction, script);
695+
var metadata = CreateMethodInvocationMetadata(instruction, script);
695696
var parameters = CreateMethodInvocationExpressionParameters(instruction, script);
696697

697-
return new MethodInvocationExpressionSyntax(identifier, parameters);
698+
return new MethodInvocationExpressionSyntax(identifier, metadata, parameters);
698699
}
699700

700701
private SyntaxToken CreateMethodNameIdentifier(ScriptInstruction instruction, ScriptFile script)
@@ -711,6 +712,21 @@ private SyntaxToken CreateMethodNameIdentifier(ScriptInstruction instruction, Sc
711712
return _syntaxFactory.Identifier($"sub{instruction.Type}");
712713
}
713714

715+
private MethodInvocationMetadataSyntax? CreateMethodInvocationMetadata(ScriptInstruction instruction, ScriptFile script)
716+
{
717+
if (!IsMethodNameTransfer(instruction, script))
718+
return null;
719+
720+
if (script.Arguments[instruction.ArgumentIndex].RawArgumentType < 0)
721+
return null;
722+
723+
SyntaxToken relSmaller = _syntaxFactory.Token(SyntaxTokenKind.Smaller);
724+
var value = CreateLiteralExpression(script.Arguments[instruction.ArgumentIndex].RawArgumentType, ScriptArgumentType.Int);
725+
SyntaxToken relBigger = _syntaxFactory.Token(SyntaxTokenKind.Greater);
726+
727+
return new MethodInvocationMetadataSyntax(relSmaller, value, relBigger);
728+
}
729+
714730
private MethodInvocationExpressionParametersSyntax CreateMethodInvocationExpressionParameters(ScriptInstruction instruction, ScriptFile script)
715731
{
716732
SyntaxToken parenOpen = _syntaxFactory.Token(SyntaxTokenKind.ParenOpen);
@@ -759,7 +775,7 @@ private ValueExpressionSyntax CreateValueExpression(object value, ScriptArgument
759775
ExpressionSyntax parameter = CreateArgumentExpression(value, argumentType);
760776

761777
ValueMetadataParametersSyntax? parameters = null;
762-
if (rawArgumentType > 0)
778+
if (rawArgumentType >= 0)
763779
parameters = CreateValueMetadataParameters(rawArgumentType);
764780

765781
return new ValueExpressionSyntax(parameter, parameters);

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/Level5ScriptManagementWorkflow.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ private void PrintHelp()
282282
Console.WriteLine(" Valid operations are: e for extraction, c for creation, d for decompression");
283283
Console.WriteLine(" -t, --type\t\tThe type of file given");
284284
Console.WriteLine(" Valid types are: xq32, xseq");
285-
Console.WriteLine(" The type is automatically detected when extracting; This argument will not have any effect on operation 'e'");
285+
Console.WriteLine(" The type is automatically detected when extracting; This argument will not have any effect on operation 'e' and 'd'");
286286
Console.WriteLine(" -f, --file\t\tThe file to process");
287-
Console.WriteLine(" -n, --no-compression\t[Optional] If the file uses a compression layer");
288-
Console.WriteLine(" This option is automatically detected when extracting; This argument will not have any effect on operation 'e'");
287+
Console.WriteLine(" -nc, --no-compression\t[Optional] If the file should use a compression layer");
288+
Console.WriteLine(" This option is automatically detected when extracting; This argument will not have any effect on operation 'e' and 'd'");
289289
Console.WriteLine(" -l, --length\t\t[Optional]The pointer length given");
290290
Console.WriteLine(" Valid lengths are: int, long");
291291
Console.WriteLine(" Default value is 'int'");

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/_Configuration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class Level5ScriptManagementConfiguration
1616
[ConfigMap("CommandLine", new[] { "l", "length" })]
1717
public virtual string Length { get; set; } = "int";
1818

19-
[ConfigMap("CommandLine", new[] { "n", "no-compression" })]
19+
[ConfigMap("CommandLine", new[] { "nc", "no-compression" })]
2020
public virtual bool WithoutCompression { get; set; } = false;
2121

2222
[ConfigMap("CommandLine", new[] { "f", "file" })]

XtractQuery/Logic.Domain.CodeAnalysis/Logic.Domain.CodeAnalysis.Contract/Level5/DataClasses/MethodInvocationExpressionSyntax.cs

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Data.Common;
4-
using System.Linq;
5-
using System.Reflection.Metadata;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
using Logic.Domain.CodeAnalysis.Contract.DataClasses;
1+
using Logic.Domain.CodeAnalysis.Contract.DataClasses;
92

103
namespace Logic.Domain.CodeAnalysis.Contract.Level5.DataClasses
114
{
125
public class MethodInvocationExpressionSyntax : ExpressionSyntax
136
{
147
public SyntaxToken Identifier { get; private set; }
8+
public MethodInvocationMetadataSyntax? Metadata { get; private set; }
159
public MethodInvocationExpressionParametersSyntax Parameters { get; private set; }
1610

1711
public override SyntaxLocation Location => Identifier.FullLocation;
1812
public override SyntaxSpan Span => new(Identifier.FullSpan.Position, Parameters.Span.EndPosition);
1913

20-
public MethodInvocationExpressionSyntax(SyntaxToken identifier, MethodInvocationExpressionParametersSyntax parameters)
14+
public MethodInvocationExpressionSyntax(SyntaxToken identifier, MethodInvocationMetadataSyntax? metadata, MethodInvocationExpressionParametersSyntax parameters)
2115
{
2216
identifier.Parent = this;
17+
if (metadata != null)
18+
metadata.Parent = this;
2319
parameters.Parent = this;
2420

2521
Identifier = identifier;
22+
Metadata = metadata;
2623
Parameters = parameters;
2724

2825
Root.Update();
@@ -37,6 +34,16 @@ public void SetIdentifier(SyntaxToken identifier, bool updatePosition = true)
3734
Root.Update();
3835
}
3936

37+
public void SetMetadata(MethodInvocationMetadataSyntax? metadata, bool updatePosition = true)
38+
{
39+
if (metadata != null)
40+
metadata.Parent = this;
41+
Metadata = metadata;
42+
43+
if (updatePosition)
44+
Root.Update();
45+
}
46+
4047
public void SetParameters(MethodInvocationExpressionParametersSyntax parameters, bool updatePosition = true)
4148
{
4249
parameters.Parent = this;
@@ -46,12 +53,13 @@ public void SetParameters(MethodInvocationExpressionParametersSyntax parameters,
4653
Root.Update();
4754
}
4855

49-
5056
internal override int UpdatePosition(int position, ref int line, ref int column)
5157
{
5258
SyntaxToken identifier = Identifier;
5359

5460
position = identifier.UpdatePosition(position, ref line, ref column);
61+
if (Metadata != null)
62+
position = Metadata.UpdatePosition(position, ref line, ref column);
5563
position = Parameters.UpdatePosition(position, ref line, ref column);
5664

5765
Identifier = identifier;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Logic.Domain.CodeAnalysis.Contract.DataClasses;
2+
3+
namespace Logic.Domain.CodeAnalysis.Contract.Level5.DataClasses
4+
{
5+
public class MethodInvocationMetadataSyntax : SyntaxNode
6+
{
7+
public SyntaxToken RelSmaller { get; private set; }
8+
public LiteralExpressionSyntax Parameter { get; private set; }
9+
public SyntaxToken RelBigger { get; private set; }
10+
11+
public override SyntaxLocation Location => RelSmaller.FullLocation;
12+
public override SyntaxSpan Span => new(RelSmaller.FullSpan.Position, RelBigger.FullSpan.EndPosition);
13+
14+
public MethodInvocationMetadataSyntax(SyntaxToken relSmaller, LiteralExpressionSyntax parameter, SyntaxToken relBigger)
15+
{
16+
relSmaller.Parent = this;
17+
parameter.Parent = this;
18+
relBigger.Parent = this;
19+
20+
RelSmaller = relSmaller;
21+
Parameter = parameter;
22+
RelBigger = relBigger;
23+
24+
Root.Update();
25+
}
26+
27+
public void SetRelSmaller(SyntaxToken relSmaller, bool updatePosition = true)
28+
{
29+
relSmaller.Parent = this;
30+
RelSmaller = relSmaller;
31+
32+
if (updatePosition)
33+
Root.Update();
34+
}
35+
36+
public void SetParameter(LiteralExpressionSyntax parameterSyntax, bool updatePosition = true)
37+
{
38+
parameterSyntax.Parent = this;
39+
Parameter = parameterSyntax;
40+
41+
if (updatePosition)
42+
Root.Update();
43+
}
44+
45+
public void SetRelBigger(SyntaxToken relBigger, bool updatePosition = true)
46+
{
47+
relBigger.Parent = this;
48+
RelBigger = relBigger;
49+
50+
if (updatePosition)
51+
Root.Update();
52+
}
53+
54+
internal override int UpdatePosition(int position, ref int line, ref int column)
55+
{
56+
SyntaxToken relSmaller = RelSmaller;
57+
SyntaxToken relBigger = RelBigger;
58+
59+
position = relSmaller.UpdatePosition(position, ref line, ref column);
60+
position = Parameter.UpdatePosition(position, ref line, ref column);
61+
position = relBigger.UpdatePosition(position, ref line, ref column);
62+
63+
RelSmaller = relSmaller;
64+
RelBigger = relBigger;
65+
66+
return position;
67+
}
68+
}
69+
}

XtractQuery/Logic.Domain.CodeAnalysis/Logic.Domain.CodeAnalysis/Level5/Level5ScriptComposer.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
using Logic.Domain.CodeAnalysis.Contract.DataClasses;
22
using Logic.Domain.CodeAnalysis.Contract.Level5;
33
using Logic.Domain.CodeAnalysis.Contract.Level5.DataClasses;
4-
using System;
5-
using System.Buffers;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Linq.Expressions;
94
using System.Text;
10-
using System.Threading.Tasks;
115

126
namespace Logic.Domain.CodeAnalysis.Level5
137
{
@@ -477,9 +471,20 @@ private void ComposeArrayIndexerExpression(ArrayIndexerExpressionSyntax indexer,
477471
private void ComposeMethodInvocationExpression(MethodInvocationExpressionSyntax invocation, StringBuilder sb)
478472
{
479473
ComposeSyntaxToken(invocation.Identifier, sb);
474+
ComposeMethodInvocationMetadata(invocation.Metadata, sb);
480475
ComposeMethodInvocationExpressionParameters(invocation.Parameters, sb);
481476
}
482477

478+
private void ComposeMethodInvocationMetadata(MethodInvocationMetadataSyntax? metadata, StringBuilder sb)
479+
{
480+
if (metadata == null)
481+
return;
482+
483+
ComposeSyntaxToken(metadata.RelSmaller, sb);
484+
ComposeLiteralExpression(metadata.Parameter, sb);
485+
ComposeSyntaxToken(metadata.RelBigger, sb);
486+
}
487+
483488
private void ComposeMethodInvocationExpressionParameters(MethodInvocationExpressionParametersSyntax invocationParameters, StringBuilder sb)
484489
{
485490
ComposeSyntaxToken(invocationParameters.ParenOpen, sb);

XtractQuery/Logic.Domain.CodeAnalysis/Logic.Domain.CodeAnalysis/Level5/Level5ScriptParser.cs

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Logic.Domain.CodeAnalysis.Contract;
1+
using Logic.Domain.CodeAnalysis.Contract;
72
using Logic.Domain.CodeAnalysis.Contract.DataClasses;
83
using Logic.Domain.CodeAnalysis.Contract.Level5;
94
using Logic.Domain.CodeAnalysis.Contract.Level5.DataClasses;
@@ -421,7 +416,8 @@ private ExpressionSyntax ParseExpression(IBuffer<Level5SyntaxToken> buffer)
421416
if (IsUnaryExpression(buffer))
422417
return ParseUnaryExpression(buffer);
423418

424-
if (HasTokenKind(buffer, SyntaxTokenKind.Identifier) && HasTokenKind(buffer, 1, SyntaxTokenKind.ParenOpen))
419+
if (HasTokenKind(buffer, SyntaxTokenKind.Identifier)
420+
&& (HasTokenKind(buffer, 1, SyntaxTokenKind.ParenOpen) || HasTokenKind(buffer, 1, SyntaxTokenKind.Smaller)))
425421
return ParseMethodInvocationExpression(buffer);
426422

427423
ExpressionSyntax left;
@@ -696,9 +692,22 @@ private ArrayIndexerExpressionSyntax ParseArrayIndexerExpression(IBuffer<Level5S
696692
private MethodInvocationExpressionSyntax ParseMethodInvocationExpression(IBuffer<Level5SyntaxToken> buffer)
697693
{
698694
SyntaxToken identifier = ParseIdentifierToken(buffer);
695+
var metadata = ParseMethodInvocationMetadata(buffer);
699696
var methodInvocationParameters = ParseMethodInvocationExpressionParameters(buffer);
700697

701-
return new MethodInvocationExpressionSyntax(identifier, methodInvocationParameters);
698+
return new MethodInvocationExpressionSyntax(identifier, metadata, methodInvocationParameters);
699+
}
700+
701+
private MethodInvocationMetadataSyntax? ParseMethodInvocationMetadata(IBuffer<Level5SyntaxToken> buffer)
702+
{
703+
if (!HasTokenKind(buffer, SyntaxTokenKind.Smaller))
704+
return null;
705+
706+
SyntaxToken relSmallerToken = ParseSmallerToken(buffer);
707+
var parameter = ParseNumericLiteralExpression(buffer);
708+
SyntaxToken relBiggerToken = ParseGreaterToken(buffer);
709+
710+
return new MethodInvocationMetadataSyntax(relSmallerToken, parameter, relBiggerToken);
702711
}
703712

704713
private MethodInvocationExpressionParametersSyntax ParseMethodInvocationExpressionParameters(IBuffer<Level5SyntaxToken> buffer)

XtractQuery/Logic.Domain.CodeAnalysis/Logic.Domain.CodeAnalysis/Level5/Level5ScriptWhitespaceNormalizer.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ private void NormalizeReturnStatement(ReturnStatementSyntax returnStatement, Whi
389389
returnStatement.SetReturn(newReturnKeyword, false);
390390
returnStatement.SetSemicolon(newSemicolon, false);
391391

392-
if (returnStatement.ValueExpression == null)
392+
if (returnStatement.ValueExpression == null)
393393
return;
394394

395395
ctx.IsFirstElement = true;
@@ -690,9 +690,23 @@ private void NormalizeMethodInvocationExpression(MethodInvocationExpressionSynta
690690

691691
invocation.SetIdentifier(newIdentifier, false);
692692

693+
NormalizeMethodInvocationMetadata(invocation.Metadata, ctx);
693694
NormalizeMethodInvocationExpressionParameters(invocation.Parameters, ctx);
694695
}
695696

697+
private void NormalizeMethodInvocationMetadata(MethodInvocationMetadataSyntax? metadata, WhitespaceNormalizeContext ctx)
698+
{
699+
if (metadata == null)
700+
return;
701+
702+
SyntaxToken newRelSmaller = metadata.RelSmaller.WithNoTrivia();
703+
SyntaxToken newRelBigger = metadata.RelBigger.WithNoTrivia();
704+
705+
metadata.SetRelSmaller(newRelSmaller, false);
706+
NormalizeLiteralExpression(metadata.Parameter, ctx);
707+
metadata.SetRelBigger(newRelBigger, false);
708+
}
709+
696710
private void NormalizeMethodInvocationExpressionParameters(MethodInvocationExpressionParametersSyntax invocationParameters, WhitespaceNormalizeContext ctx)
697711
{
698712
SyntaxToken parenOpen = invocationParameters.ParenOpen.WithNoTrivia();

0 commit comments

Comments
 (0)