Пример #1
0
        public override Reference VisitRefPort([NotNull] LogicScriptParser.RefPortContext context)
        {
            var      identName = context.IDENT().GetText();
            PortInfo port;

            MachinePorts?target =
                Context.Outer.Script.Inputs.TryGetValue(identName, out port) ? MachinePorts.Input
                        : Context.Outer.Script.Outputs.TryGetValue(identName, out port) ? MachinePorts.Output
                        : Context.Outer.Script.Registers.TryGetValue(identName, out port) ? MachinePorts.Register
                        : null;

            if (target == null)
            {
                Context.Errors.AddError($"Unknown identifier '{identName}'", new SourceSpan(context.IDENT().Symbol), isFatal: true);
            }

            return(new PortReference(context.Span(), port));
        }
Пример #2
0
        public override Expression VisitRefPort([NotNull] LogicScriptParser.RefPortContext context)
        {
            if (Context.Outer.Constants.TryGetValue(context.GetText(), out var val))
            {
                return(val);
            }

            if (Context.IsInConstant)
            {
                Context.Errors.AddError("You can only reference constants from other constants", context.Span(), true);
            }

            var @ref = new ReferenceVisitor(Context).Visit(context);

            if ([email protected])
            {
                Context.Errors.AddError("An identifier in an expression must be readable", context.Span());
            }

            return(new ReferenceExpression(context.Span(), @ref));
        }