@@ -1637,44 +1637,37 @@ impl<'i> TypeAnnotator<'i> {
1637
1637
fn visit_statement_expression ( & mut self , ctx : & VisitorContext , statement : & AstNode ) {
1638
1638
match statement. get_stmt ( ) {
1639
1639
AstStatement :: This => {
1640
- if let Some ( pou) = ctx. pou . and_then ( |name| self . index . find_pou ( name) ) {
1641
- match pou {
1642
- // TODO: #THIS for functionblock and for method if parent is of type functionblock
1643
- PouIndexEntry :: FunctionBlock { name, .. }
1644
- | PouIndexEntry :: Method { parent_name : name, .. } => {
1645
- if let Some ( parent_name) = self . index . find_pou ( name) {
1646
- match parent_name {
1647
- PouIndexEntry :: FunctionBlock { .. } | PouIndexEntry :: Method { .. } => {
1648
- let ptr_name = format ! ( "{}.__THIS" , name) ;
1649
- if self
1650
- . index
1651
- . find_type ( & ptr_name)
1652
- . or_else ( || self . annotation_map . new_index . find_type ( & ptr_name) )
1653
- . is_none ( )
1654
- {
1655
- let information = DataTypeInformation :: Pointer {
1656
- name : ptr_name. clone ( ) ,
1657
- inner_type_name : name. to_string ( ) ,
1658
- auto_deref : None ,
1659
- } ;
1660
- let dt = crate :: typesystem:: DataType {
1661
- name : ptr_name. clone ( ) ,
1662
- initial_value : None ,
1663
- information,
1664
- nature : TypeNature :: Any ,
1665
- location : SourceLocation :: internal ( ) ,
1666
- } ;
1667
- self . annotation_map . new_index . register_type ( dt) ;
1668
- }
1669
- self . annotate ( statement, StatementAnnotation :: value ( ptr_name) ) ;
1670
- }
1671
- _ => { }
1672
- }
1673
- }
1674
- }
1675
- _ => { }
1640
+ let name = match ctx. pou . and_then ( |name| self . index . find_pou ( name) ) {
1641
+ Some ( PouIndexEntry :: FunctionBlock { name, .. } ) => name,
1642
+ Some ( PouIndexEntry :: Method { parent_name : name, .. } )
1643
+ if self . index . find_pou ( & name) . is_some_and ( |it| it. is_function_block ( ) ) =>
1644
+ {
1645
+ name
1676
1646
}
1647
+ _ => return ,
1648
+ } ;
1649
+ let ptr_name = format ! ( "{}.__THIS" , name) ;
1650
+ if self
1651
+ . index
1652
+ . find_type ( & ptr_name)
1653
+ . or_else ( || self . annotation_map . new_index . find_type ( & ptr_name) )
1654
+ . is_none ( )
1655
+ {
1656
+ let information = DataTypeInformation :: Pointer {
1657
+ name : ptr_name. clone ( ) ,
1658
+ inner_type_name : name. to_string ( ) ,
1659
+ auto_deref : None ,
1660
+ } ;
1661
+ let dt = crate :: typesystem:: DataType {
1662
+ name : ptr_name. clone ( ) ,
1663
+ initial_value : None ,
1664
+ information,
1665
+ nature : TypeNature :: Any ,
1666
+ location : SourceLocation :: internal ( ) ,
1667
+ } ;
1668
+ self . annotation_map . new_index . register_type ( dt) ;
1677
1669
}
1670
+ self . annotate ( statement, StatementAnnotation :: value ( ptr_name) ) ;
1678
1671
}
1679
1672
AstStatement :: DirectAccess ( data, ..) => {
1680
1673
let ctx = VisitorContext { qualifier : None , ..ctx. clone ( ) } ;
@@ -2016,31 +2009,6 @@ impl<'i> TypeAnnotator<'i> {
2016
2009
ctx : & VisitorContext < ' _ > ,
2017
2010
) -> Option < StatementAnnotation > {
2018
2011
match reference. get_stmt ( ) {
2019
- AstStatement :: This => {
2020
- // Only `THIS` in FunctionBlock/methods context
2021
- // TODO: also support methods
2022
- if let Some ( pou) = ctx. pou . and_then ( |name| self . index . find_pou ( name) ) {
2023
- match pou {
2024
- // TODO: #THIS for functionblock and for method if parent is of type functionblock
2025
- PouIndexEntry :: FunctionBlock { name, .. }
2026
- | PouIndexEntry :: Method { parent_name : name, .. } => {
2027
- if let Some ( parent_name) = self . index . find_pou ( name) {
2028
- match parent_name {
2029
- PouIndexEntry :: FunctionBlock { .. } | PouIndexEntry :: Method { .. } => {
2030
- Some ( StatementAnnotation :: value ( name) )
2031
- }
2032
- _ => None ,
2033
- }
2034
- } else {
2035
- None
2036
- }
2037
- }
2038
- _ => None ,
2039
- }
2040
- } else {
2041
- None
2042
- }
2043
- }
2044
2012
AstStatement :: Identifier ( name, ..) => ctx
2045
2013
. resolve_strategy
2046
2014
. iter ( )
0 commit comments