diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs index 1fc6f8b8b..7ed42c065 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs @@ -139,7 +139,8 @@ namespace GPPGParserScanner public PascalParserTools parserTools; Stack buffStack = new Stack(); Stack fNameStack = new Stack(); - Stack IfStack = new Stack(); // 0 - if, 1 - else + Stack IfDefInElseBranch = new Stack(); + Stack IfDefVar = new Stack(); public List Defines = new List(); int IfExclude; string Pars; @@ -2182,8 +2183,9 @@ if (parserTools.buildTreeForFormatter) break; parserTools.ParseDirective(yytext, CurrentLexLocation, out var directiveName, out var directiveParams); - - if (directiveName == null) // слÑ?Ñ?ай пÑ?сÑ?ой диÑ?екÑ?ивÑ? + var orgDirectiveName = directiveName; + + if (directiveName == null) // сл�?�?ай п�?с�?ой ди�?ек�?ив�? break; parserTools.CheckDirectiveParams(directiveName, directiveParams, CurrentLexLocation); @@ -2200,7 +2202,8 @@ if (parserTools.buildTreeForFormatter) } else if (directiveName == "IFDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); if (!Defines.Contains(directiveParams[0])) { BEGIN(EXCLUDETEXT); @@ -2209,7 +2212,8 @@ if (parserTools.buildTreeForFormatter) } else if (directiveName == "IFNDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); if (Defines.Contains(directiveParams[0])) { BEGIN(EXCLUDETEXT); @@ -2218,20 +2222,22 @@ if (parserTools.buildTreeForFormatter) } else if (directiveName == "ELSE") { - if (IfStack.Count==0) + if (directiveParams.Count!=0 && directiveParams[0]!=IfDefVar.Peek()) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, IfDefVar.Peek(), directiveParams[0]); + if (IfDefInElseBranch.Count==0 || IfDefInElseBranch.Pop()) parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation); - if (IfStack.Peek()==1) - parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation); - IfStack.Pop(); - IfStack.Push(1); + IfDefInElseBranch.Push(true); BEGIN(EXCLUDETEXT); IfExclude = 1; } else if (directiveName == "ENDIF") { - if (IfStack.Count == 0) + if (IfDefInElseBranch.Count == 0) parserTools.AddErrorFromResource("UNNECESSARY $endif",CurrentLexLocation); - IfStack.Pop(); + IfDefInElseBranch.Pop(); + var define_name = IfDefVar.Pop(); + if (directiveParams.Count!=0 && directiveParams[0]!=define_name) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, define_name, directiveParams[0]); } else if (directiveName == "DEFINE") { @@ -2275,8 +2281,9 @@ BEGIN(INITIAL); break; case 74: parserTools.ParseDirective(yytext, CurrentLexLocation, out directiveName, out directiveParams); + orgDirectiveName = directiveName; - if (directiveName == null) // слÑ?Ñ?ай пÑ?сÑ?ой диÑ?екÑ?ивÑ? + if (directiveName == null) // сл�?�?ай п�?с�?ой ди�?ек�?ив�? break; parserTools.CheckDirectiveParams(directiveName, directiveParams, CurrentLexLocation); @@ -2285,29 +2292,35 @@ parserTools.ParseDirective(yytext, CurrentLexLocation, out directiveName, out di if (directiveName == "IFDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); IfExclude++; } else if (directiveName == "IFNDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); IfExclude++; } else if (directiveName == "ELSE") { - if (IfStack.Peek() == 1) + if (directiveParams.Count!=0 && directiveParams[0]!=IfDefVar.Peek()) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, IfDefVar.Peek(), directiveParams[0]); + if (IfDefInElseBranch.Count==0 || IfDefInElseBranch.Pop()) parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation); - IfStack.Pop(); - IfStack.Push(1); + IfDefInElseBranch.Push(true); if (IfExclude == 1) BEGIN(INITIAL); } else if (directiveName == "ENDIF") { - if (IfStack.Count==0) + if (IfDefInElseBranch.Count == 0) parserTools.AddErrorFromResource("UNNECESSARY $endif",CurrentLexLocation); - IfStack.Pop(); - IfExclude--; + IfDefInElseBranch.Pop(); + var define_name = IfDefVar.Pop(); + if (directiveParams.Count!=0 && directiveParams[0]!=define_name) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, define_name, directiveParams[0]); + IfExclude--; if (IfExclude == 0) BEGIN(INITIAL); } @@ -2434,7 +2447,7 @@ public LexLocation CurrentLexLocation protected override bool yywrap() { - if (IfStack.Count > 0) + if (IfDefInElseBranch.Count != 0) parserTools.AddErrorFromResource("ENDIF_ABSENT",CurrentLexLocation); BEGIN(INITIAL); if (buffStack.Count == 0) diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex b/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex index 0af9c577b..ae0a0654f 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.lex @@ -2,7 +2,8 @@ public PascalParserTools parserTools; Stack buffStack = new Stack(); Stack fNameStack = new Stack(); - Stack IfStack = new Stack(); // 0 - if, 1 - else + Stack IfDefInElseBranch = new Stack(); + Stack IfDefVar = new Stack(); public List Defines = new List(); int IfExclude; string Pars; @@ -70,7 +71,8 @@ UNICODEARROW \x890 break; parserTools.ParseDirective(yytext, CurrentLexLocation, out var directiveName, out var directiveParams); - + var orgDirectiveName = directiveName; + if (directiveName == null) // случай пустой директивы break; @@ -88,7 +90,8 @@ UNICODEARROW \x890 } else if (directiveName == "IFDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); if (!Defines.Contains(directiveParams[0])) { BEGIN(EXCLUDETEXT); @@ -97,7 +100,8 @@ UNICODEARROW \x890 } else if (directiveName == "IFNDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); if (Defines.Contains(directiveParams[0])) { BEGIN(EXCLUDETEXT); @@ -106,20 +110,22 @@ UNICODEARROW \x890 } else if (directiveName == "ELSE") { - if (IfStack.Count==0) + if (directiveParams.Count!=0 && directiveParams[0]!=IfDefVar.Peek()) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, IfDefVar.Peek(), directiveParams[0]); + if (IfDefInElseBranch.Count==0 || IfDefInElseBranch.Pop()) parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation); - if (IfStack.Peek()==1) - parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation); - IfStack.Pop(); - IfStack.Push(1); + IfDefInElseBranch.Push(true); BEGIN(EXCLUDETEXT); IfExclude = 1; } else if (directiveName == "ENDIF") { - if (IfStack.Count == 0) + if (IfDefInElseBranch.Count == 0) parserTools.AddErrorFromResource("UNNECESSARY $endif",CurrentLexLocation); - IfStack.Pop(); + IfDefInElseBranch.Pop(); + var define_name = IfDefVar.Pop(); + if (directiveParams.Count!=0 && directiveParams[0]!=define_name) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, define_name, directiveParams[0]); } else if (directiveName == "DEFINE") { @@ -140,6 +146,7 @@ UNICODEARROW \x890 {DIRECTIVE} { parserTools.ParseDirective(yytext, CurrentLexLocation, out directiveName, out directiveParams); + orgDirectiveName = directiveName; if (directiveName == null) // случай пустой директивы break; @@ -150,29 +157,35 @@ UNICODEARROW \x890 if (directiveName == "IFDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); IfExclude++; } else if (directiveName == "IFNDEF") { - IfStack.Push(0); + IfDefInElseBranch.Push(false); + IfDefVar.Push(directiveParams[0]); IfExclude++; } else if (directiveName == "ELSE") { - if (IfStack.Peek() == 1) + if (directiveParams.Count!=0 && directiveParams[0]!=IfDefVar.Peek()) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, IfDefVar.Peek(), directiveParams[0]); + if (IfDefInElseBranch.Count==0 || IfDefInElseBranch.Pop()) parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation); - IfStack.Pop(); - IfStack.Push(1); + IfDefInElseBranch.Push(true); if (IfExclude == 1) BEGIN(INITIAL); } else if (directiveName == "ENDIF") { - if (IfStack.Count==0) + if (IfDefInElseBranch.Count == 0) parserTools.AddErrorFromResource("UNNECESSARY $endif",CurrentLexLocation); - IfStack.Pop(); - IfExclude--; + IfDefInElseBranch.Pop(); + var define_name = IfDefVar.Pop(); + if (directiveParams.Count!=0 && directiveParams[0]!=define_name) + parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, define_name, directiveParams[0]); + IfExclude--; if (IfExclude == 0) BEGIN(INITIAL); } @@ -563,7 +576,7 @@ UNICODEARROW \x890 protected override bool yywrap() { - if (IfStack.Count > 0) + if (IfDefInElseBranch.Count != 0) parserTools.AddErrorFromResource("ENDIF_ABSENT",CurrentLexLocation); BEGIN(INITIAL); if (buffStack.Count == 0) diff --git a/bin/Lng/Eng/PascalABCParser.dat b/bin/Lng/Eng/PascalABCParser.dat index 10bf37003..3c029df1f 100644 --- a/bin/Lng/Eng/PascalABCParser.dat +++ b/bin/Lng/Eng/PascalABCParser.dat @@ -94,4 +94,5 @@ NESTED_RECORD_DEFINITIONS_ARE_ARE_FORBIDDEN=Nested record definitions are forbid NIL_IN_UNNAMED_OBJECT=Anonymous class field cannot be initialized by nil constant YIELD_STATEMENT_CANNOT_BE_USED_IN_LAMBDA_BODY=yield statement cannot be used in lambda body SLICES_OF MULTIDIMENSIONAL_ARRAYS_ALLOW_ONLY_FOR_RANK_LT_5=Slices of multidimensional arrays are allowed only for arrays with rank < 5 -LEFT_SIDE_CANNOT_BE_ASSIGNED_TO=Left side cannot be assigned to \ No newline at end of file +LEFT_SIDE_CANNOT_BE_ASSIGNED_TO=Left side cannot be assigned to +DIFF_DEFINE_NAME=The define name '{2}' in directive '{0}' does not match define name '{1}' from the corresponding 'ifdef'/'ifndef' \ No newline at end of file diff --git a/bin/Lng/Rus/PascalABCParser.dat b/bin/Lng/Rus/PascalABCParser.dat index ee79d658c..8aa5399b0 100644 --- a/bin/Lng/Rus/PascalABCParser.dat +++ b/bin/Lng/Rus/PascalABCParser.dat @@ -94,3 +94,4 @@ NIL_IN_UNNAMED_OBJECT=Поле анонимного класса не может YIELD_STATEMENT_CANNOT_BE_USED_IN_LAMBDA_BODY=Оператор yield нельзя использовать в теле лямбда-выражения SLICES_OF MULTIDIMENSIONAL_ARRAYS_ALLOW_ONLY_FOR_RANK_LT_5=Срезы многомерных массивов разрешены только для массивов размерности < 5 LEFT_SIDE_CANNOT_BE_ASSIGNED_TO=Нельзя присвоить левой части +DIFF_DEFINE_NAME=Имя определения '{2}' в директиве '{0}' не совпадает с именем определения '{1}' из соответствующего 'ifdef'/'ifndef' \ No newline at end of file diff --git a/bin/Lng/Ukr/PascalABCParser.dat b/bin/Lng/Ukr/PascalABCParser.dat index 606c604db..69e1a8356 100644 --- a/bin/Lng/Ukr/PascalABCParser.dat +++ b/bin/Lng/Ukr/PascalABCParser.dat @@ -76,4 +76,5 @@ BAD_INT2=Слишком маленькое целое INVALID_INTERFACE_MEMBER=Члены интерфейса не могут иметь определение EXTENDED_INDEXED_PROPERTIES=Индексные свойства не могут быть расширенными TWO_STRING_LITERALS_IN_SUCCESSION=Две литеральные строковые константы не могут стоять подряд -ATTRIBUTE_REDECLARED=Повторное задание атрибута \ No newline at end of file +ATTRIBUTE_REDECLARED=Повторное задание атрибута +DIFF_DEFINE_NAME=Ім'я визначення '{2}' в директиві '{0}' не співпадає з іменем визначення '{1}' з відповідного 'ifdef'/'ifndef' \ No newline at end of file diff --git a/bin/Lng/zh_CN/PascalABCParser.dat b/bin/Lng/zh_CN/PascalABCParser.dat index 69a39e87e..1e760f273 100644 --- a/bin/Lng/zh_CN/PascalABCParser.dat +++ b/bin/Lng/zh_CN/PascalABCParser.dat @@ -85,4 +85,5 @@ NESTED_RECORD_DEFINITIONS_ARE_ARE_FORBIDDEN=禁止嵌套记录定义 NIL_IN_UNNAMED_OBJECT=匿名类字段不能被 nil 常量初始化 YIELD_STATEMENT_CANNOT_BE_USED_IN_LAMBDA_BODY=yield 语句不能在 lambda 主体中使用 SLICES_OF MULTIDIMENSIONAL_ARRAYS_ALLOW_ONLY_FOR_RANK_LT_5=多维数组切片仅适用于秩 < 5 的数组 -LEFT_SIDE_CANNOT_BE_ASSIGNED_TO=左侧不能分配给 \ No newline at end of file +LEFT_SIDE_CANNOT_BE_ASSIGNED_TO=左侧不能分配给 +DIFF_DEFINE_NAME=指令'{0}'中的定義名稱'{2}'與相應的'ifdef'/'ifndef'中的定義名稱'{1}'不匹配 \ No newline at end of file