@@ -44,98 +44,88 @@ public override void EnterModuleVariableStmt(VBAParser.ModuleVariableStmtContext
44
44
45
45
public override void EnterSubStmt ( VBAParser . SubStmtContext context )
46
46
{
47
+ var attributeScope = ( Identifier . GetName ( context . subroutineName ( ) ) , DeclarationType . Procedure ) ;
48
+ PushNewScope ( attributeScope ) ;
49
+ _membersAllowingAttributes [ attributeScope ] = context ;
50
+ }
51
+
52
+ private void PushNewScope ( ( string scopeIdentifier , DeclarationType scopeType ) attributeScope )
53
+ {
54
+ _currentScope = attributeScope ;
47
55
_currentScopeAttributes = new Attributes ( ) ;
48
- _currentScope = ( Identifier . GetName ( context . subroutineName ( ) ) , DeclarationType . Procedure ) ;
49
- _membersAllowingAttributes [ _currentScope ] = context ;
50
56
}
51
57
52
58
public override void ExitSubStmt ( VBAParser . SubStmtContext context )
53
59
{
54
- if ( _currentScopeAttributes . Any ( ) )
60
+ SaveCurrentScopeAttributes ( context ) ;
61
+ PopScope ( ) ;
62
+ }
63
+
64
+ private void SaveCurrentScopeAttributes ( IAnnotatedContext context )
65
+ {
66
+ if ( _currentScopeAttributes . Any ( ) )
55
67
{
56
68
_attributes . Add ( _currentScope , _currentScopeAttributes ) ;
57
69
context . AddAttributes ( _currentScopeAttributes ) ;
58
70
}
59
-
60
- ResetScope ( ) ;
61
71
}
62
72
63
- private void ResetScope ( )
73
+ private void PopScope ( )
64
74
{
65
75
_currentScope = _moduleScope ;
66
76
_currentScopeAttributes = null ;
67
77
}
68
78
69
79
public override void EnterFunctionStmt ( VBAParser . FunctionStmtContext context )
70
80
{
71
- _currentScopeAttributes = new Attributes ( ) ;
72
- _currentScope = ( Identifier . GetName ( context . functionName ( ) ) , DeclarationType . Function ) ;
73
- _membersAllowingAttributes [ _currentScope ] = context ;
81
+ var attributeScope = ( Identifier . GetName ( context . functionName ( ) ) , DeclarationType . Function ) ;
82
+ PushNewScope ( attributeScope ) ;
83
+ _membersAllowingAttributes [ attributeScope ] = context ;
74
84
}
75
85
76
86
public override void ExitFunctionStmt ( VBAParser . FunctionStmtContext context )
77
87
{
78
- if ( _currentScopeAttributes . Any ( ) )
79
- {
80
- _attributes . Add ( _currentScope , _currentScopeAttributes ) ;
81
- context . AddAttributes ( _currentScopeAttributes ) ;
82
- }
83
-
84
- ResetScope ( ) ;
88
+ SaveCurrentScopeAttributes ( context ) ;
89
+ PopScope ( ) ;
85
90
}
86
91
87
92
public override void EnterPropertyGetStmt ( VBAParser . PropertyGetStmtContext context )
88
93
{
89
- _currentScopeAttributes = new Attributes ( ) ;
90
- _currentScope = ( Identifier . GetName ( context . functionName ( ) ) , DeclarationType . PropertyGet ) ;
91
- _membersAllowingAttributes [ _currentScope ] = context ;
94
+ var attributeScope = ( Identifier . GetName ( context . functionName ( ) ) , DeclarationType . PropertyGet ) ;
95
+ PushNewScope ( attributeScope ) ;
96
+ _membersAllowingAttributes [ attributeScope ] = context ;
92
97
}
93
98
94
99
public override void ExitPropertyGetStmt ( VBAParser . PropertyGetStmtContext context )
95
100
{
96
- if ( _currentScopeAttributes . Any ( ) )
97
- {
98
- _attributes . Add ( _currentScope , _currentScopeAttributes ) ;
99
- context . AddAttributes ( _currentScopeAttributes ) ;
100
- }
101
-
102
- ResetScope ( ) ;
101
+ SaveCurrentScopeAttributes ( context ) ;
102
+ PopScope ( ) ;
103
103
}
104
104
105
105
public override void EnterPropertyLetStmt ( VBAParser . PropertyLetStmtContext context )
106
106
{
107
- _currentScopeAttributes = new Attributes ( ) ;
108
- _currentScope = ( Identifier . GetName ( context . subroutineName ( ) ) , DeclarationType . PropertyLet ) ;
109
- _membersAllowingAttributes [ _currentScope ] = context ;
107
+ var attributeScope = ( Identifier . GetName ( context . subroutineName ( ) ) , DeclarationType . PropertyLet ) ;
108
+ PushNewScope ( attributeScope ) ;
109
+ _membersAllowingAttributes [ attributeScope ] = context ;
110
110
}
111
111
112
112
public override void ExitPropertyLetStmt ( VBAParser . PropertyLetStmtContext context )
113
113
{
114
- if ( _currentScopeAttributes . Any ( ) )
115
- {
116
- _attributes . Add ( _currentScope , _currentScopeAttributes ) ;
117
- context . AddAttributes ( _currentScopeAttributes ) ;
118
- }
119
-
120
- ResetScope ( ) ;
114
+ SaveCurrentScopeAttributes ( context ) ;
115
+ PopScope ( ) ;
121
116
}
122
117
123
118
public override void EnterPropertySetStmt ( VBAParser . PropertySetStmtContext context )
124
119
{
125
- _currentScopeAttributes = new Attributes ( ) ;
126
- _currentScope = ( Identifier . GetName ( context . subroutineName ( ) ) , DeclarationType . PropertySet ) ;
127
- _membersAllowingAttributes [ _currentScope ] = context ;
120
+ var attributeScope = ( Identifier . GetName ( context . subroutineName ( ) ) , DeclarationType . PropertySet ) ;
121
+ PushNewScope ( attributeScope ) ;
122
+ _membersAllowingAttributes [ attributeScope ] = context ;
128
123
}
129
124
130
125
public override void ExitPropertySetStmt ( VBAParser . PropertySetStmtContext context )
131
126
{
132
- if ( _currentScopeAttributes . Any ( ) )
133
- {
134
- _attributes . Add ( _currentScope , _currentScopeAttributes ) ;
135
- context . AddAttributes ( _currentScopeAttributes ) ;
136
- }
137
-
138
- ResetScope ( ) ;
127
+ SaveCurrentScopeAttributes ( context ) ;
128
+ PopScope ( ) ;
139
129
}
140
130
141
131
public override void ExitAttributeStmt ( VBAParser . AttributeStmtContext context )
0 commit comments