Skip to content

Commit ea88406

Browse files
committed
Implement ObsoleteCallingConventionInspection.
1 parent 0398307 commit ea88406

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Antlr4.Runtime;
7+
using Rubberduck.Inspections.Abstract;
8+
using Rubberduck.Inspections.Concrete;
9+
using Rubberduck.Inspections.Results;
10+
using Rubberduck.Parsing;
11+
using Rubberduck.Parsing.Grammar;
12+
using Rubberduck.Parsing.Inspections.Abstract;
13+
using Rubberduck.Parsing.VBA;
14+
using Rubberduck.Resources.Inspections;
15+
using Rubberduck.VBEditor;
16+
17+
namespace Rubberduck.Inspections.Inspections.Concrete
18+
{
19+
public sealed class ObsoleteCallingConventionInspection : ParseTreeInspectionBase
20+
{
21+
public ObsoleteCallingConventionInspection(RubberduckParserState state)
22+
: base(state)
23+
{
24+
Listener = new ObsoleteCallingConventionListener();
25+
}
26+
27+
public override IInspectionListener Listener { get; }
28+
29+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
30+
{
31+
return Listener.Contexts
32+
.Where(context => ((VBAParser.DeclareStmtContext) context.Context).CDECL() != null &&
33+
!IsIgnoringInspectionResultFor(context.ModuleName, context.Context.Start.Line))
34+
.Select(context => new QualifiedContextInspectionResult(this,
35+
string.Format(InspectionResults.ObsoleteCallingConventionInspection,
36+
((VBAParser.DeclareStmtContext) context.Context).identifier().GetText()), context));
37+
}
38+
39+
public class ObsoleteCallingConventionListener : VBAParserBaseListener, IInspectionListener
40+
{
41+
private readonly List<QualifiedContext<ParserRuleContext>> _contexts = new List<QualifiedContext<ParserRuleContext>>();
42+
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
43+
44+
public QualifiedModuleName CurrentModuleName { get; set; }
45+
46+
public void ClearContexts()
47+
{
48+
_contexts.Clear();
49+
}
50+
51+
public override void ExitDeclareStmt(VBAParser.DeclareStmtContext context)
52+
{
53+
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context));
54+
base.ExitDeclareStmt(context);
55+
}
56+
}
57+
}
58+
}

Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Inspections\Concrete\EmptyForLoopBlockInspection.cs" />
8080
<Compile Include="Inspections\Concrete\BooleanAssignedInIfElseInspection.cs" />
8181
<Compile Include="Inspections\Concrete\EmptyWhileWendBlockInspection.cs" />
82+
<Compile Include="Inspections\Concrete\ObsoleteCallingConventionInspection.cs" />
8283
<Compile Include="Inspections\Concrete\ObsoleteErrorSyntaxInspection.cs" />
8384
<Compile Include="Inspections\Concrete\ObsoleteMemberUsageInspection.cs" />
8485
<Compile Include="Inspections\Concrete\SheetAccessedUsingStringInspection.cs" />

Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionInfo.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,7 @@ If the parameter can be null, ignore this inspection result; passing a null valu
331331
<data name="ObsoleteMemberUsageInspection" xml:space="preserve">
332332
<value>This member is marked '@Obsolete'. It should no longer be used, there should be a better alternative.</value>
333333
</data>
334+
<data name="ObsoleteCallingConventionInspection" xml:space="preserve">
335+
<value>Windows implementations of Visual Basic only support the StdCall calling convention, and use of of the CDecl calling convention is only supported in Macintosh versions of VBA. Use of this keyword in Windows will result in runtime error 49 - 'Bad DLL calling convention'. If this procedure is only intended to be used on Macintosh hosts, it should be conditionally compiled.</value>
336+
</data>
334337
</root>

Rubberduck.Resources/Inspections/InspectionNames.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionNames.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,7 @@
330330
<data name="ObsoleteMemberUsageInspection" xml:space="preserve">
331331
<value>Member marked as '@Obsolete' is used</value>
332332
</data>
333+
<data name="ObsoleteCallingConventionInspection" xml:space="preserve">
334+
<value>Use of obsolete 'CDecl' calling convention</value>
335+
</data>
333336
</root>

Rubberduck.Resources/Inspections/InspectionResults.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionResults.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,8 @@
353353
<value>Consider replacing the call to '{0}'. {1}</value>
354354
<comment>{1} Replacement documentation</comment>
355355
</data>
356+
<data name="ObsoleteCallingConventionInspection" xml:space="preserve">
357+
<value>'{0}' is declared using the obsolete 'CDecl' calling convention.</value>
358+
<comment>{0} Procedure name</comment>
359+
</data>
356360
</root>

0 commit comments

Comments
 (0)