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

Parse struct and union #148

Merged
merged 5 commits into from
May 13, 2024
Merged

Parse struct and union #148

merged 5 commits into from
May 13, 2024

Conversation

leewei05
Copy link
Contributor

@leewei05 leewei05 commented May 10, 2024

This PR parses struct and union type declaration.

  • A new declaration node RecordDeclNode for struct and union.
  • A new declaration node FieldNode for fields of struct or union.
  • Introduces StructType and UnionType.

TODO: Just like we discusses, I will create a new symbol table (probably the same members but different name) under scope in the future PRs.

The output format is copied from clang:

$ clang -Xclang -ast-dump test/typecheck/struct.c
-FunctionDecl 0x55bf9d309910 <test/typecheck/struct.c:1:1, line:17:1> line:1:5 main 'int ()'
  `-CompoundStmt 0x55bf9d309ed0 <col:12, line:17:1>
    |-DeclStmt 0x55bf9d309aa0 <line:2:3, col:12>
    | `-RecordDecl 0x55bf9d3099f8 <col:3, col:10> col:10 struct ss
    |-DeclStmt 0x55bf9d309c98 <line:4:3, line:8:4>
    | `-RecordDecl 0x55bf9d309ab8 <line:4:3, line:8:3> line:4:10 struct birth definition
    |   |-FieldDecl 0x55bf9d309b78 <line:5:5, col:9> col:9 date 'int'
    |   |-FieldDecl 0x55bf9d309be0 <line:6:5, col:9> col:9 month 'int'
    |   `-FieldDecl 0x55bf9d309c48 <line:7:5, col:9> col:9 year 'int'
    |-DeclStmt 0x55bf9d309e88 <line:10:3, line:14:4>
    | `-RecordDecl 0x55bf9d309cb0 <line:10:3, line:14:3> line:10:3 struct definition
    |   |-FieldDecl 0x55bf9d309d68 <line:11:5, col:9> col:9 quarter 'int'
    |   |-FieldDecl 0x55bf9d309dd0 <line:12:5, col:9> col:9 dime 'int'
    |   `-FieldDecl 0x55bf9d309e38 <line:13:5, col:9> col:9 penny 'int'
    `-ReturnStmt 0x55bf9d309ec0 <line:16:3, col:10>
      `-IntegerLiteral 0x55bf9d309ea0 <col:10> 'int' 0

Related to: #140

@leewei05 leewei05 self-assigned this May 10, 2024
@leewei05 leewei05 force-pushed the parse-struct-union branch 2 times, most recently from 04ee10a to cf6a88c Compare May 10, 2024 07:18
@leewei05 leewei05 requested a review from Lai-YT May 10, 2024 07:21
@leewei05 leewei05 force-pushed the parse-struct-union branch from cf6a88c to 3120a7b Compare May 10, 2024 13:58
@leewei05 leewei05 force-pushed the parse-struct-union branch from 3120a7b to fd4fdb2 Compare May 10, 2024 14:02
include/ast.hpp Outdated Show resolved Hide resolved
include/ast.hpp Outdated Show resolved Hide resolved
include/type.hpp Outdated Show resolved Hide resolved
src/type.cpp Outdated Show resolved Hide resolved
parser.y Outdated Show resolved Hide resolved
parser.y Outdated Show resolved Hide resolved
parser.y Show resolved Hide resolved
parser.y Show resolved Hide resolved
parser.y Outdated Show resolved Hide resolved
src/type.cpp Outdated Show resolved Hide resolved
@leewei05 leewei05 requested a review from Lai-YT May 13, 2024 11:47
Copy link
Collaborator

@Lai-YT Lai-YT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else looks good to me. 🥳

include/type.hpp Outdated Show resolved Hide resolved
@leewei05 leewei05 force-pushed the parse-struct-union branch from 7d06d8a to 60b6f43 Compare May 13, 2024 12:18
@leewei05 leewei05 requested a review from Lai-YT May 13, 2024 12:21
Copy link
Collaborator

@Lai-YT Lai-YT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Looking forward to the support of struct and union! 🚀

@Lai-YT Lai-YT merged commit ef9352a into fruits-lab:main May 13, 2024
4 checks passed
@leewei05 leewei05 deleted the parse-struct-union branch May 13, 2024 12:30
@leewei05 leewei05 mentioned this pull request May 27, 2024
13 tasks
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 this pull request may close these issues.

2 participants