AutoIt Syntax Checker (Au3Check)
Checks the script for syntax errors.
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's possible that the program is still correct, like the following:
For $i = 1 To 2
If $i = 2 Then MsgBox($MB_OK, "OK", $sHello)
Global $sHello = "Goodbye"
However, this is bad programming style and Au3Check will issue a warning that $sHello 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 initially 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.
These directives prevent Au3Check from reporting errors when the code is correct but too complex for the tool's parser. As shown in the examples below they are usually used when variables are implicitly declared - such as in a function definition or by a string parameter - and would otherwise not be recognised. In particular, #forceref can be used to prevent warnings where parameters are mandatory (such as in Windows message handlers) but are not used inside the function.
#ignorefunc can be used inside functions, like the following:
Local $vCallRet = Call('Not_Defined_Func')
Local $iError = @error
Local $iExtended = @extended
MsgBox($MB_OK, 'Not defined func example', '$vCallRet = ' & $vCallRet & _
' @error = 0x' & Hex($iError) & ' @extended = 0x' & Hex($iExtended) & @CRLF)
#forceref 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) & " "
MsgBox($MB_OK, "@NumParams example", "@NumParams = " & @NumParams & @CRLF & @CRLF & $iVal)
#forcedef can be used after Assign() functions, like the following:
Local $n = Assign("y", 3)
$n = $y ;===> $y = 3
This command line utility can be invoked through an editor add-on. It is located in the same directory as AutoIt3.exe.
The SciTE4AutoIt3 editor provides such an environment.
-q : quiet (only error/warn output)Exit codes:
-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)
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.