コード例 #1
0
ファイル: CodeGenerator.cs プロジェクト: sw417f19/CBlunt
        public override int VisitParameter([NotNull] CBluntParser.ParameterContext context)
        {
#if DEBUG
            Console.WriteLine("VisitParameter");
#endif
            if (context.children.Count() > 1)
            {
                Visit(context.functioncall());
            }
            else
            {
                this.AddText(context.GetChild(0).GetText());
            }
            return(0);
        }
コード例 #2
0
        string GetParameterType(object context, CBluntParser.ParameterContext parameter)
        {
            var assignmentType = "";

            if (parameter.STRING() != null)
            {
                assignmentType = "text";
            }

            if (parameter.NUMBER() != null)
            {
                assignmentType = "number";
            }

            if (parameter.truth() != null)
            {
                assignmentType = "bool";
            }

            if (parameter.ID() != null)
            {
                var variableName = parameter.ID().GetText();

                var assignmentVariableProperties = GetDeclaredVariable(parameter.ID().GetText());

                if (assignmentVariableProperties == null)
                {
                    SyntaxError(context, "Variable " + variableName + " does not exist");
                    return("");
                }

                // Determine whether the variable we are trying to assign has been initialized
                // We can assign an initialized variable to an uninitialized, but not an uninitialized variable to an initialized variable
                if (!assignmentVariableProperties.Initialized)
                {
                    SyntaxError(context, "Variable " + variableName + " has not been initialized yet");
                    return("");
                }

                // If all checks passes, grab the assignment type
                assignmentType = assignmentVariableProperties.Type;
            }

            if (parameter.functioncall() != null)
            {
                // Visit the functioncall for potential recursive handling. If it returns 1 it means that an error has occured and
                // checking should stop
                if (Visit(parameter.functioncall()) == 1)
                {
                    return("");
                }

                /// TODO: Maybe move the part below this up above the Visit
                var methodProperties = GetMethodProperties(parameter.functioncall().ID().GetText());

                if (methodProperties == null)
                {
                    SyntaxError(context, "Method with name " + parameter.functioncall().ID().GetText() + " does not exist");
                    return("");
                }

                assignmentType = methodProperties.Type;
            }

            return(assignmentType);
        }