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

Constants validation (fb instances not allowed #295, scoped const expressions #292) #306

Merged

Conversation

riederm
Copy link
Collaborator

@riederm riederm commented Sep 25, 2021

  1. fb-instances and class-instances cannot be declared
    as constants.

the implementation does not allow to declare a const
of type FB or Class, an array of FBs or Classes
or a struct that contains a field of type FB or
Class.

Furthermore the DataTypeInformation::Struct now contains
a new field: 'source' that indicates where this struct
comes from. It is either an original Declaration
(TYPE x : STRUCT ... END_TYPE) or it was generated
from a POU(PouType). With this field it is now very
easy to see what a DataType offers (is it an FB or Class,
can I call it, etc.)

closes #295

  1. add scope to unresolved const expressions
the additional scope parameter in const_evaluator::evaluate(...)
helps the evaluator to distinguish between global constants and
POU-local ones. When resolving const expressions the given
scope will be used to resolve references.

therefore every ConstExpression holds an optional scope when it
is registered (see enum ConstExpression).

closes #292

@codecov
Copy link

codecov bot commented Sep 25, 2021

Codecov Report

Merging #306 (a369de0) into master (5f2dbcd) will decrease coverage by 0.08%.
The diff coverage is 86.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
- Coverage   95.01%   94.92%   -0.09%     
==========================================
  Files          45       45              
  Lines       12928    13034     +106     
==========================================
+ Hits        12283    12372      +89     
- Misses        645      662      +17     
Impacted Files Coverage Δ
src/validation/variable_validator.rs 89.24% <65.30%> (-10.76%) ⬇️
src/index.rs 92.40% <90.00%> (+0.04%) ⬆️
src/index/const_expressions.rs 94.95% <94.11%> (+1.01%) ⬆️
src/codegen/generators/struct_generator.rs 88.52% <100.00%> (+0.09%) ⬆️
src/index/visitor.rs 96.14% <100.00%> (+0.20%) ⬆️
src/lib.rs 97.33% <100.00%> (+0.04%) ⬆️
src/resolver/const_evaluator.rs 89.53% <100.00%> (+0.19%) ⬆️
src/typesystem.rs 97.01% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f2dbcd...a369de0. Read the comment docs.

fb-instances and class-instances cannot be declared
as constants.

the implementation does not allow to declare a const
of type FB or Class, an array of FBs or Classes
or a struct that contains a field of type FB or
Class.

Furthermore the DataTypeInformation::Struct now contains
a new field: 'source' that indicates where this struct
comes from. It is either an original Declaration
(TYPE x : STRUCT ... END_TYPE) or it was generated
from a POU(PouType). With this field it is now very
easy to see what a DataType offers (is it an FB or Class,
can I call it, etc.)

closes #295
@riederm riederm force-pushed the constants_validation_fb_instances_not_allowed__issue295 branch from aa74c49 to 229c253 Compare September 26, 2021 08:37
@riederm riederm requested a review from ghaith September 26, 2021 08:38
the additional scope parameter in const_evaluator::evaluate(...)
helps the evaluator to distinguish between global constants and
POU-local ones. When resolving const expressions the given
scope will be used to resolve references.

therefore every ConstExpression holds an optional scope when it
is registered (see enum ConstExpression).

closes #292
@riederm riederm changed the title Constants validation fb instances not allowed issue295 Constants validation (fb instances not allowed #295, scoped const expressions #292) Sep 26, 2021
@riederm riederm force-pushed the constants_validation_fb_instances_not_allowed__issue295 branch from 980c504 to a369de0 Compare September 26, 2021 19:10
@riederm riederm self-assigned this Sep 26, 2021
@riederm riederm added this to the oscat milestone Sep 26, 2021
@riederm riederm merged commit 2f3d14f into master Sep 27, 2021
@riederm riederm deleted the constants_validation_fb_instances_not_allowed__issue295 branch September 27, 2021 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
2 participants