Beispiel #1
0
 public string Build(string[] fileNames,string[] SearchPaches, List<Error> errors, SourceContextMap sourceContextMap)
 {
     if (PascalPreprocessorParser == null)
         PascalPreprocessorParser = new PascalPreprocessorLanguageParser();
     compilerDirectives = new List<compiler_directive>();
     string text = (string)SourceFilesProvider(fileNames[0], SourceFileOperation.GetText);
     PascalPreprocessorParser.Errors = errors;
     compilation_unit cu = PascalPreprocessorParser.BuildTree(fileNames[0], text, SearchPaches, PascalABCCompiler.Parsers.ParseMode.Normal) as compilation_unit;
     if (errors.Count > 0)
         return text;
     if (cu == null)
         errors.Add(new CompilerInternalError("PascalPreprocessor", new Exception("cu==null")));
     if (cu != null)
         compilerDirectives.AddRange(cu.compiler_directives);
     return text;
 }
Beispiel #2
0
        public override syntax_tree_node BuildTreeInNormalMode(string FileName, string Text)
        {
            Errors.Clear();

            string[] file_names = new string[1];
            file_names[0] = FileName;
            SourceContextMap scm = new SourceContextMap();
            Text = preprocessor2.Build(file_names, Errors, scm);

            localparser.scm = scm;
            ((localparser.parsertools) as pascalabc_parsertools).scm = scm;

            if (Errors.Count > 0)
                return null;

            syntax_tree_node  root = (syntax_tree_node)localparser.Parse(Text);
            if (root != null && root is compilation_unit)
                (root as compilation_unit).file_name = FileName;
            if (preprocessor2.CompilerDirectives != null && preprocessor2.CompilerDirectives.Count != 0)
                localparser.CompilerDirectives.AddRange(preprocessor2.CompilerDirectives);

            return root;
        }
Beispiel #3
0
        //Aspects
        public string GetAspects(List<compiler_directive> cd_list, SourceContextMap sourceContextMap)
        {
            try
            {
                compilerDirectives = new List<compiler_directive>(cd_list);
                //AspectsMap.Clear();

                //GetStructures                
                foreach (compiler_directive cd in compilerDirectives)
                {
                    if (cd.Name.text == ASP)
                    {
                        if (!(AspectsNames.Contains(cd.Directive.text)))
                        //if (!(AspectsMap.ContainsKey(cd.Directive.text)))
                        {
                            AspectsNames.Add(cd.Directive.text);
                            AspectsMap.Add(cd.Directive.text, new Aspect(cd.Directive.text));
                            AspectsMap[cd.Directive.text].AddBegin(cd.source_context);
                        }
                        else                        
                            AspectsMap[cd.Directive.text].AddBegin(cd.source_context);                       
                    }
                    //if (cd.Name.text == )
                }
                foreach (compiler_directive cd in compilerDirectives)
                {
                    if (cd.Name.text == ENDASP)
                    {
                        if (!AspectsNames.Contains(cd.Directive.text))
                        {
                            //Error - unexp end of aspect                        
                        }
                        else
                            AspectsMap[cd.Directive.text].AddEnd(cd.source_context);
                        //AspectsMap.Add(cd.Directive.text, new Aspect(cd.Directive.text, false, cd.source_context));                
                    }
                }
                //Get Text
                StringWriter sw = new StringWriter();
                //SourceContextMap = sourceContextMap;
                List<SourceContext> beg;
                List<SourceContext> end;
                string CurrentFileName;
                string CurrentFileText;

                foreach (string str in AspectsMap.Keys)
                {
                    beg = AspectsMap[str].GetBeginList();
                    end = AspectsMap[str].GetEndList();
              
                    for (int i = 0; i < beg.Count; i++)
                    {
                        CurrentFileName = beg[i].FileName;
                        CurrentFileText = (string)SourceFilesProvider(CurrentFileName, SourceFileOperation.GetText);
                        sw.WriteLine(CurrentFileText.Substring(beg[i].Position, end[i].Position - beg[i].Position + end[i].Length));
                    }                    
                    //AspectsMap[str].GetBeginList();
                }
                return sw.ToString();
            }
            catch (Exception e)
            {
                this.Errors.Add(new PascalABCCompiler.Errors.Error("Error in aspects reading"));
                return "Error in aspects reading";
            }
        }
Beispiel #4
0
 public string Build(string[] fileNames, List<Error> errors, SourceContextMap sourceContextMap)
 {
     compilerDirectives = new List<compiler_directive>();
     StringWriter sw = new StringWriter();
     tw = sw;
     Errors = errors;
     SourceContextMap = sourceContextMap;
     //AspectsMap.Clear();
     ProcessedFileNames.Clear();
     DefineDirectives.Clear();
     foreach (string name in fileNames)
     {
         ProcessFile(name);
         if (sm.GetEndifCount() != 0)
             Errors.Add(new UnexpectedEOF(CurrentFileName, new SourceContext(int.MaxValue, 1, int.MaxValue, 1)));
         if (errors.Count > 0)
             return null;
     }
     return sw.ToString();
 }