Skip to content

Attributes and Directives

DQ has declaration attributes written with [[...]] and source directives written with #.

Attributes

Attributes can appear before a declaration or after the declaration item, depending on the declaration kind.

[[external]] function printf(fmt : ^cchar, ...) -> int

function printf(fmt : ^cchar, ...) -> int [[external('printf')]]

Multiple attributes can be written in one list.

function Run() [[virtual, abstract]]

Common Attributes

Attribute Use
[[external]] Link a function or global variable to an external symbol
[[external('name')]] Link to a specific external symbol name
[[overload]] Mark a function, method, or constructor as overloaded
[[virtual]] Mark an object method as virtual
[[override]] Mark an object method as overriding a base virtual method
[[abstract]] Mark a virtual method as abstract
[[final]] Mark a method or virtual slot as final
[[packed]] Request packed aggregate layout
[[align(n)]] Request alignment
[[volatile]] Mark low-level volatile storage/access where supported
[[cexport]] Export a symbol using C-compatible linkage where supported
[[nowarn]] Suppress warnings for the declaration where supported

Unsupported or inapplicable attributes may be ignored with a compiler warning.

External Attribute

[[external]] without an argument uses the DQ declaration name as the external symbol name.

[[external]] function puts(s : ^cchar) -> int

Use an argument when the external symbol name differs.

[[external('fprintf')]] function c_fprintf(stream : pointer, fmt : ^cchar, ...) -> int

External global variables are supported.

var libc_stdout : pointer [[external('stdout')]]

Preprocessor Symbols

#define defines a preprocessor symbol.

#define DEBUG
#define BUFFER_SIZE = 4096

Preprocessor symbols can be read through @def.

var size : int = @def.BUFFER_SIZE

DQ does not provide C-style textual macro expansion.

Conditional Compilation

Conditional directives include:

#if CONDITION
#ifdef SYMBOL
#ifndef SYMBOL
#elif CONDITION
#elifdef SYMBOL
#elifndef SYMBOL
#else
#endif

Example:

#ifdef DEBUG
    const LOGGING : bool = true
#else
    const LOGGING : bool = false
#endif

Directive blocks can also be written inline with #{...}.

var value : int = #{ifdef FAST} 1 #{else} 2 #{endif}

Include

Source include directives are supported.

#include "file.dqi"
#include 'file.dqi'

Include files are processed by the source feeder before parsing the resulting DQ source.

#linklib requests linking with an external library.

#linklib('z')

function zlibVersion() -> ^cchar  [[external]]

The exact linker behavior depends on the target platform and compiler driver.

Directive Style

Directives start with # and are part of the DQ source feeder layer. They are not general-purpose textual macros. Prefer DQ constants, functions, and modules for normal program structure.