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

Record constants are not recorded correctly + fields in record constants are recorded differently from other ntField nodes. #250

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

Comments

@JBontes
Copy link

JBontes commented Oct 15, 2017

Consider the following example:

unit Test;
interface
const
  OperatorsInfo: array [0..2] of TOperatorInfo =
    ((Typ: ntAddr;         AssocType: atRight),
     (Typ: ntDeref;        AssocType: atLeft),
     (Typ: ntGeneric;      AssocType: atRight));

implementation
end.

The record constants are not recorded.
In addition the ntField nodes are constructed different from ntField nodes elsewhere.
All ntField should be constructed the same, so that we don't need different code to decode them
depending on the context.

The fix:

procedure TPasSyntaxTreeBuilder.RecordConstant;
begin
  FStack.Push(ntRecordConstant);
  try
    inherited;
  finally
    FStack.Pop;
  end;
end;

procedure TPasSyntaxTreeBuilder.RecordFieldConstant;
var
  Node: TSyntaxNode;
begin
  //A field in a record constant should have exactly the same layout
  //as a field in a class.
  //ntField (class)
  //+-- ntName (anName = name)
  //+-- ntType
  //Recordconstant
  //ntField (recordconstant)
  //+-- ntName
  //+-- ntExpression.
  FStack.Push(ntField).AddChild(ntName).Attribute[anName]:= Lexer.Token;
  try
    inherited;
  finally
    FStack.Pop;
  end;
end;
@JBontes JBontes changed the title Record constants are not recorded correctly + fields in record constants or recorded differently from other ntField nodes. Record constants are not recorded correctly + fields in record constants are recorded differently from other ntField nodes. Oct 15, 2017
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 15, 2017
This is esp. evident in the following example:
const
  OperatorsInfo: array [0..2] of TOperatorInfo =
    ((Typ: ntAddr;         AssocType: atRight),
     (Typ: ntDeref;        AssocType: atLeft),
     (Typ: ntGeneric;      AssocType: atRight));

All constants are incorrectly listed as one long list, instead of as separate records.
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