Because the anName attribute can (and does) come from Lexer.Token. It can be anything. If I create a type named subrange or enum, which is perfectly legal, it will clash with the anName attribute for an actual enum or subrange.
Instead the fact that a type is a subrange or enum should be stored in a anType attribute.
Faulty
procedure TPasSyntaxTreeBuilder.SubrangeType;
begin
FStack.Push(ntType).SetAttribute(anName, AttributeValues[atSubRange]);
try
inherited;
finally
FStack.Pop;
end;
end;
procedure TPasSyntaxTreeBuilder.EnumeratedType;
var
TypeNode: TSyntaxNode;
begin
TypeNode := FStack.Push(ntType);
try
TypeNode.SetAttribute(anName, AttributeValues[atEnum]);
if ScopedEnums then
TypeNode.SetAttribute(anVisibility, 'scoped');
inherited;
finally
FStack.Pop;
end;
end;
Fix
```Delphi
procedure TPasSyntaxTreeBuilder.SubrangeType;
begin
FStack.Push(ntType).SetAttribute(anType, AttributeValues[atSubRange]);
try
inherited;
finally
FStack.Pop;
end;
end;
procedure TPasSyntaxTreeBuilder.EnumeratedType;
var
TypeNode: TSyntaxNode;
begin
TypeNode := FStack.Push(ntType);
try
TypeNode.SetAttribute(anType, AttributeValues[atEnum]);
if ScopedEnums then
TypeNode.SetAttribute(anVisibility, 'scoped');
inherited;
finally
FStack.Pop;
end;
end;
Because the anName attribute can (and does) come from
Lexer.Token
. It can be anything. If I create a type namedsubrange
orenum
, which is perfectly legal, it will clash with the anName attribute for an actual enum or subrange.Instead the fact that a type is a
subrange
orenum
should be stored in a anType attribute.Faulty
Fix