Exemple #1
0
        public override void EnterCondGroup(HS_Gen1Parser.CondGroupContext context)
        {
            if (_debug)
            {
                _logger.CondGroup(context, CompilerContextAction.Enter);
            }

            // Link to the previous expression or cond group.
            LinkDatum();

            // push the types of the group members.
            _expectedTypes.PushTypes(_condReturnType, context.expression().Count() - 1);
            _expectedTypes.PushType("boolean");

            var parentCond = context.Parent as HS_Gen1Parser.CondContext;
            var ifInfo = _opcodes.GetFunctionInfo("if")[0];
            var compilerIf = new ScriptExpression
            {
                Index = _currentIndex,
                Opcode = ifInfo.Opcode,
                ReturnType = _opcodes.GetTypeInfo(_condReturnType).Opcode,
                Type = ScriptExpressionType.Group,
                Next = DatumIndex.Null,
                StringOffset = context.GetCorrectTextPosition(_missingCarriageReturnPositions),
                Value = new LongExpressionValue(_currentIndex.Next),
                LineNumber = 0
            };

            // Keep the if call closed. We will open the initial one later on.
            AddExpressionIncrement(compilerIf);

            var compilerIfName = new ScriptExpression
            {
                Index = _currentIndex,
                Opcode = ifInfo.Opcode,
                ReturnType = _opcodes.GetTypeInfo("function_name").Opcode,
                Type = ScriptExpressionType.Expression,
                Next = DatumIndex.Null,
                StringOffset = _strings.Cache(ifInfo.Name),
                Value = new LongExpressionValue(0),
                LineNumber = GetLineNumber(context)
            };
            OpenDatumAddExpressionIncrement(compilerIfName);

            // Push the index to the condition so that we can modify it later on.
            _condIndeces.Push(_expressions.Count);
        }
Exemple #2
0
        public override void ExitCondGroup(HS_Gen1Parser.CondGroupContext context)
        {
            if (_debug)
            {
                _logger.CondGroup(context, CompilerContextAction.Exit);
            }

            // Close the final value expression.
            CloseDatum();

            int index = _condIndeces.Pop();
            var beginInfo = _opcodes.GetFunctionInfo("begin")[0];

            // Grab the index to value expression of the cond group. Modify the condition expression afterwards.
            // Next has to point to the begin call, which is added by the compiler.
            var valueExpressionDatum = _expressions[index].Next;
            _expressions[index].Next = _currentIndex;

            var compilerBeginCall = new ScriptExpression
            {
                Index = _currentIndex,
                Opcode = beginInfo.Opcode,
                ReturnType = _opcodes.GetTypeInfo(_condReturnType).Opcode,
                Type = ScriptExpressionType.Group,
                Next = DatumIndex.Null,
                StringOffset = context.GetCorrectTextPosition(_missingCarriageReturnPositions),
                Value = new LongExpressionValue(_currentIndex.Next),
                LineNumber = 0
            };
            OpenDatumAddExpressionIncrement(compilerBeginCall);

            var compilerBeginName = new ScriptExpression
            {
                Index = _currentIndex,
                Opcode = beginInfo.Opcode,
                ReturnType = _opcodes.GetTypeInfo("function_name").Opcode,
                Type = ScriptExpressionType.Expression,
                Next = valueExpressionDatum,
                StringOffset = _strings.Cache(beginInfo.Name),
                Value = new LongExpressionValue(0),
                LineNumber = 0
            };
            AddExpressionIncrement(compilerBeginName);
        }
 /// <summary>
 /// Exit a parse tree produced by <see cref="HS_Gen1Parser.condGroup"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCondGroup([NotNull] HS_Gen1Parser.CondGroupContext context)
 {
 }