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

designated initializer style #32

Closed
roptat opened this issue May 14, 2021 · 3 comments · Fixed by #35
Closed

designated initializer style #32

roptat opened this issue May 14, 2021 · 3 comments · Fixed by #35

Comments

@roptat
Copy link
Contributor

roptat commented May 14, 2021

Sorry, here's another one :D

struct point {
  int    x;
  int    y;
};

int main() {
  struct point p = { .y = 2, .x = 1 };
}

fails to parse the initialization of variable p.

designated initializer style is a C99 feature.

@ivg
Copy link
Member

ivg commented May 14, 2021

Yeah, that's the syntax I always found myself hard to grasp) Do you plan to work on it?

@roptat
Copy link
Contributor Author

roptat commented May 14, 2021

I'll give it a try

@ivg
Copy link
Member

ivg commented May 14, 2021

Awesome, I meantime, added more tests. With that said, could you please include tests in your next patch? It is easy with dune cram, just take the code you examples and put into ctoxml/test.t/c99-struct-initializers.c and add the following line to ctoxml/test.t/run.t (notice a pair of spaces before $, they are important)

  $ ctoxml c99-struct-initializers.c

Then run dune test and it will spill the diff saying that there is a change in the tests, review if the output matches your expectations, and once it does, just do

dune promote

to accept this output.

roptat pushed a commit to roptat/FrontC that referenced this issue May 14, 2021
Fixes BinaryAnalysisPlatform#32.

* frontc/cabs.ml: Add `DESIGNATED` expression type for struct
initialization.
* frontc/cparser.mly: Add rules for compounds (struct initialization).  A
compound contains a list of expressions or designated, but a standard
initialization cannot be a designated outside a compound.
* frontc/cprint.ml: Print new AST type.
* frontc/ctoxml.ml: Print XML for new designated AST type.
* ctoxml/test.t/c99-struct-initializers.c: New test.
* ctoxml/test.t/run.t: Update expected output for new test.
roptat pushed a commit to roptat/FrontC that referenced this issue May 14, 2021
Fixes BinaryAnalysisPlatform#32.

* frontc/cabs.ml: Add `DESIGNATOR` expression type for struct
initialization.
* frontc/cparser.mly: Add rules for compounds (struct initialization).  A
compound contains a list of expressions or designated, but a standard
initialization cannot be a designated outside a compound.
* frontc/cprint.ml: Print new AST type.
* frontc/ctoxml.ml: Print XML for new designated AST type.
* ctoxml/test.t/c99-struct-initializers.c: New test.
* ctoxml/test.t/run.t: Update expected output for new test.
roptat pushed a commit to roptat/FrontC that referenced this issue May 14, 2021
Fixes BinaryAnalysisPlatform#32.

* frontc/cabs.ml: Add `DESIGNATED` expression type for struct
initialization.
* frontc/cparser.mly: Add rules for compounds (struct initialization).  A
compound contains a list of expressions or designated, but a standard
initialization cannot be a designated outside a compound.
* frontc/cprint.ml: Print new AST type.
* frontc/ctoxml.ml: Print XML for new designated AST type.
* ctoxml/test.t/c99-struct-initializers.c: New test.
* ctoxml/test.t/run.t: Update expected output for new test.
@ivg ivg closed this as completed in #35 May 14, 2021
ivg pushed a commit that referenced this issue May 14, 2021
Fixes #32.

* frontc/cabs.ml: Add `DESIGNATED` expression type for struct
initialization.
* frontc/cparser.mly: Add rules for compounds (struct initialization).  A
compound contains a list of expressions or designated, but a standard
initialization cannot be a designated outside a compound.
* frontc/cprint.ml: Print new AST type.
* frontc/ctoxml.ml: Print XML for new designated AST type.
* ctoxml/test.t/c99-struct-initializers.c: New test.
* ctoxml/test.t/run.t: Update expected output for new test.

Co-authored-by: Julien Lepiller <julien.lepiller@yale.edu>
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

Successfully merging a pull request may close this issue.

2 participants