Предупреждения для $else и $endif, у которых не совпадает имя дефайна (#3109)
* `$ifdef`: add warnings * save directive name casing
This commit is contained in:
parent
6612fac1c4
commit
edf3358b39
|
|
@ -139,7 +139,8 @@ namespace GPPGParserScanner
|
|||
public PascalParserTools parserTools;
|
||||
Stack<BufferContext> buffStack = new Stack<BufferContext>();
|
||||
Stack<string> fNameStack = new Stack<string>();
|
||||
Stack<int> IfStack = new Stack<int>(); // 0 - if, 1 - else
|
||||
Stack<bool> IfDefInElseBranch = new Stack<bool>();
|
||||
Stack<string> IfDefVar = new Stack<string>();
|
||||
public List<string> Defines = new List<string>();
|
||||
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) // сл<D181>?<3F>?ай п<>?с<>?ой ди<D0B4>?ек<D0B5>?ив<D0B8>?
|
||||
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) // Ñ<EFBFBD>лÑ?Ñ?ай пÑ?Ñ<>Ñ?ой диÑ?екÑ?ивÑ?
|
||||
if (directiveName == null) // сл<EFBFBD>?<3F>?ай п<>?с<>?ой ди<D0B4>?ек<D0B5>?ив<D0B8>?
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
public PascalParserTools parserTools;
|
||||
Stack<BufferContext> buffStack = new Stack<BufferContext>();
|
||||
Stack<string> fNameStack = new Stack<string>();
|
||||
Stack<int> IfStack = new Stack<int>(); // 0 - if, 1 - else
|
||||
Stack<bool> IfDefInElseBranch = new Stack<bool>();
|
||||
Stack<string> IfDefVar = new Stack<string>();
|
||||
public List<string> Defines = new List<string>();
|
||||
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
|
|||
<EXCLUDETEXT>{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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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'
|
||||
|
|
@ -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'
|
||||
|
|
@ -76,4 +76,5 @@ BAD_INT2=Слишком маленькое целое
|
|||
INVALID_INTERFACE_MEMBER=Члены интерфейса не могут иметь определение
|
||||
EXTENDED_INDEXED_PROPERTIES=Индексные свойства не могут быть расширенными
|
||||
TWO_STRING_LITERALS_IN_SUCCESSION=Две литеральные строковые константы не могут стоять подряд
|
||||
ATTRIBUTE_REDECLARED=Повторное задание атрибута
|
||||
ATTRIBUTE_REDECLARED=Повторное задание атрибута
|
||||
DIFF_DEFINE_NAME=Ім'я визначення '{2}' в директиві '{0}' не співпадає з іменем визначення '{1}' з відповідного 'ifdef'/'ifndef'
|
||||
|
|
@ -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=左侧不能分配给
|
||||
LEFT_SIDE_CANNOT_BE_ASSIGNED_TO=左侧不能分配给
|
||||
DIFF_DEFINE_NAME=指令'{0}'中的定義名稱'{2}'與相應的'ifdef'/'ifndef'中的定義名稱'{1}'不匹配
|
||||
Loading…
Reference in a new issue