-
Notifications
You must be signed in to change notification settings - Fork 48
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
Fix sizeof. Also inlines many sizes variable sizes directly. However,… #79
Conversation
I see that the Parser now indeed uses the Capital case/not to determine it it's a type. There's one corner case I also ran into this issue with the stat() function in libC. There a function stat() and a struct stat. Hmmm.. Why did the following test change: test/Functions/struct_functions/static_member.c2 |
My suggestion was that C structs are imported as _C_<struct_name> into C2 so:
1. struct foo in plain C is imported as _C_foo. This means our naming standard is retained (the _C_ prefix is interpreted an upper case struct)
2. function Foo in plain C is imported as _c_Foo. Again naming standard is retained.
3. Since we disallow _C_ as prefix for C2 structs, this is no issue.
4. This also fixes the problem with function / struct in C that you mention.
The only downside is for C functions that follow the name standard. I suggest that those are imported with prefix, but aliased to their normal name.
So:
C:
1. struct Foo { … }
2. struct bar { … }
3. void Foo( … )
4. void bar( … )
Imported into C2 as:
1. Foo and _C_Foo
2. _C_bar
3. _c_Foo
4. bar and _c_bar
This should resolve all issues.
For the less nice ”_C_bar”, it’s easy to alias it with a good name.
/C
… On 2 Dec 2018, at 12:08, Bas van den Berg ***@***.***> wrote:
I see that the Parser now indeed uses the Capital case/not to determine it it's a type. There's one corner case
here (just impacts other stuff) and that's external C libraries. External C libraries are allowed to have types with lower cased characters. So that's very nasty.
I also ran into this issue with the stat() function in libC. There a function stat() and a struct stat. Hmmm..
What I still have to try is to change struct stat -> struct Stat and use an attribute (c-name='stat'). That way
we can maintain the spelling and keep this code.
Why did the following test change: test/Functions/struct_functions/static_member.c2
The error seemed ok, but now it's 'i32 cannot be assigned to value'
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#79 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AABtVb4vU2Mq0mF0CB0Oz1kJGTAJHTLDks5u07SrgaJpZM4Y89qS>.
|
There are lots of call (most of them) that just fit in. printf, open/close, etc. |
@bvdberg re-read my suggestion. printf would be available as is without change. The prefix is only for the ones not matching our conventions. |
Any other questions on this one @bvdberg ? Next after this is tackling the struct packing / calculations |
… structs are skipped as exact sizes are unclear at this point of time. A bug was found, where – for example – "Foo a = Foo;" is allowed. This requires some extra code to distinguish between typevalues and types of expressions. Since this bug already existed, I did not want to do the extra work in this commit, however, I've updated the expected error.
I removed one diff in indent to make the diff even smaller. Will there be time to merge this? |
Could you please add some tests to show what C-code is generated for the new generator? What I see is that |
At this point, everything except structs will inline the sizes. This was simpler than sending it to C actually. You should have several examples already, but sure, I can add more.
|
I realized you're right, the C-gen was not there. Added now. |
merged after adding some tests and fixing some static struct stuff.. |
Would you mind explaining what you did @bvdberg? Looks like you changed a lot compared to my implementation. |
I did some refactoring indeed. The base was to get the unit test test/Expr/member_expr.c2 running correctly. Most changes have nothing to do with @lerno 's patch, but issues already present.
|
… structs are skipped as exact sizes are unclear at this point of time. A bug was found, where – for example – "Foo a = Foo;" is allowed. This requires some extra code to distinguish between typevalues and types of expressions. Since this bug already existed, I did not want to do the extra work in this commit, however, I've updated the expected error.