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

feat: Validation of AST #26

Merged
merged 14 commits into from
Sep 22, 2024
Merged

feat: Validation of AST #26

merged 14 commits into from
Sep 22, 2024

Conversation

Gashmob
Copy link
Member

@Gashmob Gashmob commented Aug 23, 2024

Closes #25

@Gashmob Gashmob added the enhancement New feature or request label Aug 23, 2024
@Gashmob Gashmob added this to the v0.1.0 milestone Aug 23, 2024
@Gashmob Gashmob self-assigned this Aug 23, 2024
@Gashmob Gashmob linked an issue Aug 23, 2024 that may be closed by this pull request
Part of #25

This validator does nothing for now, it just throw for each expression.
@Gashmob Gashmob force-pushed the 25-validation-of-ast branch from 419ecfc to 9bec4f7 Compare August 23, 2024 16:23
Gashmob added 13 commits August 28, 2024 18:30
Part of #25

It will be used to store context of ValidationVisitor easily. Instead of
creating a new member each time, just store it directly in the context.

The stack/unstack allow to have a different context if we need it
Part of #25

It will help to show understandable message
Part of #25

It helps to format message shown to user
Part of #25

Show a warning if value not used
Part of #25

Instead of using a pointer to parent, use std::stack of map.

There is at least one map in the stack (unstack cannot pop last map).
Part of #25

It set type of expressions (just literals for now) and check that last
expression is an int (return type of program)
Part of #25

- Check constant has a value
- Check declared type (if exists)
- Check assigned value (if exists)
  - Check assigned value == declared type (if exists)
- Check existence of at least type or value
Part of #25

- check name exists
Part of #25

- check name exists
- check it's not a constant
- check type equality
Part of #25

- check left operand
- check right operand
- check calcul can be done between types

Also add early return when type given by sub-expression is nullptr: it
means there is an error, so no need to go further in this expression
Part of #25

It ease the dump of types when it's aliased types
Part of 25

This public method tells if there was an error during validation. To do
so it just checks if a call to displayError was made (if so it means
there was an error). displayWarning is not considered as an error
Part of #25

All cases are covered (at least all I can think of)
@Gashmob Gashmob merged commit bf116c0 into master Sep 22, 2024
13 checks passed
@Gashmob Gashmob deleted the 25-validation-of-ast branch September 22, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation of AST
1 participant