Skip to content

Commit 6d60707

Browse files
author
jbontes
committed
RomanYankovsky#250 record constants are not recorded correctly
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.
1 parent 8ae51f0 commit 6d60707

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Source/DelphiAST.Consts.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface
116116
ntProperty,
117117
ntRaise,
118118
ntRead,
119+
ntRecordConstant,
119120
ntRecordConstraint,
120121
ntRecordVariant,
121122
ntRepeat,

Source/DelphiAST.pas

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ TPasSyntaxTreeBuilder = class(TmwSimplePasPar)
216216
procedure PropertyParameterList; override;
217217
procedure RaiseStatement; override;
218218
procedure RecordConstraint; override;
219+
procedure RecordConstant; override;
219220
procedure RecordFieldConstant; override;
220221
procedure RecordType; override;
221222
procedure RecordVariant; override;
@@ -333,7 +334,7 @@ TStringStreamHelper = class helper for TStringStream
333334
// do not use const strings here to prevent allocating new strings every time
334335

335336
type
336-
TAttributeValue = (atAsm, atTrue, atFunction, atProcedure, atOperator, atClassOf, atClass,
337+
TAttributeValue = (atAsm, atTrue, atFunction, atProcedure, atOperator, atClass_Of, atClass,
337338
atConst, atConstructor, atDestructor, atEnum, atInterface, atNil, atNumeric,
338339
atOut, atPointer, atName, atString, atSubRange, atVar, atType{ExplicitType},
339340
atObject, atSealed, atAbstract, atBegin, atOf_Object{procedure of object},
@@ -984,7 +985,7 @@ procedure TPasSyntaxTreeBuilder.ClassProperty;
984985

985986
procedure TPasSyntaxTreeBuilder.ClassReferenceType;
986987
begin
987-
FStack.Push(ntType).Attribute[anType]:= AttributeValues[atClassof];
988+
FStack.Push(ntType).Attribute[anType]:= AttributeValues[atClass_of];
988989
try
989990
inherited;
990991
finally
@@ -1143,6 +1144,15 @@ procedure TPasSyntaxTreeBuilder.ConstructorConstraint;
11431144
end;
11441145
end;
11451146

1147+
procedure TPasSyntaxTreeBuilder.RecordConstant;
1148+
begin
1149+
FStack.Push(ntRecordConstant);
1150+
try
1151+
inherited;
1152+
finally
1153+
FStack.Pop;
1154+
end;
1155+
end;
11461156
procedure TPasSyntaxTreeBuilder.RecordConstraint;
11471157
begin
11481158
FStack.Push(ntRecordConstraint);
@@ -2190,9 +2200,17 @@ procedure TPasSyntaxTreeBuilder.RecordFieldConstant;
21902200
var
21912201
Node: TSyntaxNode;
21922202
begin
2193-
Node := FStack.PushValuedNode(ntField, Lexer.Token);
2203+
//A field in a record constant should have exactly the same layout
2204+
//as a field in a class.
2205+
//ntField (class)
2206+
//+-- ntName (anName = name)
2207+
//+-- ntType
2208+
//Recordconstant
2209+
//ntField (recordconstant)
2210+
//+-- ntName
2211+
//+-- ntExpression.
2212+
FStack.Push(ntField).AddChild(ntName).Attribute[anName]:= Lexer.Token;
21942213
try
2195-
Node.Attribute[anType]:= AttributeValues[atName];
21962214
inherited;
21972215
finally
21982216
FStack.Pop;

0 commit comments

Comments
 (0)