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: add support for inline variable declaration #991

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ghaith
Copy link
Collaborator

@ghaith ghaith commented Oct 18, 2023

Variables can be defined in the body using the syntax

{def} VAR y : DINT := 0; (*Pragma to avoid confusion with var blocks *)
(*Pragma is optional once in body*)
VAR x := 0; (*Implicit type declaration to DINT*)
FOR VAR x := 0 TO 10 BEGIN
(*Implicit variable declaration as loop counter*)
END_FOR

Ref: #973

@ghaith ghaith linked an issue Oct 18, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Attention: Patch coverage is 84.66899% with 44 lines in your changes are missing coverage. Please review.

Project coverage is 95.74%. Comparing base (f58a57f) to head (6dd7ed9).

❗ Current head 6dd7ed9 differs from pull request most recent head b9a62a7. Consider uploading reports for the commit b9a62a7 to get more accurate results

Files Patch % Lines
src/resolver.rs 84.33% 26 Missing ⚠️
src/index/scoped_index.rs 53.57% 13 Missing ⚠️
src/index/symbol.rs 0.00% 3 Missing ⚠️
compiler/plc_ast/src/ast.rs 95.65% 1 Missing ⚠️
src/index.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #991      +/-   ##
==========================================
- Coverage   95.75%   95.74%   -0.02%     
==========================================
  Files         147      154       +7     
  Lines       43119    42607     -512     
==========================================
- Hits        41290    40792     -498     
+ Misses       1829     1815      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ghaith ghaith force-pushed the 973-add-support-for-inline-declared-variables branch 3 times, most recently from 661776f to 6dd7ed9 Compare October 25, 2023 09:01
GitExample and others added 2 commits November 10, 2023 11:08
Variables can be defined in the body using the syntax
```st
{def} VAR y : DINT := 0; (*Pragma to avoid confusion with var blocks *)
(*Pragma is optional once in body*)
VAR x := 0; (*Implicit type declaration to DINT*)
FOR VAR x := 0 TO 10 BEGIN
(*Implicit variable declaration as loop counter*)
END_FOR
```

Ref: #973
The scoped index contains new variables and datatypes that could later
be merged into the main index.

Any ast statetment that could declare new variables or represents a
scope is marked with a new scope.
Further statements would inherit this scope to see new variables.
TODO: Going out of scope would merge the new variables with unique names
back into the index.

Co-authored-by: Michael <[email protected]>
@ghaith ghaith force-pushed the 973-add-support-for-inline-declared-variables branch from 6dd7ed9 to a13aeca Compare November 10, 2023 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for inline-declared variables
1 participant