AutoIt 表达式检查器(Au3Check)

Syntax checks the complete language.
Checks all symbols used:

Usage of non-defined macros are reported as errors.

Au3Check issues warning if variables are used before they are declared.
It is possible that the program is still correct, like the following:

For $i = 1 To 2
    If $i = 2 Then MsgBox(0, "OK", $sHello)
    Global $sHello = "Goodbye"
Next

However, this is bad programming style, and Au3Check will issue a warning that $hello is possibly used before it is declared.
Likewise, Global variables should never be declared within functions and always declared at the top of the script.
If one is used higher up in the code, a warning is issued.
Finally, Au3Check issues an error if a variable is used but is never either explicitly or implicitly declared.

Functions may be defined later than where they are called. Au3Check checks that all functions are called with the correct number of parameters.
It also checks that ByRef parameters are called with variables (not l-values, expressions).
Finally, non-defined functions are reported.

Specific directives can be included in the script to manage some warnings/errors that can not be avoided.

Directives
--------------

#ignorefunc funcname [, ...]

Can be used inside functions, like the following:

#ignoreFunc PluginFunc1
Local $hWnd = PluginOpen("example.dll")
PluginFunc1(0.1, 0.2) ; Will call the user defined function "PluginFunc1" with 2 parameters
PluginClose($hWnd)


#forceref $varname [, ...]

Can be used inside functions, like the following:

Func Test_NumParams($v1 = 0, $v2 = 0, $v3 = 0, $v4 = 0, $v5 = 0, $v6 = 0, $v7 = 0, $v8 = 0, $v9 = 0)
    #forceref $v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9

    Local $iVal = 0

    For $i = 1 To @NumParams
        $iVal &= Eval("v" & $i) & " "
    Next
    MsgBox(0, "@NumParams example", "@NumParams = " & @NumParams & @CRLF & @CRLF & $iVal)
EndFunc   ;==>Test_NumParams


#forcedef $varname [, ...]

can be used after Assign() functions, like the following:

Local $n = Assign("y", 3)
#forcedef $y
$n = $y ;===> $y = 3


This command line utility can be invoked though an editor add-on. It is located in the same directory as AutoIt3.exe.
The SciTE4AutoIt3 editor provides such an environment.

Usage
--------

Au3Check [-q] [-d] [-w[-] n]... [-v[-] n]... [-I dir]... file.au3

-q : quiet (only error/warn output)
-d : as Opt("MustDeclareVars", 1)
-w 1: already included file (on)
-w 2: missing #comments-end (on)
-w 3: already declared var (off)
-w 4: local var used in global scope (off)
-w 5: local var declared but not used (off)
-w 6: warn when using Dim (off)
-w 7: warn when passing Const or expression on ByRef param(s) (on)
-I dir: additional directories for searching include files

-v 1: show include paths/files (off)
-v 2: show lexer tokens (off)
-v 3: show unreferenced UDFs and global variables (off)
Exit codes:
0: success: no errors or warnings
1: warning(s) only
2: syntax error(s)
3: usage or input error

What is not checked
--------------------------
Basically runtime information:
- No checks are made for array dimensions or indices. This can only be done during runtime.
- Logical errors, illegal parameters to functions and division by zero.