Your Search Results

    Using Dehydra

    As GCC compiles file, Dehydra calls functions in the user analysis script with information about the code being compiled. For more information, see the function reference and the object reference.

    Example: printing the location of type declarations

    Save the following C++ code

    typedef int MyInt;
    struct Foo { int i; char *c; };

    Save the following analysis script dumptypes.js:

    function process_type(t)
      print("Type found: " + + " location: " + t.loc);
    function input_end()
      print("Hello, world!");

    Compile using the following command:

    $ g++ -fplugin=~/dehydra/ -fplugin-arg=~/dumptypes.js -o/dev/null -c

    Note:for g++4.5 and up

    use -fplugin-arg-gcc_dehydra-script= rather than -fplugin-arg

    It should print the following results:

    Type found: Foo location:
    Type found: MyInt location:
    Hello, world!

    See documentation for: process_type, input_end, print, .loc property

     Example: using attributes to mark a class as "final"

    Save the following code as

    // This class should not be subclassed!
    class __attribute__((user("final"))) MyClass
    // This subclass should be an error
    class SubClass : public MyClass

    Save the following analysis script final.js:

     * 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 ( == '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 " + + " extends final class " +, t.loc);

    Compile using the following command:

    $ g++ -fplugin=~/dehydra/ -fplugin-arg=~/final.js -o/dev/null -c

    It should print the following results and return with an error code: error: class SubClass extends final class MyClass

     See documentation for: process_type, error, .bases property, .attributes property

    Document Tags and Contributors

    Contributors to this page: Sheppy, Tglek, BenjaminSmedberg, thesamprice, Imphil
    Last updated by: Sheppy,
    Hide Sidebar