Beispiel #1
0
        public bool Build()
        {
            State = CompilationState.Parsing;

            NvFile file = OpenNvFile(InputFilePath);

            if (file == null)
            {
                return(false);
            }

            if (!CreateContainer(file))
            {
                return(false);
            }

            State = CompilationState.TypeLink;

            List <SemanticalError> errors = new List <SemanticalError>();

            foreach (var @class in Container.GetClasses())
            {
                Container.TypeManager.Register(@class, false);
            }

            foreach (var @class in Container.GetClasses())
            {
                errors.AddRange(@class.ValidateTypes(Container));
            }

            foreach (var @class in Container.GetClasses())
            {
                errors.AddRange(@class.ValidateSemantics(Container));
            }

            State = CompilationState.SemanticalValidation;

            if (errors.Count > 0)
            {
                foreach (var error in errors)
                {
                    Logger.Write(error.ToString(), LogType.SemanticError);
                }
                return(false);
            }


            State = CompilationState.BytecodeGeneration;

            BuildNovFile();

            State = CompilationState.End;

            if (Result == null)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private static NvFile OpenNvFile(string path)
        {
            NvFile result = new NvFile(path);

            if (!result.Read())
            {
                return(null);
            }

            return(result);
        }
Beispiel #3
0
        private bool CreateContainerRecursively(NvFile file, List <string> usings)
        {
            foreach (var @class in file.Classes)
            {
                if (Container.ContainsClass(@class.ClassName))
                {
                    Logger.Write("Redefinition of class: \"" + @class.ClassName + "\"", LogType.Error);
                    return(false);
                }
                this.Container.Add(@class);
            }

            foreach (var @using in file.Usings)
            {
                if (!usings.Contains(@using.Value))
                {
                    string path = string.Empty;

                    if (@using.Type == UsingType.Ref)
                    {
                        path = Path.Combine(Path.GetDirectoryName(InputFilePath), @using.Value);
                    }
                    else
                    {
                        throw new Exception();
                    }

                    NvFile nvFile = OpenNvFile(path);

                    if (nvFile == null)
                    {
                        return(false);
                    }

                    usings.Add(@using.Value);

                    return(CreateContainerRecursively(nvFile, usings));
                }
            }
            return(true);
        }
Beispiel #4
0
 private bool CreateContainer(NvFile mainFile)
 {
     this.Container = new ClassesContainer();
     return(CreateContainerRecursively(mainFile, new List <string>()));
 }