Can I add my own syntax check rules?


(Theo) #1

Because I work a lot with SQL server, my code has a lot of SQL Strings embedded.
To prevent bugs, the variables that are embedded within those strings must be non nullable.
I’d like to write my own check for this, bus has Oxygene some framework available that allows me to do that?


(marc hoffman) #2

I’m not sure if I completely follow. can you give an example? Note that you can use “not nullable” as type prefix to mark parameters and fields as not allowing null, eg:

method foo(aBar: not nullable string);
begin
end;

foo(nil); // compiler error

var x := if a then "foo" else nil;
foo(x); // compiler warning

(Theo) #3

I know how to do it, with non nullable variables, but I am trying to find my own mistakes where I forgot to use it.


(marc hoffman) #4

ok. can you give me an example?


(Theo) #5

@ck: sorry, interpolated string scenario.

@mh:
The code line:
var stmt := "select * from table where value = {myValue}"

In the case that:

  • a string starts with Select or Update or Delete or Insert
  • and myValue is a nullable type,

I want a warning.

Another code line:
var stmt := "delete from table"

In the case that:

  • a string starts with Update or Delete
  • and the string does not contain the word where,

I want also a warning.

And I can think of a lot of other rules I can enforce on my own code, that are specific to my code.
So, not something that you can implement - I have to implement it myself.

The question is: can I implement such rules?


(Carlo Kok) #6

You could use a method aspect to validate a string like that, but you’d have to wrap it in a call:

var stmt := CheckSQL(…);

where CheckSQL would be eliminated by an aspect and checked.


(Theo) #7

No possibility for static code analysis?


(Carlo Kok) #8

We don’t have (outside usable) apis yet that allow you to walk the whole source tree.


(Theo) #9

Can you give me some example code for a method aspect?


(Carlo Kok) #10

I have a string obfuscation attribute which will need todays build; I can show it (but you need the new build for it to work).


(Carlo Kok) #11

see my reply here Oxfuscator