From 6ccd4448d4a14984c8a01254eb33294f63c3089e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Thu, 26 May 2016 13:16:32 +0200 Subject: [PATCH] #159 --- CodeCompletion/CodeCompletion.cs | 78 ++++++++----------- Compiler/Compiler.cs | 12 ++- ParserTools/ParserTools/BaseParser.cs | 4 +- ParserTools/ParserTools/IParser.cs | 2 +- ParserTools/ParsersController.cs | 8 +- .../PascalABCParserNewSaushkin/ABCPascal.cs | 8 +- .../PascalABCParserNewSaushkin/ABCPascal.lex | 2 +- .../DocTagsParser/Parser.cs | 2 +- Parsers/PascalABCParserNewSaushkin/Parser.cs | 12 +-- .../VBNETParser/DocTagsParser/DocParser.cs | 2 +- Parsers/VBNETParser/Parser.cs | 2 +- TestSuite/debug1.pas | 10 +++ 12 files changed, 72 insertions(+), 70 deletions(-) create mode 100644 TestSuite/debug1.pas diff --git a/CodeCompletion/CodeCompletion.cs b/CodeCompletion/CodeCompletion.cs index 2f47b0c46..2ef18f310 100644 --- a/CodeCompletion/CodeCompletion.cs +++ b/CodeCompletion/CodeCompletion.cs @@ -68,15 +68,8 @@ namespace CodeCompletion } } - internal compilation_unit ParsersControllerGetComilationUnit(string FileName, string Text, List ErrorsList, bool partParse) + internal compilation_unit ParsersControllerGetCompilationUnit(string FileName, string Text, List ErrorsList) { - string fnpart = FileName + "part" + PascalABCCompiler.Parsers.Controller.HideParserExtensionPostfixChar; - if (partParse) - if (ParsersController.ParserExists(".paspart_")) - { - if (!comp.InternalDebug.UseStandarParserForIntellisense) - FileName = fnpart; - } string ext = Path.GetExtension(FileName); Parser = ParsersController.selectParser(ext.ToLower()); parsers[ext] = Parser; @@ -86,7 +79,7 @@ namespace CodeCompletion return cu; } - internal compilation_unit ParsersControllerGetComilationUnitSpecial(string FileName, string Text, List ErrorsList, bool partParse) + internal compilation_unit ParsersControllerGetCompilationUnitSpecial(string FileName, string Text, List ErrorsList) { string ext = Path.GetExtension(FileName); Parser = ParsersController.selectParser(ext.ToLower()); @@ -106,7 +99,7 @@ namespace CodeCompletion string ext = Path.GetExtension(FileName); try { - cu = ParsersControllerGetComilationUnit(FileName, Text, ErrorsList, true); + cu = ParsersControllerGetCompilationUnit(FileName, Text, ErrorsList); ErrorsList.Clear(); PascalABCCompiler.SyntaxTree.documentation_comment_list dt = ParsersController.Compile(System.IO.Path.ChangeExtension(FileName, get_doctagsParserExtension(ext)), Text/*+")))));end."*/, ErrorsList, PascalABCCompiler.Parsers.ParseMode.Normal) as PascalABCCompiler.SyntaxTree.documentation_comment_list; PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); @@ -134,7 +127,7 @@ namespace CodeCompletion string tmp = ParsersHelper.GetModifiedProgramm(Text); if (tmp != null) { - cu = ParsersControllerGetComilationUnitSpecial(FileName, tmp, ErrorsList, true); + cu = ParsersControllerGetCompilationUnitSpecial(FileName, tmp, ErrorsList); } if (comp_modules[FileName] == null) { @@ -162,45 +155,40 @@ namespace CodeCompletion return dconv; //ConvertToDom(cu); } - + //vremenno, potom ubrat private compilation_unit get_fictive_unit(string s, string FileName) { - program_module prog = new program_module(); - int line = 1; - int col = 1; - for (int i=0; i ErrorsList = new List(); - PascalABCCompiler.SyntaxTree.compilation_unit cu = ParsersControllerGetComilationUnit(FileName, Text, ErrorsList, false); - if (cu == null) - { - ErrorsList.Clear(); - cu = ParsersControllerGetComilationUnit(FileName, Text, ErrorsList, true); - } + PascalABCCompiler.SyntaxTree.compilation_unit cu = ParsersControllerGetCompilationUnit(FileName, Text, ErrorsList); return cu; } @@ -236,7 +224,7 @@ namespace CodeCompletion string tmp = ParsersHelper.GetModifiedProgramm(Text); if (tmp != null) { - cu = ParsersControllerGetComilationUnitSpecial(FileName, tmp, ErrorsList, true); + cu = ParsersControllerGetCompilationUnitSpecial(FileName, tmp, ErrorsList); ErrorsList.Clear(); } if (cu == null) @@ -264,8 +252,6 @@ namespace CodeCompletion return dconv; } - - public DomConverter CompileAllIfNeed(string FileName, bool parse_only_interface=false) { this.FileName = FileName; @@ -300,7 +286,7 @@ namespace CodeCompletion string tmp = ParsersHelper.GetModifiedProgramm(Text); if (tmp != null) { - cu = ParsersControllerGetComilationUnitSpecial(FileName, tmp, ErrorsList, true); + cu = ParsersControllerGetCompilationUnitSpecial(FileName, tmp, ErrorsList); ErrorsList.Clear(); } if (cu == null) diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 2ff891741..64b5ecfaa 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -2743,10 +2743,10 @@ namespace PascalABCCompiler return cu; } - private SyntaxTree.compilation_unit InternalParseText(string FileName, string Text, List ErrorList) + private SyntaxTree.compilation_unit InternalParseText(string FileName, string Text, List ErrorList, List DefinesList = null) { OnChangeCompilerState(this, CompilerState.BeginParsingFile, FileName); - SyntaxTree.compilation_unit cu = ParsersController.GetCompilationUnit(FileName, Text, ErrorsList); + SyntaxTree.compilation_unit cu = ParsersController.GetCompilationUnit(FileName, Text, ErrorsList, DefinesList); OnChangeCompilerState(this, CompilerState.EndParsingFile, FileName); //Вычисляем сколько строк скомпилировали if (ErrorList.Count == 0 && cu != null && cu.source_context!=null) @@ -2893,8 +2893,12 @@ namespace PascalABCCompiler throw new SourceFileNotFound(UnitName); else throw new UnitNotFound(CurrentCompilationUnit.SyntaxTree.file_name, UnitName, SyntaxUsesUnit.source_context); - - CurrentUnit.SyntaxTree = InternalParseText(UnitName, SourceText, errorsList); + List DefinesList = new List(); + if (!compilerOptions.Debug && !compilerOptions.ForDebugging) + DefinesList.Add("RELEASE"); + else + DefinesList.Add("DEBUG"); + CurrentUnit.SyntaxTree = InternalParseText(UnitName, SourceText, errorsList, DefinesList); if (errorsList.Count == 0) // SSM 2/05/16 - для преобразования синтаксических деревьев извне { diff --git a/ParserTools/ParserTools/BaseParser.cs b/ParserTools/ParserTools/BaseParser.cs index 185ad2958..8a7cbc36b 100644 --- a/ParserTools/ParserTools/BaseParser.cs +++ b/ParserTools/ParserTools/BaseParser.cs @@ -103,7 +103,7 @@ namespace PascalABCCompiler.Parsers } } - public virtual PascalABCCompiler.SyntaxTree.syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode) + public virtual PascalABCCompiler.SyntaxTree.syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List DefinesList = null) { syntax_tree_node root = null; @@ -146,7 +146,7 @@ namespace PascalABCCompiler.Parsers } - public virtual syntax_tree_node BuildTreeInNormalMode(string FileName, string Text) + public virtual syntax_tree_node BuildTreeInNormalMode(string FileName, string Text, List DefinesList = null) { return null; } diff --git a/ParserTools/ParserTools/IParser.cs b/ParserTools/ParserTools/IParser.cs index c32086564..cbd8a1126 100644 --- a/ParserTools/ParserTools/IParser.cs +++ b/ParserTools/ParserTools/IParser.cs @@ -60,7 +60,7 @@ namespace PascalABCCompiler.Parsers { get; }*/ - syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode); + syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List DefinesList = null); void Reset(); diff --git a/ParserTools/ParsersController.cs b/ParserTools/ParsersController.cs index 0d21a13eb..82725a79a 100644 --- a/ParserTools/ParsersController.cs +++ b/ParserTools/ParsersController.cs @@ -115,13 +115,13 @@ namespace PascalABCCompiler.Parsers // return p.Keywords; // return null; //} - public SyntaxTree.syntax_tree_node Compile(string FileName, string Text, List Errors, ParseMode ParseMode) + public SyntaxTree.syntax_tree_node Compile(string FileName, string Text, List Errors, ParseMode ParseMode, List DefinesList = null) { LastParser = selectParser(Path.GetExtension(FileName).ToLower()); if (LastParser == null) throw new ParserBadFileExtension(FileName); LastParser.Errors = Errors; - return LastParser.BuildTree(FileName, Text, ParseMode); + return LastParser.BuildTree(FileName, Text, ParseMode, DefinesList); } public SyntaxTree.compilation_unit GetCompilationUnitSpecial(string FileName, string Text, List Errors) { @@ -134,9 +134,9 @@ namespace PascalABCCompiler.Parsers return null; //throw new Errors.CompilerInternalError("Parsers.Controller.GetComilationUnit", new Exception("bad node type")); } - public SyntaxTree.compilation_unit GetCompilationUnit(string FileName, string Text, List Errors) + public SyntaxTree.compilation_unit GetCompilationUnit(string FileName, string Text, List Errors, List DefinesList = null) { - SyntaxTree.syntax_tree_node cu = Compile(FileName, Text, Errors, ParseMode.Normal); + SyntaxTree.syntax_tree_node cu = Compile(FileName, Text, Errors, ParseMode.Normal, DefinesList); if (cu == null) return null; if (cu is SyntaxTree.compilation_unit) diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs index 5d6e4158b..782228d7d 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs @@ -1,9 +1,9 @@ // // This CSharp output file generated by Gardens Point LEX // Version: 1.1.3.301 -// Machine: SSM -// DateTime: 25.04.2016 9:01:24 -// UserName: ????????? +// Machine: IVAN-PC +// DateTime: 26.05.2016 12:11:54 +// UserName: Ivan // GPLEX input file // GPLEX frame file // @@ -140,7 +140,7 @@ public PT parsertools; Stack buffStack = new Stack(); Stack fNameStack = new Stack(); Stack IfStack = new Stack(); // 0 - if, 1 - else - List Defines = new List(); + public List Defines = new List(); int IfExclude; string Pars; string directivename; diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex b/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex index ec8c7ffe6..da7107084 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex @@ -3,7 +3,7 @@ Stack buffStack = new Stack(); Stack fNameStack = new Stack(); Stack IfStack = new Stack(); // 0 - if, 1 - else - List Defines = new List(); + public List Defines = new List(); int IfExclude; string Pars; string directivename; diff --git a/Parsers/PascalABCParserNewSaushkin/DocTagsParser/Parser.cs b/Parsers/PascalABCParserNewSaushkin/DocTagsParser/Parser.cs index 79bdb5c8c..2bb11365f 100644 --- a/Parsers/PascalABCParserNewSaushkin/DocTagsParser/Parser.cs +++ b/Parsers/PascalABCParserNewSaushkin/DocTagsParser/Parser.cs @@ -117,7 +117,7 @@ namespace PascalABCCompiler.DocTagsParser dcs.text = text; return dcs; } - public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode) + public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List DefinesList = null) { MatchCollection mc = Regex.Matches(Text, @"(([\f\t\v\x85\p{Z}])*///.*\r\n)*([\f\t\v\x85\p{Z}])*///.*", RegexOptions.Compiled); syntax_tree_node cu = null; diff --git a/Parsers/PascalABCParserNewSaushkin/Parser.cs b/Parsers/PascalABCParserNewSaushkin/Parser.cs index 538d32c15..767e802f4 100644 --- a/Parsers/PascalABCParserNewSaushkin/Parser.cs +++ b/Parsers/PascalABCParserNewSaushkin/Parser.cs @@ -20,6 +20,7 @@ namespace PascalABCCompiler.PascalABCNewParser private List Errs; private string FileName; public bool build_tree_for_formatter = false; + public List DefinesList = null; public GPPGParserHelper(List Errs, string FileName) { @@ -45,7 +46,8 @@ namespace PascalABCCompiler.PascalABCNewParser Scanner scanner = new Scanner(); scanner.SetSource(Text, 0); scanner.parsertools = parsertools;// передали parsertools в объект сканера - + if (DefinesList != null) + scanner.Defines.AddRange(DefinesList); GPPGParser parser = new GPPGParser(scanner); parsertools.build_tree_for_formatter = build_tree_for_formatter; parser.parsertools = parsertools; // передали parsertools в объект парсера @@ -136,7 +138,7 @@ namespace PascalABCCompiler.PascalABCNewParser //preprocessor2 = new Preprocessor2.Preprocessor2(SourceFilesProvider); } - public override PascalABCCompiler.SyntaxTree.syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode) + public override PascalABCCompiler.SyntaxTree.syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List DefinesList = null) { syntax_tree_node root = null; @@ -144,7 +146,7 @@ namespace PascalABCCompiler.PascalABCNewParser switch (ParseMode) { case ParseMode.Normal: - root = BuildTreeInNormalMode(FileName, Text); + root = BuildTreeInNormalMode(FileName, Text, DefinesList); break; case ParseMode.Expression: root = BuildTreeInExprMode(FileName, Text); @@ -178,7 +180,7 @@ namespace PascalABCCompiler.PascalABCNewParser } - public override syntax_tree_node BuildTreeInNormalMode(string FileName, string Text) + public override syntax_tree_node BuildTreeInNormalMode(string FileName, string Text, List DefinesList = null) { Errors.Clear(); @@ -194,7 +196,7 @@ namespace PascalABCCompiler.PascalABCNewParser return null; localparserhelper = new GPPGParserHelper(Errors, FileName); - + localparserhelper.DefinesList = DefinesList; syntax_tree_node root = localparserhelper.Parse(Text); if (Errors.Count > 0) diff --git a/Parsers/VBNETParser/DocTagsParser/DocParser.cs b/Parsers/VBNETParser/DocTagsParser/DocParser.cs index 0ebdc4eae..f76bba57d 100644 --- a/Parsers/VBNETParser/DocTagsParser/DocParser.cs +++ b/Parsers/VBNETParser/DocTagsParser/DocParser.cs @@ -115,7 +115,7 @@ namespace PascalABCCompiler.VBNETParser dcs.text = text; return dcs; } - public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode) + public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List DefinesList = null) { MatchCollection mc = Regex.Matches(Text, @"(([\f\t\v\x85\p{Z}])*///.*\r\n)*([\f\t\v\x85\p{Z}])*'''.*", RegexOptions.Compiled); syntax_tree_node cu = null; diff --git a/Parsers/VBNETParser/Parser.cs b/Parsers/VBNETParser/Parser.cs index 4f9a7890c..e50f90bd2 100644 --- a/Parsers/VBNETParser/Parser.cs +++ b/Parsers/VBNETParser/Parser.cs @@ -187,7 +187,7 @@ namespace PascalABCCompiler.VBNETParser } } - public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode) + public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List DefinesList = null) { if (string.IsNullOrEmpty(Text)) return null; diff --git a/TestSuite/debug1.pas b/TestSuite/debug1.pas new file mode 100644 index 000000000..57e43d4b0 --- /dev/null +++ b/TestSuite/debug1.pas @@ -0,0 +1,10 @@ +begin +var i: integer; +{$IFDEF DEBUG} +i := 2; +{$ENDIF} +{$IFDEF RELEASE} +i := 3; +{$ENDIF} +assert(i = {$IFDEF DEBUG}2{$ELSE}3{$ENDIF}); +end. \ No newline at end of file