Skip to content

Commit c343b15

Browse files
authored
Merge pull request #23306 from ntrel/module-decls
[spec/module] Improve docs
2 parents d76d240 + 7f12eb5 commit c343b15

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

spec/declaration.dd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ $(GNAME Declaration):
1414
$(GLINK2 function, FuncDeclaration)
1515
$(GLINK VarDeclarations)
1616
$(GLINK AliasDeclaration)
17-
$(GLINK AliasAssign)
1817
$(GLINK AggregateDeclaration)
1918
$(GLINK2 enum, EnumDeclaration)
2019
$(GLINK2 module, ImportDeclaration)
@@ -26,7 +25,6 @@ $(GNAME Declaration):
2625
$(GLINK2 template-mixin, TemplateMixin)
2726
)
2827

29-
3028
$(H3 $(LNAME2 aggregates, Aggregates))
3129

3230
$(GRAMMAR

spec/module.dd

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,73 @@ $(SPEC_S Modules,
44

55
$(HEADERNAV_TOC)
66

7+
$(H2 $(LNAME2 grammar, Grammar))
8+
79
$(GRAMMAR
810
$(GNAME Module):
911
$(GLINK ModuleDeclaration)
10-
$(GLINK ModuleDeclaration) $(GLINK DeclDefs)
11-
$(GLINK DeclDefs)
12+
$(GLINK ModuleDeclaration)$(OPT) $(GLINK DeclDefs)
1213

1314
$(GNAME DeclDefs):
1415
$(GLINK DeclDef)
1516
$(GLINK DeclDef) $(GSELF DeclDefs)
1617

1718
$(GNAME DeclDef):
1819
$(GLINK2 attribute, AttributeSpecifier)
20+
$(GLINK2 declaration, AliasAssign)
1921
$(GLINK2 declaration, Declaration)
20-
$(GLINK2 class, Constructor)
21-
$(GLINK2 struct, NewDeclaration)
22-
$(GLINK2 class, Destructor)
23-
$(GLINK2 struct, Postblit)
24-
$(GLINK2 class, Invariant)
22+
$(GLINK AggregateMember)
2523
$(GLINK2 unittest, UnitTest)
26-
$(GLINK2 class, AliasThis)
2724
$(GLINK2 class, StaticConstructor)
2825
$(GLINK2 class, StaticDestructor)
2926
$(GLINK2 class, SharedStaticConstructor)
3027
$(GLINK2 class, SharedStaticDestructor)
31-
$(GLINK2 version, ConditionalDeclaration)
3228
$(GLINK2 version, DebugSpecification)
3329
$(GLINK2 version, VersionSpecification)
3430
$(GLINK MixinDeclaration)
3531
$(GLINK EmptyDeclaration)
3632

33+
$(GNAME AggregateMember):
34+
$(GLINK2 class, Constructor)
35+
$(GLINK2 struct, NewDeclaration)
36+
$(GLINK2 class, Destructor)
37+
$(GLINK2 struct, Postblit)
38+
$(GLINK2 class, Invariant)
39+
$(GLINK2 class, AliasThis)
40+
3741
$(GNAME EmptyDeclaration):
3842
$(D ;)
3943
)
4044

45+
$(P A *Module* normally has one or more *DeclDef* declarations.)
46+
47+
- $(GLINK2 declaration, Declaration) is the only *DeclDef* allowed as a
48+
$(GLINK2 statement, Statement) in a function body.
49+
- *DeclDef* is also a member of $(DDSUBLINK spec/declaration, AggregateDeclaration,
50+
aggregate type declarations) and templates.
51+
- *AggregateMember* is only semantically valid as an aggregate type member
52+
(though it is syntactically valid outside of one).
53+
54+
55+
$(H2 $(LNAME2 overview, Overview))
56+
4157
$(P Modules have a one-to-one correspondence with source files. When not
4258
explicitly set via a $(GLINK ModuleDeclaration), a module's name defaults
4359
to the name of the file stripped of its path and extension.)
4460

4561
$(P A module's name automatically acts as a namespace scope for its contents. Modules
46-
superficially resemble classes, but differ in that:)
62+
superficially resemble $(DDLINK spec/struct, Structs and Unions, structs), but differ in that:)
4763

4864
$(UL
4965
$(LI Only one instance of a module exists, and it is
5066
statically allocated.)
5167

52-
$(LI Modules do not have virtual tables.)
53-
54-
$(LI Modules do not inherit, do not have super modules, etc.)
55-
5668
$(LI A source file may contain only one module.)
5769

58-
$(LI Symbols in a module can be imported.)
70+
$(LI Symbols in a module can be $(RELATIVE_LINK2 import-declaration, imported).)
5971

6072
$(LI Modules are always compiled at global scope and are unaffected
61-
by surrounding attributes or other modifiers.)
73+
by storage classes or other modifiers.)
6274
)
6375

6476
$(P Modules can be grouped into hierarchies called $(I packages).)
@@ -181,9 +193,7 @@ import foo; // Deprecated: module foo is deprecated - Please use foo2 instead.
181193
---------
182194

183195
$(IMPLEMENTATION_DEFINED
184-
$(OL
185-
$(LI How the deprecation messages are presented to the user.)
186-
))
196+
How the deprecation messages are presented to the user.)
187197

188198

189199
$(H2 $(LEGACY_LNAME2 ImportDeclaration, import-declaration, Import Declaration))
@@ -230,10 +240,8 @@ qualified with whatever packages they are in. They are not considered to be
230240
relative to the module that imports them.)
231241

232242
$(IMPLEMENTATION_DEFINED
233-
$(OL
234-
$(LI How the compiler resolves the package and module identifiers in an
243+
How the compiler resolves the package and module identifiers in an
235244
import declaration to its corresponding source files.)
236-
))
237245

238246
$(H3 $(LNAME2 name_lookup, Symbol Name Lookup))
239247

0 commit comments

Comments
 (0)