示例#1
0
        public PsiVisitor(CompilationUnit cu, CompilerDTO dto)
        {
            DTO = dto;
            CurrentCompilationUnit = cu;

            InitHelpers();
        }
        public PsiSemanticAnaliserVisitor(CompilationUnit cu, CompilerDTO dto)
            : base(cu, dto)
        {
            CurrentCompilationUnit = cu;
            DTO = dto;

            InitHelpers();
        }
        //  обновить информацию о компиляторе
        public int InsertOrUpdateCompiler(String SessionKey, CompilerDTO Compiler)
        {
            CheckSession(SessionKey);
            bool isNewRecord = (Compiler.Id < 0);

            using (var db = new DataBase())
            {
                if ((Compiler.CompilerType == "native" || Compiler.CompilerType == "javavm" ||
                     Compiler.CompilerType == "dotnet" || Compiler.CompilerType == "custom") == false)
                {
                    throw new Exception("CompilerType Должен быть одним из: native, javavm, dotnet, custom");
                }

                Compiler cmp;
                if (isNewRecord)
                {
                    cmp = new DataModel.Compiler();
                    cmp.CompilerData_ver = 0;
                }
                else
                {
                    cmp = db.Compilers.Where(c => c.Id == Compiler.Id).Single();
                }

                cmp.ShortName      = Compiler.ShortName;
                cmp.FullName       = Compiler.FullName;
                cmp.CompilerType   = Compiler.CompilerType;
                cmp.CompilePath    = Compiler.CompilePath;
                cmp.RunPath        = Compiler.RunPath;
                cmp.Enabled        = Compiler.Enabled;
                cmp.FileNameSource = Compiler.FileNameSource;
                cmp.FileNameTarget = Compiler.FileNameTarget;
                cmp.Note           = Compiler.Note;
                cmp.Extension      = Compiler.Extension;
                cmp.TestCode       = Compiler.TestCode;

                cmp.CompilerData_ver++;

                if (isNewRecord)
                {
                    db.Compilers.AddObject(cmp);
                }

                int res = db.SaveChanges();
                if (res != 1)
                {
                    throw new Exception("Error insert/update operation");
                }

                // если новая запись - то в cmp.Id поместится id этой записи в БД
                return(cmp.Id);
            }
        }
示例#4
0
        public void Parse(string source, string sourceFileName, CompilerDTO dto, ProgramPart part)
        {
            // ANTLR Compile
            var result = ANTLRCompiler.Compile(source, sourceFileName, part);

            // Simple program can not be imported
            if (dto.CompilationUnitList.Count != 0 &&
                result.PsiNode != null &&
                result.PsiNode.Left != null &&
                result.PsiNode.Left.GetType() == typeof(SimpleProgramNode))
            {
                dto.CompilerMessages.Warnings.Add(new Warning
                    {
                        Interval = new Interval() { FileName = sourceFileName },
                        MessageText = string.Format(
                        "Simple programs can not be imported! Compilation unit will be skipped!")
                    });
                return;
            }

            // Create CompilationUnit
            dto.CompilationUnitList.Add(
                new CompilationUnit
                {
                    Source = source,
                    CleanedSourceText = source,
                    FileName = sourceFileName,
                    PsiNodeSyntaxTree = result.PsiNode
                });

            // Generate messages
            if (result.ANTLRExceptionText != "" || result.ANTLRErrorMessages.Count != 0)
            {
                result.ANTLRErrorMessages.ForEach(x =>
                    dto.CompilerMessages.AntlrErrors.Add(new AntlrError
                    {
                        Interval = new Interval() { FileName = sourceFileName },
                        MessageText = x
                    }));

                if (result.ANTLRExceptionText != "")
                    dto.CompilerMessages.AntlrErrors.Add(new AntlrError
                    {
                        Interval = new Interval(),
                        MessageText = result.ANTLRExceptionText
                    });
            }
        }
 public PsiImportResolverVisitor(CompilationUnit cu, CompilerDTO dto, Compiler c)
     : base(cu,dto)
 {
     compiler = c;
     InitHelpers();
 }
 public PsiCodeGeneratorVisitor(CompilationUnit cu, CompilerDTO dto)
     : base(cu,dto)
 {
     InitHelpers();
 }