Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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")
     });
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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,
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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)));
        }
Exemplo n.º 11
0
        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)))));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
 public SleepUntilContext(ScenarioTag.ScriptSyntaxNode node, ScriptDataType returnType) : base(node)
 {
     this.ReturnType = returnType;
 }
Exemplo n.º 14
0
 public UnaryOperatorContext(ScenarioTag.ScriptSyntaxNode node, SyntaxKind operatorSyntaxKind) : base(node)
 {
     this.operatorSyntaxKind = operatorSyntaxKind;
     this.OwnDataType        = node.DataType;
 }
Exemplo n.º 15
0
 public BaseGenerationContext(ScenarioTag.ScriptSyntaxNode node)
 {
     this.OriginalNode = node;
 }
Exemplo n.º 16
0
 public ScopeGenerationContext(ScenarioTag.ScriptSyntaxNode node, Scope containingScope) : base(node)
 {
     this.OwnDataType     = node.DataType;
     this.containingScope = containingScope;
 }
Exemplo n.º 17
0
 public StatementContext(ScenarioTag.ScriptSyntaxNode node, Scope containingScope) : base(node, containingScope)
 {
 }
Exemplo n.º 18
0
 public BeginRandomContext(ScenarioTag.ScriptSyntaxNode node, ScriptDataType type) : base(node)
 {
     this.OwnDataType = type;
 }
Exemplo n.º 19
0
 public MethodCallContext(ScenarioTag.ScriptSyntaxNode node, string methodName, ScriptDataType returnType) : base(node)
 {
     this.MethodName = methodName;
     this.ReturnType = returnType;
 }
Exemplo n.º 20
0
 public FieldSetContext(ScenarioTag.ScriptSyntaxNode node) : base(node)
 {
 }
Exemplo n.º 21
0
 public BeginCallContext(ScenarioTag.ScriptSyntaxNode node, Scope context, ScriptDataType returnType) : base(node)
 {
     this.returnType = returnType;
 }
Exemplo n.º 22
0
 public SingleExpressionStatementContext(ScenarioTag.ScriptSyntaxNode node, ScriptDataType scopeType) : base(node)
 {
     this.OwnDataType = scopeType;
 }
Exemplo n.º 23
0
 public BinaryOperatorContext(ScenarioTag.ScriptSyntaxNode node, SyntaxKind operatorSyntaxKind, ScriptDataType returnType) : base(node)
 {
     this.operatorSyntaxKind = operatorSyntaxKind;
     this.OwnDataType        = returnType;
 }
Exemplo n.º 24
0
        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));
        }