Jump to content
Sign in to follow this  
Bomba

Tool: Standalone script compiler/syntax checker for ArmA2

Recommended Posts

Tool: ArmA2 Script Compiler v.0.1 /link/

Home: http://code.google.com/p/arma2warfare/

The solution is designed as standalone script compiler/syntax checker for ArmA2.

This is partial syntax checker, so it not cover checking all function arguments and arguments types;

Allowed file types: .sqf, .fsm

FSM path tracing - all avaible paths routing and script checking.

FSM extract script definition and check it as regular .sqf and check in common context of FSM file;

REQUIREMENTS

------------

Microsoft .NET Framework 3.5

PowerShell 2.0 (required to launch an example)

USAGE

-----

Examine the file sample.ps1, it contains a typical usage: a compilation set of scripts from ArmA2 mission folder

Run the file compile.bat or .\sample.ps1 from PowerShell console

By default will compiled mission scripts from folder sampleMission

warning:

Script sample.ps1 not signed with certificate, so you propably get PowerShell error about restriction to run unsigned scripts.

To resolve this issue, execute follow the command with administrator privileges in powershell console

Set-ExecutionPolicy -ExecutionPolicy ByPass

or sign a file sample.ps1 with your trusted certificate.

CHECKED WARNING AND ERRORS:

---------------------------

* Possible Perfomance Degradade

* Out Of Function Scope Variable Declaration

* Assigment To Reserved Variable Name,

* Not declared as Private Var

* Duplicate declaration as Private Var

* Declared as private but never Used

* Variable used but not have assign prior

* Invalid Array ElementType for some operations

* Command Invalid Argument,

* Missing Separator

* FsmMissedProperty,

* FsmMissedClass,

* FsmInvalidValueType

COMPILE RESULT SAMPLE

------------------------

ArmA2 Script Compiler, Version 0.1

© Evgeny Zyuzin, 2011. All rights reserved

Compile: C:\Users\Administrator\AppData\Local\Temp\_sampleMission.compiled\initJIPCompatible.sqf

warning CS104: PrivateVarUndeclared

Not declared as private: '_u'

At Scope:

if(!isServer || local player)then

{

waitUntil{!isNull(player)};

12452 cutText[(localize 'STR_WF_Loading') + "...", "BLACK FADED", 0]

};

setVi

...

Edited by Bomba

Share this post


Link to post
Share on other sites

Thanks for your work and the release Bomba!

First a few notes:

While in the powershell one can also permit the missing signature for the one file only with:

PowerShell -ExecutionPolicy Bypass -File .\sample.ps1

ref and background:

http://stackoverflow.com/questions/728143/ignore-security-warning-running-script-from-command-line

http://technet.microsoft.com/de-de/library/dd347628.aspx

One can get the powershell 2.0 from here:

http://support.microsoft.com/kb/968929

It ran through scripts of my game mode without issues. Good start.

As for the results, I only got these four types:

  • warning CS103: AssigmentToReserved
  • warning CS104: PrivateVarUndeclared
  • warning CS105: PrivateVarDuplicate
  • warning CS106: PrivateVarUnused

AssigmentToReserved was _x = _x1 - _x2; from one script

In my case it was a none issue, but bad practice nevertheless

PrivateVarUndeclared are warnings of for loop increment variables and from EH scope.

PrivateVarUnused is from checking hpp only (sqf with the hpp include works).

PrivateVarDuplicate are false positives. Some make no sense at all.

Others do not take scope (well enough) into account to judge it right.

sample: http://pastebin.jonasscholz.de/1312

