liveBook · Manning

Attribute dependency

As explained in Building User-Friendly DSLs

An attribute dependency is a relationship in which initializing one attribute requires the initialization of another attribute first.

An attribute dependency exists when initializing one attribute requires another attribute to be initialized first. Write a dependent attribute before its dependency as a1 → a2; generate a2 before a1. section 9.3.4

Use dependency relationships to order generated initialization code:

  • Represent each attribute by its definition index and connect dependent attributes to the attributes they reference. section 9.3.4
  • Follow dependency chains such as 4 → 2, then emit initialization for attribute 2 before attribute 4. section 9.3.4

Out-of-order generated fields

Generated code such as attribute1 = this.attribute2 followed by attribute2 = 42 initializes fields in the wrong order. Reordering the generated assignments resolves the dependency: initialize attribute2 first, then attribute1. section 9.3.4

How Building User-Friendly DSLs covers it

How deep it goes
Implements AST dependency extraction and recursive topological ordering from shorthand relations.
Examples
Uses Rental attributes, the relation 4 → 2, and generated assignments for attribute1 and attribute2.
What it assumes
Assumes attributes have initial values represented as AST objects and may contain attribute references.
What you can do after
Builds dependency extraction and initialization ordering for generated record classes.
How it connects
Connects attribute references, abstract syntax trees, generated code, and topological sorting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.