Project 7 - Second Milestone (Const Statement)#12
Open
EGmux wants to merge 16 commits into
Open
Conversation
- Introduced `const_statement` to parse local constant declarations in function bodies. - Updated the `statement` function to include `const_statement` in its parsing order. - Enhanced documentation to reflect the new constant declaration feature.
- tests increase in complexity - each test modify "knobs" to control complexity such as the ammount of expressions and the allowed nested level Note: The following C features are NOT covered by these tests: - Pointer types (T*, &, *) - Struct/union types and members - Array types and indexing - Function pointers - Type qualifiers (volatile, restrict) - Storage class specifiers (static, extern, register) - Multiple declarators (int x = 1, y = 2) - Designated initializers - Compound literals - Cast expressions - sizeof expressions - Enum constants - Bitfields - Inline assembly - Preprocessor directives - _Generic, _Alignas, _Static_assert (C11/C23 features)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Milestone 2 Progress Report: Global Constants Implementation
Enzo Gurgel Bissoli
Shellyda de Fatima Silva Barbosa
Rodrigo Santos Batista
Juliana Serafim da Silva
Anderson Vitor Leoncio de Lima
The type checking and semantic analysis layers for global constants are fully implemented and verified. The type checker successfully compiles, validates type safety, and passes all target environment verification suites inside
tests/constant_declaration.rscleanly.What We Had (The Problems)
Initially, the type checker suffered from a scope-isolation issue when dealing with global constants:
type_check_fun_decl) uses an environment snapshotting mechanism (env.restore(fn_snapshot.clone())) to isolate a function's local variables.type_check, the taken snapshot (fn_snapshot) only captured function signatures.mainbegan type checking, the environment was restored to this bare snapshot, wiping out any trace of global constants and causing compiler panics for anundeclared variable(e.g.,MAX_SIZE,PI).What We Did (The Solutions)
To preserve the strict, pre-existing API interfaces enforced by the project architecture (ensuring
type_check_fun_decl(f, &mut env, &fn_snapshot)remained entirely unchanged), we re-engineered the environment setup sequence insidesrc/semantic/type_checker.rs.We established a strict top-down layout before capturing the environment state:
type_checkto processprogram.constantsfirst. It validates each constant's type alignment, checks the initializer expression against the current type context, ensures novoidtypes are declared, and catches variable redeclarations.let fn_snapshot = env.snapshot();.Why This Fixes the Architecture
Because the global constants are registered before the snapshot is captured, they are natively baked directly into the
fn_snapshotmap. When individual function scopes later restore their local environments using this snapshot, the global constants safely persist and remain visible across all functions, sub-blocks, and expressions.Current State of the Type Checker
void), catches type mismatches between the constant definition and its initializer expression, and safely prevents global variable redeclarations.proptestthat involve mutating operations on raw literal values—such as++(++155...)—are limited by the structural constraints of the parser definition, which remains locked and separate from this milestone).