You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Summary
Added support for static and extern storage class specifiers across the compiler pipeline (lexer, parser, semantic analysis, IR, and code generation).
Introduced a scoped symbol table with linkage and storage duration tracking, replacing the previous flat symbol handling. A GlobalSymbolTable keeps global data for
functions and static variables, while local scopes track automatic-storage variables.
Implemented C linkage resolution rules: external vs. internal linkage, tentative definitions, and redeclaration merging at file scope.
Handled static local variables with unique name mangling to allow different functions to declare static variables with the same name without collisions.
Key changes
Lexer: Added static and extern keyword tokens.
Parser: Extended declaration parsing to consume optional storage class specifiers and propagate them to AST nodes (VarDeclaration, FunctionDeclaration).
AST: Added StorageClass enum, storage class and unique-name fields on declarations, and Linkage/ScopeType/InitialValue enums for semantic attributes.
Sema (Scope & Symbol Table): Created SymbolEntry with variant attributes (FunAttr, StaticAttr, LocalAttr). Implemented linkage conflict detection, file-scope
variable merging, and static-local variable renaming.
IR & CodeGen: Updated IR generation and x64 backend to emit static variables in the data/bss segment with correct visibility (global vs. local linkage).
Diagnostics: Added new error messages for conflicting linkage, duplicate definitions, and invalid storage class usage (e.g. static/extern in for-loop init).
Test plan
All existing Chapter 1-9 test suites continue to pass.