public FieldGetContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node, MemberNameRepository nameRepo) : base(node) { this.OwnDataType = node.DataType; if (node.NodeString == 0) { accessor = SyntaxFactory.DefaultExpression(SyntaxUtil.ScriptTypeSyntax(node.DataType)); } else { var stringVal = SyntaxUtil.GetScriptString(scenario, node); if (stringVal == "none") { accessor = SyntaxFactory.DefaultExpression(SyntaxUtil.ScriptTypeSyntax(node.DataType)); } else { if (nameRepo.TryGetName(stringVal, node.DataType.ToString(), node.NodeData_H16, out var finalName)) { accessor = SyntaxFactory.IdentifierName(finalName); } else { accessor = SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(stringVal)); } } } accessor = accessor.WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(node.DataType)); }
private void PushNext(ScenarioTag.ScriptSyntaxNode node) { if (node.NextIndex != ushort.MaxValue) { Debug.Assert(scenario.ScriptSyntaxNodes[node.NextIndex].Checkval == node.NextCheckval, "Node's next checkval didn't match"); childIndices.PushFull(node.NextIndex); } }
private IGenerationContext HandleNodeStart(ScenarioTag.ScriptSyntaxNode node) { return(node.NodeType switch { NodeType.BuiltinInvocation => HandleScopeStart(node), NodeType.Expression => HandleExpression(node), NodeType.ScriptInvocation => HandleScriptInvocation(node), NodeType.VariableAccess => HandleVariableAccess(node), _ => throw new NotSupportedException($"Node type {node.NodeType} is not yet supported") });
public IfStatementContext(ScenarioTag.ScriptSyntaxNode node, Scope containingScope) : base(node) { var resultVarName = "ifResult_" + this.GetHashCode(); resultVariable = IdentifierName(resultVarName) .WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(containingScope.Type)); this.containingScope = containingScope; this.producesValue = containingScope.Type != ScriptDataType.Void; this.shouldHoist = containingScope.IsInStatementContext == false && containingScope.SuppressHoisting == false; }
public Result Interpret(ScenarioTag.ScriptSyntaxNode node, out ushort next) { next = ushort.MaxValue; return(node.NodeType switch { NodeType.BuiltinInvocation => InterpretScope(node, out next), NodeType.Expression => InterpretExpression(node, out next), NodeType.ScriptInvocation => InterpretScriptInvocation(node, out next), NodeType.VariableAccess => this.variables[node.NodeData_H16], _ => default,
public VariableAccessContext(ScenarioTag tag, ScenarioTag.ScriptSyntaxNode node) : base(node) { this.OwnDataType = node.DataType; access = SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName( SyntaxUtil.SanitizeIdentifier( SyntaxUtil.GetScriptString(tag, node)))) .WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(node.DataType)); }
public ScriptInvocationContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node) : base(node) { var method = scenario.ScriptMethods[node.OperationId]; invocation = SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName( SyntaxUtil.SanitizeIdentifier(method.Description)))) .WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(method.ReturnType)); }
public TagGetContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node) : base(node) { this.OwnDataType = node.DataType; invocation = InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("Engine"), GenericName(Identifier(nameof(IScriptEngine.GetTag))) .WithTypeArgumentList(TypeArgumentList(SingletonSeparatedList( SyntaxUtil.ScriptTypeSyntax(this.OwnDataType.Value)))))) .AddArgumentListArguments( Argument(SyntaxUtil.LiteralExpression(SyntaxUtil.GetScriptString(scenario, node))), Argument(SyntaxUtil.LiteralExpression(node.NodeData_32))) .WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(node.DataType)); }
public LiteralContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node, Scope containing) : base(node) { this.OwnDataType = node.DataType; var dest = node.DataType; if (SyntaxUtil.NumericLiteralTypes.Contains(node.DataType) && containing.Context is BinaryOperatorContext bin && SyntaxUtil.NumericLiteralTypes.Contains(bin.OwnDataType.Value)) { dest = bin.OwnDataType.Value; } this.literal = SyntaxUtil.LiteralExpression(scenario, node, dest); }
public GameDifficultyContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node, Scope containing) : base(node) { this.OwnDataType = node.DataType; var difficulty = node.NodeData_H16 switch { 0 => nameof(GameDifficulty.Easy), 1 => nameof(GameDifficulty.Normal), 2 => nameof(GameDifficulty.Heroic), 3 => nameof(GameDifficulty.Legendary), _ => throw new NotSupportedException() }; this.literal = InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(nameof(GameDifficulty)), IdentifierName(difficulty))); }
public UnknownContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node) : base(node) { this.OwnDataType = node.DataType; string unknownDescription = ""; if (node.NodeString > 0 && node.NodeString < scenario.ScriptStrings.Length && scenario.ScriptStrings[node.NodeString - 1] == 0) { unknownDescription = SyntaxUtil.GetScriptString(scenario, node); } unknownDescription += $" -{node.NodeType}<{node.DataType}>"; invocation = SyntaxFactory.InvocationExpression( SyntaxFactory.IdentifierName("UNKNOWN"), SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument(SyntaxUtil.LiteralExpression(unknownDescription))))); }
public EntityGetContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node, MemberNameRepository nameRepo) : base(node) { this.OwnDataType = node.DataType; if (node.NodeString == 0) { accessor = SyntaxFactory.DefaultExpression(SyntaxUtil.ScriptTypeSyntax(node.DataType)); } else { var stringVal = SyntaxUtil.GetScriptString(scenario, node); if (stringVal == "none") { accessor = SyntaxFactory.DefaultExpression(SyntaxUtil.ScriptTypeSyntax(node.DataType)); } else { if (nameRepo.TryGetName(stringVal, nameof(ScenarioTag.EntityReference), node.NodeData_H16, out var finalName)) { accessor = SyntaxFactory.IdentifierName(finalName); } else { accessor = SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(stringVal)); } if (node.DataType != ScriptDataType.EntityIdentifier) { accessor = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, accessor, SyntaxFactory.IdentifierName(nameof(ScenarioEntity <object> .Entity))); } } } accessor = accessor.WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(node.DataType)); }
public SleepUntilContext(ScenarioTag.ScriptSyntaxNode node, ScriptDataType returnType) : base(node) { this.ReturnType = returnType; }
public UnaryOperatorContext(ScenarioTag.ScriptSyntaxNode node, SyntaxKind operatorSyntaxKind) : base(node) { this.operatorSyntaxKind = operatorSyntaxKind; this.OwnDataType = node.DataType; }
public BaseGenerationContext(ScenarioTag.ScriptSyntaxNode node) { this.OriginalNode = node; }
public ScopeGenerationContext(ScenarioTag.ScriptSyntaxNode node, Scope containingScope) : base(node) { this.OwnDataType = node.DataType; this.containingScope = containingScope; }
public StatementContext(ScenarioTag.ScriptSyntaxNode node, Scope containingScope) : base(node, containingScope) { }
public BeginRandomContext(ScenarioTag.ScriptSyntaxNode node, ScriptDataType type) : base(node) { this.OwnDataType = type; }
public MethodCallContext(ScenarioTag.ScriptSyntaxNode node, string methodName, ScriptDataType returnType) : base(node) { this.MethodName = methodName; this.ReturnType = returnType; }
public FieldSetContext(ScenarioTag.ScriptSyntaxNode node) : base(node) { }
public BeginCallContext(ScenarioTag.ScriptSyntaxNode node, Scope context, ScriptDataType returnType) : base(node) { this.returnType = returnType; }
public SingleExpressionStatementContext(ScenarioTag.ScriptSyntaxNode node, ScriptDataType scopeType) : base(node) { this.OwnDataType = scopeType; }
public BinaryOperatorContext(ScenarioTag.ScriptSyntaxNode node, SyntaxKind operatorSyntaxKind, ScriptDataType returnType) : base(node) { this.operatorSyntaxKind = operatorSyntaxKind; this.OwnDataType = returnType; }
public AiGetContext(ScenarioTag scenario, ScenarioTag.ScriptSyntaxNode node, MemberNameRepository nameRepo) : base(node) { this.OwnDataType = node.DataType; if (node.NodeString == 0) { accessor = SyntaxFactory.DefaultExpression(SyntaxUtil.ScriptTypeSyntax(node.DataType)); } else { var stringVal = SyntaxUtil.GetScriptString(scenario, node); var slashIndex = stringVal.IndexOf('/'); if (slashIndex > 0) { Debug.Assert(node.NodeData_B0 == 192); // It's a squad member accessor var squadName = stringVal.Substring(0, slashIndex); var memberName = stringVal.Substring(slashIndex + 1); if (nameRepo.TryGetName(squadName, node.DataType.ToString(), node.NodeData_B1, out var finalSquad) && nameRepo.NestedRepos.TryGetValue(finalSquad, out var nestedRepo) && nestedRepo.TryGetName(memberName, node.DataType.ToString(), node.NodeData_H16, out var finalProp)) { accessor = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(finalSquad)), SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(finalProp))); } else { accessor = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(squadName)), SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(memberName))); } } else { // Ambiguous reference to either a squad or squad group...? if (nameRepo.TryGetName(stringVal, node.DataType.ToString(), node.NodeData_H16, out var finalSquad)) { if (nameRepo.NestedRepos.TryGetValue(finalSquad, out var nestedRepo)) { accessor = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(finalSquad)), SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier("Squad"))); } else { accessor = SyntaxFactory.IdentifierName(finalSquad); } } else { accessor = SyntaxFactory.IdentifierName(SyntaxUtil.SanitizeIdentifier(stringVal)); } } } accessor = accessor.WithAdditionalAnnotations(ScriptGenAnnotations.TypeAnnotation(node.DataType)); }