Exemplo n.º 1
0
        /// <summary>
        /// Checks if the operand is used as a macro parameter node
        /// </summary>
        /// <param name="context"></param>
        private void CheckForMacroParamNode(Z80AsmParser.BuiltinFunctionInvocationContext context)
        {
            if (context.operand() == null)
            {
                return;
            }

            var op = (Operand)VisitOperand(context.operand());

            if (!MacroParsingPhase && (op.Type != OperandType.Expr || !(op.Expression is MacroParamNode)))
            {
                // --- Built in function can use only macro parameters during the collection phase
                IssueToEmit = Errors.Z0421;
            }
        }
Exemplo n.º 2
0
        public override object VisitBuiltinFunctionInvocation(Z80AsmParser.BuiltinFunctionInvocationContext context)
        {
            AddFunction(context);
            string token = null;

            switch (context)
            {
            case Z80AsmParser.TextOfInvokeContext ctx:
                if (ctx.macroParam() != null)
                {
                    AddFunction(context);
                    AddMacroParam(ctx.macroParam());
                    if (ctx.macroParam().IDENTIFIER() != null)
                    {
                        AddMacroParamName(ctx.macroParam().IDENTIFIER().NormalizeToken());
                    }
                }
                if (ctx.mnemonic() != null)
                {
                    AddMnemonics(ctx.mnemonic());
                    token = ctx.mnemonic().NormalizeToken();
                }
                else if (ctx.regsAndConds() != null)
                {
                    AddOperand(ctx.regsAndConds());
                    token = ctx.regsAndConds().NormalizeToken();
                }

                if (ctx.LTEXTOF() != null)
                {
                    token = token?.ToLower();
                }
                return(new LiteralNode(ctx, token));

            case Z80AsmParser.DefInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand() != null && ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg8InvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx,
                                       (ctx.operand()?.reg8() != null ||
                                        ctx.operand()?.reg8Spec() != null ||
                                        ctx.operand()?.reg8Idx() != null) &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg8StdInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.reg8() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg8StdSpecInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.reg8Spec() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg8IdxInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.reg8Idx() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg16InvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx,
                                       (ctx.operand()?.reg16() != null ||
                                        ctx.operand()?.reg16Idx() != null ||
                                        ctx.operand()?.reg16Spec() != null) &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg16StdInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.reg16() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsReg16IdxInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.reg16Idx() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsRegIndirectInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.regIndirect() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsCportInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.cPort() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsIndexedAddrInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.indexedAddr() != null &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsConditionInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx,
                                       (ctx.operand()?.condition() != null || ctx.operand().reg8()?.GetText()?.ToLower() == "c") &&
                                       ctx.operand().NONEARG() == null));

            case Z80AsmParser.IsExprInvokeContext ctx:
                CheckForMacroParamNode(ctx.operand());
                return(new LiteralNode(ctx, ctx.operand()?.expr() != null &&
                                       ctx.operand().NONEARG() == null));
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Visit a parse tree produced by <see cref="Z80AsmParser.builtinFunctionInvocation"/>.
        /// <para>
        /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
        /// on <paramref name="context"/>.
        /// </para>
        /// </summary>
        /// <param name="context">The parse tree.</param>
        /// <return>The visitor result.</return>
        public override object VisitBuiltinFunctionInvocation(Z80AsmParser.BuiltinFunctionInvocationContext context)
        {
            AddFunction(context);
            string token = null;

            if (context.TEXTOF() != null || context.LTEXTOF() != null)
            {
                if (context.macroParam() != null)
                {
                    AddFunction(context);
                    AddMacroParam(context.macroParam());
                    if (context.macroParam().IDENTIFIER() != null)
                    {
                        AddMacroParamName(context.macroParam().IDENTIFIER().NormalizeToken());
                    }
                }
                if (context.mnemonic() != null)
                {
                    AddMnemonics(context.mnemonic());
                    token = context.mnemonic().NormalizeToken();
                }
                else if (context.regsAndConds() != null)
                {
                    AddOperand(context.regsAndConds());
                    token = context.regsAndConds().NormalizeToken();
                }

                if (context.LTEXTOF() != null)
                {
                    token = token?.ToLower();
                }
                return(new LiteralNode(token));
            }

            if (context.DEF() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand() != null && context.operand().NONEARG() == null));
            }

            if (context.ISREG8() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(
                           (context.operand()?.reg8() != null ||
                            context.operand()?.reg8Spec() != null ||
                            context.operand()?.reg8Idx() != null) &&
                           context.operand().NONEARG() == null));
            }

            if (context.ISREG8STD() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.reg8() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISREG8SPEC() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.reg8Spec() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISREG8IDX() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.reg8Idx() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISREG16() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(
                           (context.operand()?.reg16() != null ||
                            context.operand()?.reg16Idx() != null ||
                            context.operand()?.reg16Spec() != null) &&
                           context.operand().NONEARG() == null));
            }

            if (context.ISREG16IDX() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.reg16Idx() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISREG16STD() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.reg16() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISREGINDIRECT() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.regIndirect() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISCPORT() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.cPort() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISINDEXEDADDR() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.indexedAddr() != null &&
                                       context.operand().NONEARG() == null));
            }

            if (context.ISCONDITION() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(
                           (context.operand()?.condition() != null || context.operand().reg8()?.GetText()?.ToLower() == "c") &&
                           context.operand().NONEARG() == null));
            }

            if (context.ISEXPR() != null)
            {
                CheckForMacroParamNode(context);
                return(new LiteralNode(context.operand()?.expr() != null &&
                                       context.operand().NONEARG() == null));
            }

            return(null);
        }