Can I add my own syntax check rules?

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?

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

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.

ok. can you give me an example?

@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?

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.

No possibility for static code analysis?

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

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

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).

1 Like

see my reply here Oxfuscator

1 Like