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

in procedure X(y: array of const) the const part is registered incorrectly. #255

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

Comments

@JBontes
Copy link

JBontes commented Oct 17, 2017

The following code:

...
  procedure FailFmt(args: array of const);
  procedure FailFmt2(args: array of string);
...

Gets parsed as:

...
            <PARAMETERS line="7" col="20">
              <PARAMETER line="7" col="21">
                <NAME line="7" col="21" name="args"/>
                <TYPE line="7" col="27" type="array">
                  <BOUNDS line="7" col="33"/>
                  <TYPE line="7" col="36" name="const">
                    <IDENTIFIER line="7" col="36" name="const"/>
                  </TYPE>
                </TYPE>
              </PARAMETER>
            </PARAMETERS>
  ...
            <PARAMETERS line="8" col="21">
              <PARAMETER line="8" col="22">
                <NAME line="8" col="22" name="args"/>
                <TYPE line="8" col="28" type="array">
                  <BOUNDS line="8" col="34"/>
                  <TYPE line="8" col="37" name="string"/>
                </TYPE>
              </PARAMETER>
            </PARAMETERS>
  ...

The const keyword is incorrectly tagged as an identifier. It is not.
array of const is a special construct that should be treated specially.
See: http://www.dragonkiller.nl/Delphi/delphi2009.html#ArraySubType

I propose the following changes:

procedure TPasSyntaxTreeBuilder.ArrayOfConst;
begin
  //do not fill the name attribute. const is a keyword, not a type.
  //note that the `anType` attribute is empty.
  FStack.Push(ntType).Attribute[anKind]:= AttributeValues[atConst];
  try
    inherited;
  finally
    FStack.Pop;
  end;
end;

procedure TmwSimplePasPar.ArrayType;
begin
  Expected(ptArray);
  ArrayBounds;
  Expected(ptOf);
  ArraySubType;
end;

procedure TmwSimplePasPar.ArrayOfConst;
begin
  Expected(ptConst);
end;

procedure TmwSimplePasPar.ArraySubType;
begin
  case TokenID of
    ptConst: ArrayOfConst;
    else TypeKind;
  end;
end;
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 17, 2017
array of const is a special construct. `const` here is not an identifier.
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