This commit is contained in:
Бондарев Иван 2016-05-26 13:16:32 +02:00
parent d8f195656c
commit 6ccd4448d4
12 changed files with 72 additions and 70 deletions

View file

@ -68,15 +68,8 @@ namespace CodeCompletion
}
}
internal compilation_unit ParsersControllerGetComilationUnit(string FileName, string Text, List<Error> ErrorsList, bool partParse)
internal compilation_unit ParsersControllerGetCompilationUnit(string FileName, string Text, List<Error> 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<Error> ErrorsList, bool partParse)
internal compilation_unit ParsersControllerGetCompilationUnitSpecial(string FileName, string Text, List<Error> 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<s.Length; i++)
if (s[i] == '\n')
{
line++;
col = 1;
}
else
{
col++;
}
prog.source_context = new SourceContext(1,1,line+3,3);
prog.program_block = new block();
prog.file_name = FileName;
statement_list sl = new statement_list();
prog.program_block.program_code = sl;
prog.program_block.program_code.left_logical_bracket = new token_info("begin");
prog.program_block.program_code.left_logical_bracket.source_context = new SourceContext(1,1,1,5);
prog.program_block.program_code.right_logical_bracket = new token_info("end");
prog.program_block.program_code.right_logical_bracket.source_context = new SourceContext(line+3,1,line+3,3);
sl.subnodes.Add(new empty_statement());
return prog;
program_module prog = new program_module();
int line = 1;
int col = 1;
for (int i = 0; i < s.Length; i++)
if (s[i] == '\n')
{
line++;
col = 1;
}
else
{
col++;
}
prog.source_context = new SourceContext(1, 1, line + 3, 3);
prog.program_block = new block();
prog.file_name = FileName;
statement_list sl = new statement_list();
prog.program_block.program_code = sl;
prog.program_block.program_code.left_logical_bracket = new token_info("begin");
prog.program_block.program_code.left_logical_bracket.source_context = new SourceContext(1, 1, 1, 5);
prog.program_block.program_code.right_logical_bracket = new token_info("end");
prog.program_block.program_code.right_logical_bracket.source_context = new SourceContext(line + 3, 1, line + 3, 3);
sl.subnodes.Add(new empty_statement());
return prog;
}
public PascalABCCompiler.SyntaxTree.compilation_unit ParseOnlySyntaxTree(string FileName, string Text)
{
List<PascalABCCompiler.Errors.Error> ErrorsList = new List<PascalABCCompiler.Errors.Error>();
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)

View file

@ -2743,10 +2743,10 @@ namespace PascalABCCompiler
return cu;
}
private SyntaxTree.compilation_unit InternalParseText(string FileName, string Text, List<Error> ErrorList)
private SyntaxTree.compilation_unit InternalParseText(string FileName, string Text, List<Error> ErrorList, List<string> 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<string> DefinesList = new List<string>();
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 - для преобразования синтаксических деревьев извне
{

View file

@ -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<string> 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<string> DefinesList = null)
{
return null;
}

View file

@ -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<string> DefinesList = null);
void Reset();

View file

@ -115,13 +115,13 @@ namespace PascalABCCompiler.Parsers
// return p.Keywords;
// return null;
//}
public SyntaxTree.syntax_tree_node Compile(string FileName, string Text, List<Error> Errors, ParseMode ParseMode)
public SyntaxTree.syntax_tree_node Compile(string FileName, string Text, List<Error> Errors, ParseMode ParseMode, List<string> 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<Error> 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<Error> Errors)
public SyntaxTree.compilation_unit GetCompilationUnit(string FileName, string Text, List<Error> Errors, List<string> 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)

View file

@ -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 <ABCPascal.lex>
// GPLEX frame file <embedded resource>
//
@ -140,7 +140,7 @@ public PT parsertools;
Stack<BufferContext> buffStack = new Stack<BufferContext>();
Stack<string> fNameStack = new Stack<string>();
Stack<int> IfStack = new Stack<int>(); // 0 - if, 1 - else
List<string> Defines = new List<string>();
public List<string> Defines = new List<string>();
int IfExclude;
string Pars;
string directivename;

View file

@ -3,7 +3,7 @@
Stack<BufferContext> buffStack = new Stack<BufferContext>();
Stack<string> fNameStack = new Stack<string>();
Stack<int> IfStack = new Stack<int>(); // 0 - if, 1 - else
List<string> Defines = new List<string>();
public List<string> Defines = new List<string>();
int IfExclude;
string Pars;
string directivename;

View file

@ -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<string> 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;

View file

@ -20,6 +20,7 @@ namespace PascalABCCompiler.PascalABCNewParser
private List<Errors.Error> Errs;
private string FileName;
public bool build_tree_for_formatter = false;
public List<string> DefinesList = null;
public GPPGParserHelper(List<Errors.Error> 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<string> 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<string> 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)

View file

@ -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<string> 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;

View file

@ -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<string> DefinesList = null)
{
if (string.IsNullOrEmpty(Text))
return null;

10
TestSuite/debug1.pas Normal file
View file

@ -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.