Type system plug-ins [Was: Re: Coverity tool]
retard
re at tard.com.invalid
Fri Feb 12 10:57:39 PST 2010
Fri, 12 Feb 2010 12:07:16 -0500, bearophile wrote:
> /**
> * Helper function: returns true if a class is marked with the "final"
> attribute. */
> function isFinal(c) {
> if (!c.attributes)
> return false;
> for each (let a in c.attributes)
> if (a.name == 'user' && a.value == 'final')
> return true;
> return false;
> }
> function process_type(t) {
> if (t.bases)
> for each (let base in t.bases)
> if (isFinal(base.type))
> error("class " + t.name + " extends final class " +
> base.type.name, t.loc);
> }
That kind of code is rather clumsy. Having written couple of toy
languages, I really enjoy expressing the rules as immutable declarative
axioms, e.g.:
final_class_rule: node.metatype == class && node.hasBases ==> !
node.bases.exists(n => n.attributes.contains("final"))
By using declarative notion, the ambiguity of rules can be tested and
rules can be verified more easily.
More information about the Digitalmars-d
mailing list