public override int VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            string variableName = context.VAR_ID().GetText();
            compiler.Emit(ByteCode.PushVariable, variableName);

            return 0;
        }
Example #2
0
        public override Yarn.IType VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            // The type of the value depends on the declared type of the
            // variable

            var name = context.VAR_ID()?.GetText();

            if (name == null)
            {
                // We don't have a variable name for this Variable context.
                // The parser will have generated an error for us in an
                // earlier stage; here, we'll bail out.
                return(BuiltinTypes.Undefined);
            }

            foreach (var declaration in Declarations)
            {
                if (declaration.Name == name)
                {
                    return(declaration.Type);
                }
            }

            // We don't have a declaration for this variable. Return
            // Undefined. Hopefully, other context will allow us to infer a
            // type.
            return(BuiltinTypes.Undefined);
        }
Example #3
0
        public override int VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            string variableName = context.VAR_ID().GetText();

            this.compiler.Emit(OpCode.PushVariable, context.Start, new Operand(variableName));

            return(0);
        }
Example #4
0
        public override Yarn.IType VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            // The type of the value depends on the declared type of the
            // variable

            var name = context.VAR_ID()?.GetText();

            if (name == null)
            {
                // We don't have a variable name for this Variable context.
                // The parser will have generated an error for us in an
                // earlier stage; here, we'll bail out.
                return(BuiltinTypes.Undefined);
            }

            foreach (var declaration in Declarations)
            {
                if (declaration.Name == name)
                {
                    return(declaration.Type);
                }
            }

            // do we already have a potential warning about this?
            // no need to make more
            foreach (var hmm in deferredTypes)
            {
                if (hmm.Name == name)
                {
                    return(BuiltinTypes.Undefined);
                }
            }

            // creating a new diagnostic for us having an undefined variable
            // this won't get added into the existing diags though because its possible a later pass will clear it up
            // so we save this as a potential diagnostic for the compiler itself to resolve
            var diagnostic = new Diagnostic(sourceFileName, context, string.Format(CantDetermineVariableTypeError, name));

            deferredTypes.Add(DeferredTypeDiagnostic.CreateDeferredTypeDiagnostic(name, diagnostic));

            // We don't have a declaration for this variable. Return
            // Undefined. Hopefully, other context will allow us to infer a
            // type.
            return(BuiltinTypes.Undefined);
        }
Example #5
0
        public override Yarn.Type VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            // The type of the value depends on the declared type of the
            // variable

            var name = context.VAR_ID().GetText();

            foreach (var declaration in Declarations)
            {
                if (declaration.Name == name)
                {
                    return(declaration.ReturnType);
                }
            }

            // We don't have a declaration for this variable. Return
            // Undefined. Hopefully, other context will allow us to infer a
            // type.
            return(Yarn.Type.Undefined);
        }