Global Declarations
A Larol program is composed of global declarations, each of which is either a
- function,
- structure,
- enumeration,
- namespace, or
- define.
A program is a sequence of top-level global declarations; see the complete grammar.
Names
Each global declaration has a namespace-qualified name, which must be unique; in cases where qualified names are not unique, a fatal error is produced.
Names must be unique between all global declarations, not only declarations of the same kind (function, structure, etc).
Global declarations' names are composed of the unqualified identifier token they were declared with, qualified with the qualified name of any directly enclosing namespace. The identifier token used for a declaration's name is the first identifier token in the declaration, unless otherwise stated.
See namespaces.
Declaration Resolution Order
Global declarations' lexical order is semantically meaningless.
Some global declarations depend on other global declarations: a dependency edge exists from a global declaration D to a global declaration R when resolving D requires R to be fully resolved. A dependency edge exists when:
D's definition contains a raw reference to the type declared byR. A raw reference is any use of a type which requires its layout: structure fields, enumeration variant payloads, function parameter and return types, construction operands, and type positions within a function or define's expression, other than as a handle or slice pointee.D's definition referencesRby value;Ris a define, structure, or enumeration declaration. A reference which resolves to a function value creates no edge, whetherRis a function declaration or a define bound to a function; see the first exception below.
A dependency edge does not exist when:
D's definition referencesRas a function value, whetherRis a function declaration or a define whose value is a function; a reference to a function value requires only its signature, never its completeness.D's definition referencesRonly as a handle or slice pointee; a pointer's layout is independent of its pointee, and only that the pointee is runtime representable is required.D's definition referencesRonly as a namespace or a namespace path element; names are available lexically.
In particular, references to function values, whether to a function declaration or a define bound to a function, and references to handle/slice pointees never create dependency edges, so recursion through function references and through handles or slices is not cyclic.
Global declarations are arranged in a directed acyclic graph (DAG) where vertices represent global declarations and edges point to dependent global declarations. If declarations do not conform to such a graph, a fatal error is produced.
Dependency cycles between global declarations cause a fatal error; compilation cannot continue as the graph must be topologically orderable. For example, a structure directly embedding itself causes a cycle, and must be embedded indirectly through a handle or slice instead.
The global declaration directed acyclic graph is topologically ordered; dependencies are resolved before dependent global declarations.
Symbol Resolution
All global declarations' names resolve to a value whose type is dependent on the declaration kind, when referenced by a reference expression.
Each global declaration's page in this document describes what the declared name will resolve to when referenced (under the 'resultant symbol' subheading).
Syntax
global_declaration = function_declaration | structure_declaration | enumeration_declaration | namespace_declaration | define_declaration ;