-
Notifications
You must be signed in to change notification settings - Fork 55
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
Issue 375 add support for any type #380
Conversation
935691c
to
8f03a6b
Compare
Codecov Report
@@ Coverage Diff @@
## master #380 +/- ##
==========================================
+ Coverage 92.89% 93.01% +0.12%
==========================================
Files 31 31
Lines 10470 10924 +454
==========================================
+ Hits 9726 10161 +435
- Misses 744 763 +19
Continue to review full report at Codecov.
|
src/ast.rs
Outdated
GenericType { | ||
name: String, | ||
generic_symbol: String, | ||
nature: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this be usefull as an enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the 'nature' field? So we could limit it to only possible ANY_XXX type natures? I think that might be good yes. I think once we're in OOP territory we are just working with interfaces / derived types anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry yes, I'm talking about the nature. I thought it would be highlighted when i mark it when commenting
Avoid generating generic methods Actidate codegen tests for generics
478a704
to
c51bfa3
Compare
|
||
pub fn pre_process(unit: &mut CompilationUnit) { | ||
//process all local variables from POUs | ||
for mut pou in unit.units.iter_mut() { | ||
//Find all generic types in that pou |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we put this into it's own function?. It kindo'f disturbs the level of detail of the rest of this function
src/index/visitor.rs
Outdated
name: enum_name.to_string(), | ||
initial_value: init, | ||
information, | ||
nature: TypeNature::Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is enum really ANY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have type casting for ENUM -> DINT? If yes they could be Signed otherwise we have to assume any or live with conversion issues if you call a generic ANY_INT method with an enum
src/index/visitor.rs
Outdated
name: name.to_string(), | ||
initial_value: init, | ||
information, | ||
nature: TypeNature::Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is subrange really any? It should be at least something numeric? no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subrange will / should never be queried directly, and at this stage I don't know the subtype of it, I could however in the least assume an Int nature so I'll change to that
src/lexer/tokens.rs
Outdated
@@ -362,6 +362,9 @@ pub enum Token { | |||
#[regex("[a-zA-Z_][a-zA-Z_0-9]*#")] | |||
TypeCastPrefix, | |||
|
|||
#[regex("ANY(?:_(DERIVED|ELEMENTARY|MAGNITUDE|NUM|REAL|INT|SIGNED|UNSIGNED|DURATION|BIT|CHARS|STRING|CHAR|DATE)+)?", super::parse_type_nature)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's ok for me, although I would also not mind to not make them keywords, but to look for an identifier and check in the parser (so syntactical validation) that this a valid nature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can indeed delegate to the parser, in which case we expect something like an Identifie and we manually check the possible types and create the nature
I'll delay this to the end though, i'm prioritizing the other issues first
@@ -35,6 +42,95 @@ pub enum DirectAccessType { | |||
DWord, | |||
} | |||
|
|||
#[derive(Debug, PartialEq, Clone, Copy)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i find it a bit surprising, that typeNatures are note defined in typesystem.rs
I guess you want to avoid the dependency from AST -> typesystem?
src/resolver.rs
Outdated
/// It collects all candidates for a generic function | ||
/// Then chooses the best fitting function signature | ||
/// And reannotates the function with the found information | ||
fn update_generic_information( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename this to: update_generic_call_statement
src/resolver.rs
Outdated
fn update_generic_information( | ||
&mut self, | ||
generics_candidates: HashMap<&str, Vec<&str>>, | ||
operator_qualifier: &str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operator_qualifier
gives me a hard time. as far as I can see, we don't really use this a qualifier somewhere here?
is this the implementation_name maybe?
src/resolver.rs
Outdated
fn update_generic_function_parameters( | ||
&mut self, | ||
s: &AstStatement, | ||
operator_qualifier: &str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operator_qualifier
is this the function's name?
src/resolver.rs
Outdated
); | ||
self.annotation_map.add_generic_nature(p, *nature); | ||
//If assginment, annotate the left side with the new type | ||
if let AstStatement::Assignment { left, right, .. } = p { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually the annotator does not annotate the assignment itself. semantically it is not correct that a := b
reuslts in a's type - it results in void. there are languages that work like that, but so far rusty's ST-flavor does not.
3 lines above we annotated p, although it is an assignment.
i think we should only do this if it is not an Assignment. (so maybe just into an else-clause)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
} | ||
|
||
#[test] | ||
fn test_external_function_called() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cool!
added additional tests that test if generic function parameters can be provided in an arbitrary order: it should make no difference if you write foo(a := x, b := y); or foo(b := y, a := x); for a foo<T, V>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 again, cool feature and nice implementation!
Generics/ANY type support:
Generics can be defined on functions
Functions with generics will be resolved to typed functions during the call
External declaration for typed functions are added
Generics implementation will be ignored in this commit.