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

fix issue #70 about storage class v2 #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ppci/lang/c/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,21 @@ def check_redeclaration_storage_class(self, sym, declaration):
old_storage_class = sym.declaration.storage_class
new_storage_class = declaration.storage_class
# None == automatic storage class.
invalid_combos = [(None, "static"), ("extern", "static")]
# changes of linkage between internal and external are illegal
Copy link
Owner

Choose a reason for hiding this comment

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

Playing around a bit at this site makes it appear differently, you can declare a function as non-static after first specifying it as static.

invalid_combos = [(None, "static"),
("extern", "static"),
Copy link
Owner

Choose a reason for hiding this comment

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

I changed this code a bit, so that there are booleans checking for previously static or not.

("static", None)]
combo = (old_storage_class, new_storage_class)
if combo in invalid_combos:
message = "Invalid redefine of storage class. Was {}, but now {}".format(
old_storage_class, new_storage_class
)
self.invalid_redeclaration(sym, declaration, message)

if not declaration.storage_class:
if sym.declaration.storage_class:
declaration.storage_class = sym.declaration.storage_class
# if new storage-class is "extern", keep the old storage-class
# otherwise use the new one
if new_storage_class == "extern":
Copy link
Owner

Choose a reason for hiding this comment

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

Rather than changing the storage class, it is probably better to change the position in the Symbol.declarations list of this declaration.

declaration.storage_class = old_storage_class

def invalid_redeclaration(
self, sym, declaration, message="Invalid redefinition"
Expand Down