warning CS105: PrivateVarDuplicate
Duplicated '_numberOfGunnerWeapons' in private array
At scope:
{
   private["_numberOfGunnerWeapons"];
   _numberOfGunnerWeapons = count(getArray(configFile / "CfgVehicles" / _vehicleClass / "Turrets" / "MainTu

I am mainly interested in 'Possible Perfomance Degradade'.

Can you please tell us more about this check(s) please.

You should have a look at Squint by Mac. It would be great to see you to

join forces and work together. :)

Share this post


Link to post
Share on other sites

Thx for response,

"Possible Perfomance Degradade" is warning for code with runtime compilation and execute: for sample to follow line warning will be generated.

call/spawn compile format ["_funds = %1;",_itemFunds];

in sample1.ps this warning is disabled

But here not complex analysis, just simple compare with code template match,

so this warning is just flag for check for a performance: because such code can be called once, but in other cases can can be called unlimited times.

for sample in warfareBE mission a lot of code is often compiled on the fly, replacing it with the same static code get increase server performance to 5-10 fps

Share this post


Link to post
Share on other sites

Thanks!

Yep good point. It is a good info to the coder. :)

Share this post


Link to post
Share on other sites

about EH and PrivateVarUndeclared

i think for this code must be warned about undeclared vars

_displayEH_mousezchanged = (finddisplay 46) displayaddeventhandler ["mousezchanged","

_zchange = _this select 1;

_oldAperture = BIS_UAV_PLANE getvariable 'BIS_UAV_aperture';

_zChangeFinal = _zChange / 2;

if (_oldAperture <= 1.0) then {_zChangeFinal = _zChange / 10};

if (_oldAperture <= 0.1) then {_zChangeFinal = _zChange / 1000};

_aperture = _oldAperture + _zchangeFinal;

if (_oldaperture > 1.0 && _aperture < 1.0) then {_aperture = 1.0};

if (_oldaperture > 0.1 && _aperture < 0.1) then {_aperture = 0.1};

if (_aperture < 0.001) then {_aperture = 0.001};

BIS_UAV_PLANE setvariable ['BIS_UAV_aperture',_aperture];

setaperture _aperture;

"];

although perhaps the arma2 script runtime itself is well clear of these variables and not transfer them to the global stack allocated variables. I have not tested this. But think be better raise warn about this. :)

In many scripts I see that for such EH declaration was added private declare.

---------- Post added at 10:31 PM ---------- Previous post was at 10:16 PM ----------

Also I check you sample

sample: http://pastebin.jonasscholz.de/1312

and not receive any warning CS105: PrivateVarDuplicate

just four errors

error CS501: UsedNotAssigned

Variables used, but not have assigned: '_vehicleClass'

can you show completed script where incorrect warning was generated.

Edited by Bomba

Share this post


Link to post
Share on other sites

From ours and Mac's test it does not mix the scope of outside and inside EH definitions.

for "_i" from ..

the _i does not need a private definition either. One may not use _i before and after the loop though too.

The complete script: http://pastebin.jonasscholz.de/1313

(remove the include and the two "string" defines or set #define string)

Share this post


Link to post
Share on other sites

i checked, :(

this is due to the fact that the preprocessor currently are not processed, (actually include script not loaded too), so substitute empty string instead "string", defined in hpp not be executed

so script parsing is failed on:

string _vehicleClass = _this select 0;

string _vehicleType = switch (true) do

and in result have some unintelligible warnings and errors

:(

if remove "strings" and rewrote script to (this do preprocessor)

_vehicleClass = _this select 0;

_vehicleType = switch (true) do

in result no warning and errors.

Share this post


Link to post
Share on other sites

Alright.

While I can understand your interest in your tool very well, you should take a look at squint.

Mac has made a very powerful base there and your skills could make it even better. :)

Share this post


Link to post
Share on other sites

Any plans to expand/update this work? If this was made open source, then it would have great potential to be updated and/or extended for A3 :)

;1864281']Alright.

While I can understand your interest in your tool very well' date=' you should take a look at squint.

Mac has made a very powerful base there and your skills could make it even better. :)[/quote']

I understand that Squint has a lot of credit in the community, and I don't deny that it has a very good error checker. However, I don't like squint very much because of it's limited interface. It's lacking some features that I've grown accustomed to when programming. I'm used to working with IDE's like VS and eclipse. Squint lacks support for planning and teamwork. We're using Mantis and Hg for developing our missions. Using feature branching allows for great flexibility in mission development, so good integration with mercurial really makes my life a lot easier. Same with Mantis for issue tracking. It all just 'beams' into eclipse, without ever leaving the editor.

I'd prefer to have a complete ArmaDEV/ARMAScript based toolchain, but that still needs some work. I think that somehow integrating this compiler into ArmaDEV or eclipse would be a great addition to that toolchain. If I can get the output parsed in eclipse, that is.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×