Skip to content

Commit 38c48ed

Browse files
authored
Merge pull request #2790 from comintern/next
Fixes for wildly promiscuous subclassing, type hinted functions, and Mid statement\function duality.
2 parents fbc21be + f96969d commit 38c48ed

File tree

13 files changed

+3552
-3205
lines changed

13 files changed

+3552
-3205
lines changed

RetailCoder.VBE/Common/WinAPI/User32.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ public static class User32
160160
[DllImport("user32.dll", CharSet = CharSet.Auto)]
161161
internal static extern IntPtr SendMessage(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
162162

163-
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
164-
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
165-
166163
public delegate int WindowEnumProc(IntPtr hwnd, IntPtr lparam);
167164
[DllImport("user32.dll")]
168165
public static extern bool EnumChildWindows(IntPtr hwnd, WindowEnumProc func, IntPtr lParam);

Rubberduck.Parsing/Grammar/Tokens.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public static class Tokens
169169
public static readonly string Step = "Step";
170170
public static readonly string Stop = "Stop";
171171
public static readonly string Str = "Str";
172+
public static readonly string StrConv = "StrConv";
172173
public static readonly string String = "String";
173174
public static readonly string StrPtr = "StrPtr";
174175
public static readonly string Sub = "Sub";

Rubberduck.Parsing/Grammar/VBALexer.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ LENB : L E N B;
5050
LONGLONG : L O N G L O N G;
5151
LONGPTR : L O N G P T R;
5252
MIDB : M I D B;
53-
MIDBTYPESUFFIX : M I D B '$';
54-
MIDTYPESUFFIX : M I D '$';
53+
// MIDBTYPESUFFIX : M I D B '$';
54+
// MIDTYPESUFFIX : M I D '$';
5555
OPTION : O P T I O N;
5656
PSET : P S E T;
5757
SCALE : S C A L E;

Rubberduck.Parsing/Grammar/VBAParser.cs

Lines changed: 3415 additions & 3192 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ redimStmt : REDIM whiteSpace (PRESERVE whiteSpace)? redimDeclarationList;
428428
redimDeclarationList : redimVariableDeclaration (whiteSpace? COMMA whiteSpace? redimVariableDeclaration)*;
429429
redimVariableDeclaration : expression (whiteSpace asTypeClause)?;
430430

431+
// 5.4.3.5 Mid/MidB/Mid$/MidB$ Statement
432+
// This needs to be explicitly defined to distinguish between Mid as a function and Mid as a keyword.
433+
midStatement : modeSpecifier
434+
LPAREN whiteSpace?
435+
lExpression whiteSpace? COMMA whiteSpace? lExpression whiteSpace? (COMMA whiteSpace? lExpression whiteSpace?)?
436+
RPAREN
437+
whiteSpace? ASSIGN whiteSpace?
438+
expression;
439+
modeSpecifier : (MID | MIDB) DOLLAR? ;
440+
431441
integerExpression : expression;
432442

433443
callStmt :
@@ -524,7 +534,7 @@ subscript : (expression whiteSpace TO whiteSpace)? expression;
524534
unrestrictedIdentifier : identifier | statementKeyword | markerKeyword;
525535
identifier : typedIdentifier | untypedIdentifier;
526536
untypedIdentifier : identifierValue;
527-
typedIdentifier : identifierValue typeHint;
537+
typedIdentifier : untypedIdentifier typeHint;
528538
identifierValue : IDENTIFIER | keyword | foreignName | BF;
529539
foreignName : L_SQUARE_BRACKET foreignIdentifier* R_SQUARE_BRACKET;
530540
foreignIdentifier : ~(L_SQUARE_BRACKET | R_SQUARE_BRACKET) | foreignName;
@@ -702,8 +712,8 @@ keyword :
702712
| ME
703713
| MID
704714
| MIDB
705-
| MIDBTYPESUFFIX
706-
| MIDTYPESUFFIX
715+
// | MIDBTYPESUFFIX
716+
// | MIDTYPESUFFIX
707717
| MOD
708718
| NEW
709719
| NOT

Rubberduck.Parsing/Grammar/VBAParserBaseListener.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,19 @@ public virtual void EnterEndOfStatement([NotNull] VBAParser.EndOfStatementContex
501501
/// <param name="context">The parse tree.</param>
502502
public virtual void ExitEndOfStatement([NotNull] VBAParser.EndOfStatementContext context) { }
503503

504+
/// <summary>
505+
/// Enter a parse tree produced by <see cref="VBAParser.midStatement"/>.
506+
/// <para>The default implementation does nothing.</para>
507+
/// </summary>
508+
/// <param name="context">The parse tree.</param>
509+
public virtual void EnterMidStatement([NotNull] VBAParser.MidStatementContext context) { }
510+
/// <summary>
511+
/// Exit a parse tree produced by <see cref="VBAParser.midStatement"/>.
512+
/// <para>The default implementation does nothing.</para>
513+
/// </summary>
514+
/// <param name="context">The parse tree.</param>
515+
public virtual void ExitMidStatement([NotNull] VBAParser.MidStatementContext context) { }
516+
504517
/// <summary>
505518
/// Enter a parse tree produced by <see cref="VBAParser.optionCompareStmt"/>.
506519
/// <para>The default implementation does nothing.</para>
@@ -2997,6 +3010,19 @@ public virtual void EnterCharPosition([NotNull] VBAParser.CharPositionContext co
29973010
/// <param name="context">The parse tree.</param>
29983011
public virtual void ExitCharPosition([NotNull] VBAParser.CharPositionContext context) { }
29993012

3013+
/// <summary>
3014+
/// Enter a parse tree produced by <see cref="VBAParser.modeSpecifier"/>.
3015+
/// <para>The default implementation does nothing.</para>
3016+
/// </summary>
3017+
/// <param name="context">The parse tree.</param>
3018+
public virtual void EnterModeSpecifier([NotNull] VBAParser.ModeSpecifierContext context) { }
3019+
/// <summary>
3020+
/// Exit a parse tree produced by <see cref="VBAParser.modeSpecifier"/>.
3021+
/// <para>The default implementation does nothing.</para>
3022+
/// </summary>
3023+
/// <param name="context">The parse tree.</param>
3024+
public virtual void ExitModeSpecifier([NotNull] VBAParser.ModeSpecifierContext context) { }
3025+
30003026
/// <summary>
30013027
/// Enter a parse tree produced by <see cref="VBAParser.moduleConfigElement"/>.
30023028
/// <para>The default implementation does nothing.</para>

Rubberduck.Parsing/Grammar/VBAParserBaseVisitor.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,17 @@ public partial class VBAParserBaseVisitor<Result> : AbstractParseTreeVisitor<Res
428428
/// <return>The visitor result.</return>
429429
public virtual Result VisitEndOfStatement([NotNull] VBAParser.EndOfStatementContext context) { return VisitChildren(context); }
430430

431+
/// <summary>
432+
/// Visit a parse tree produced by <see cref="VBAParser.midStatement"/>.
433+
/// <para>
434+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
435+
/// on <paramref name="context"/>.
436+
/// </para>
437+
/// </summary>
438+
/// <param name="context">The parse tree.</param>
439+
/// <return>The visitor result.</return>
440+
public virtual Result VisitMidStatement([NotNull] VBAParser.MidStatementContext context) { return VisitChildren(context); }
441+
431442
/// <summary>
432443
/// Visit a parse tree produced by <see cref="VBAParser.optionCompareStmt"/>.
433444
/// <para>
@@ -2540,6 +2551,17 @@ public partial class VBAParserBaseVisitor<Result> : AbstractParseTreeVisitor<Res
25402551
/// <return>The visitor result.</return>
25412552
public virtual Result VisitCharPosition([NotNull] VBAParser.CharPositionContext context) { return VisitChildren(context); }
25422553

2554+
/// <summary>
2555+
/// Visit a parse tree produced by <see cref="VBAParser.modeSpecifier"/>.
2556+
/// <para>
2557+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
2558+
/// on <paramref name="context"/>.
2559+
/// </para>
2560+
/// </summary>
2561+
/// <param name="context">The parse tree.</param>
2562+
/// <return>The visitor result.</return>
2563+
public virtual Result VisitModeSpecifier([NotNull] VBAParser.ModeSpecifierContext context) { return VisitChildren(context); }
2564+
25432565
/// <summary>
25442566
/// Visit a parse tree produced by <see cref="VBAParser.moduleConfigElement"/>.
25452567
/// <para>

Rubberduck.Parsing/Grammar/VBAParserListener.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@ public interface IVBAParserListener : IParseTreeListener {
437437
/// <param name="context">The parse tree.</param>
438438
void ExitEndOfStatement([NotNull] VBAParser.EndOfStatementContext context);
439439

440+
/// <summary>
441+
/// Enter a parse tree produced by <see cref="VBAParser.midStatement"/>.
442+
/// </summary>
443+
/// <param name="context">The parse tree.</param>
444+
void EnterMidStatement([NotNull] VBAParser.MidStatementContext context);
445+
/// <summary>
446+
/// Exit a parse tree produced by <see cref="VBAParser.midStatement"/>.
447+
/// </summary>
448+
/// <param name="context">The parse tree.</param>
449+
void ExitMidStatement([NotNull] VBAParser.MidStatementContext context);
450+
440451
/// <summary>
441452
/// Enter a parse tree produced by the <c>optionCompareStmt</c>
442453
/// labeled alternative in <see cref="VBAParser.moduleOption"/>.
@@ -2611,6 +2622,17 @@ public interface IVBAParserListener : IParseTreeListener {
26112622
/// <param name="context">The parse tree.</param>
26122623
void ExitCharPosition([NotNull] VBAParser.CharPositionContext context);
26132624

2625+
/// <summary>
2626+
/// Enter a parse tree produced by <see cref="VBAParser.modeSpecifier"/>.
2627+
/// </summary>
2628+
/// <param name="context">The parse tree.</param>
2629+
void EnterModeSpecifier([NotNull] VBAParser.ModeSpecifierContext context);
2630+
/// <summary>
2631+
/// Exit a parse tree produced by <see cref="VBAParser.modeSpecifier"/>.
2632+
/// </summary>
2633+
/// <param name="context">The parse tree.</param>
2634+
void ExitModeSpecifier([NotNull] VBAParser.ModeSpecifierContext context);
2635+
26142636
/// <summary>
26152637
/// Enter a parse tree produced by <see cref="VBAParser.moduleConfigElement"/>.
26162638
/// </summary>

Rubberduck.Parsing/Grammar/VBAParserVisitor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ public interface IVBAParserVisitor<Result> : IParseTreeVisitor<Result> {
288288
/// <return>The visitor result.</return>
289289
Result VisitEndOfStatement([NotNull] VBAParser.EndOfStatementContext context);
290290

291+
/// <summary>
292+
/// Visit a parse tree produced by <see cref="VBAParser.midStatement"/>.
293+
/// </summary>
294+
/// <param name="context">The parse tree.</param>
295+
/// <return>The visitor result.</return>
296+
Result VisitMidStatement([NotNull] VBAParser.MidStatementContext context);
297+
291298
/// <summary>
292299
/// Visit a parse tree produced by the <c>optionCompareStmt</c>
293300
/// labeled alternative in <see cref="VBAParser.moduleOption"/>.
@@ -1663,6 +1670,13 @@ public interface IVBAParserVisitor<Result> : IParseTreeVisitor<Result> {
16631670
/// <return>The visitor result.</return>
16641671
Result VisitCharPosition([NotNull] VBAParser.CharPositionContext context);
16651672

1673+
/// <summary>
1674+
/// Visit a parse tree produced by <see cref="VBAParser.modeSpecifier"/>.
1675+
/// </summary>
1676+
/// <param name="context">The parse tree.</param>
1677+
/// <return>The visitor result.</return>
1678+
Result VisitModeSpecifier([NotNull] VBAParser.ModeSpecifierContext context);
1679+
16661680
/// <summary>
16671681
/// Visit a parse tree produced by <see cref="VBAParser.moduleConfigElement"/>.
16681682
/// </summary>

Rubberduck.Parsing/Symbols/DeclarationLoaders/AliasDeclarations.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public IReadOnlyList<Declaration> Load()
3232
Grammar.Tokens.Hex,
3333
Grammar.Tokens.Oct,
3434
Grammar.Tokens.Str,
35+
Grammar.Tokens.StrConv,
3536
Grammar.Tokens.CurDir,
3637
Grammar.Tokens.Command,
3738
Grammar.Tokens.Environ,
@@ -177,6 +178,7 @@ private List<FunctionDeclaration> FunctionAliasesWithoutParameters()
177178
HexFunction(),
178179
OctFunction(),
179180
StrFunction(),
181+
StrConvFunction(),
180182
CurDirFunction(),
181183
CommandFunction(),
182184
EnvironFunction(),
@@ -270,6 +272,24 @@ private FunctionDeclaration StrFunction()
270272
new Attributes());
271273
}
272274

275+
private FunctionDeclaration StrConvFunction()
276+
{
277+
return new FunctionDeclaration(
278+
new QualifiedMemberName(_stringsModule.QualifiedName.QualifiedModuleName, "StrConv"),
279+
_stringsModule,
280+
_stringsModule,
281+
"Variant",
282+
null,
283+
string.Empty,
284+
Accessibility.Global,
285+
null,
286+
new Selection(),
287+
false,
288+
true,
289+
new List<IAnnotation>(),
290+
new Attributes());
291+
}
292+
273293
private FunctionDeclaration CurDirFunction()
274294
{
275295
return new FunctionDeclaration(

0 commit comments

Comments
 (0)