Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronisation between TOperators and TSyntaxNodeType is not enforced. #258

Open
JBontes opened this issue Oct 19, 2017 · 0 comments
Open

Comments

@JBontes
Copy link

JBontes commented Oct 19, 2017

If I add a new operator and mix up the definition for TOperators, DelphiAST will not complain.

A simple fix solves this issue, forcing the two structures to be in sync.

const
  OperatorsInfo: array [ntAddr..ntIs] of TOperatorInfo =  //1: use A TSyntaxNodeType as the index.
    ((Typ: ntAddr;         Priority: 1; Kind: okUnary;  AssocType: atRight),
     (Typ: ntDoubleAddr;   Priority: 1; Kind: okUnary;  AssocType: atRight),
     (Typ: ntDeref;        Priority: 1; Kind: okUnary;  AssocType: atLeft),
...

class function TOperators.GetItem(Typ: TSyntaxNodeType): TOperatorInfo;
begin
  Assert(Typ = OperatorsInfo[Typ].Typ);  //2: force the Typ's to match.
  if (Typ in [ntAddr..ntIs]) then Exit(OperatorsInfo[Typ])
  else Assert(false);  //do not allow buffer overruns.
end;
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 19, 2017
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant