Module in D Language (Module)

xiaoxiao2021-03-06  39

Module

Module:

Module declarations multiple declaration definitions

Multiple declaration definitions

Multiple declaration definitions:

Declare definition

Disclaimer definitions multiple declaration definitions

Disclaimer definition:

Feature indicator

Import declaration

Enumeration statement

Class declaration

Interface declaration

Gather

statement

Constructor

Destructor

Invillate

unit test

Static constructor

Static destructor

Debug specification

Version specification

;

Module:

Moduledeclaration Decldefs

Decldefs

Decldefs:

Decldef

Decldef Decldefs

Decldef:

AttributeSpecifier

ImportDeclaration

ENUMDECLATION

ClassDeclaration

InterfaceDeclaration

AggregatedEclaration

Declaration

Constructor

Destructor

Invariant

UnitTest

StaticConstructor

StaticDestructor

Debugspecification

VersionSpecification

;

Module homologous files are one or one. The module name is the file name of the path and extension.

The module automatically provides a namespace for its content. The module has a little bit like class, the difference is:

Each module has only one instance and it is static allocation. The module has no virtual functions. Modules cannot inherit, they do not have parent modules, and so on. There is only one module each file. The symbol of the module can be imported. The module is always compiled in the global scope and is not affected by the surrounding features or other modifiers. Multiple modules can be organized into a structure called

Package.

Module declaration

The module declaration specifies the name of the module and the package it belongs. If not specified, the module name will be set to the file name of the path and the extension.

Module declaration:

Module module name;

Module Name:

Marker

Module name. Signature

MODULEDECLATION:

Module modulename;

Modulename:

Identifier

Modulename. Identifier

Rightmost

The flag is in the module

Package. The package corresponds to the directory name in the source file path.

If there is, the module declaration is in the beginning of the source file according to the syntax, and each source file can only be one.

Example:

Module C.STDIO; // This is the STDIO module in the C package

According to the practice, the package and module name are lowercase. This is because the package and module name correspond to the directory name and file name in the operating system, and many file systems are not case sensitive. Captify all packets and module names will reduce the problem when migrating projects between different file systems.

The import declaration is different from the textual contained file, and D is imported directly into the symbol through the Import declaration:

Import declaration:

IMPORT module list;

Module name list:

Module name

Module name, module name list

ImportDeclaration:

Import modulenamelist;

ModulenameList:

Modulename

Modulename, ModulenameList

Rightmost

The flag is a module name. The uppermost scope in the module will merge with the current scope.

Example:

Import std.c.stdio; // Import the STDIO module from the C package

Import foo, bar; // Import foo and bar modules

Schemes and modules have their own namespaces each module. When a module is imported into another module, the default behavior is that all of its top layer declaration is valid in the current module. The ambiguous two can be illegal, and the method can be resolved by explicitly referenced by the module name.

For example, it is assumed to have the following modules:

Module foo

INT x = 1;

INT Y = 2;

Module Bar

INT Y = 3; int Z = 4;

then:

IMPORT FOO;

...

Q = Y; // Set Q is equal to foo.y

and:

IMPORT FOO;

INT Y = 5;

Q = Y; // The local Y covers foo.y

as well as:

IMPORT FOO;

IMPORT BAR;

Q = Y; / / error: foo.y or bar.y?

and also:

IMPORT FOO;

IMPORT BAR;

Q = bar.y; // q set to 3

If the import is private, for example:

Module ABC;

PRIVATE IMPORT DEF;

Then be other modules import

Will not search when ABC

DEF.

The module scope operator is sometimes necessary to rewrite the usual word method for the domain rules to access the name that is covered by the local name. You can use global scope operators '.' To reach this, the global operator is before the flag:

INT X;

Int foo (int x)

{

IF (y)

Return X; // Return FOO.x, not the overall X

Else

Return .x; // Return to the overall X

}

The preamble '.' Means looking for the name in the module scope level.

Static constructors and destructive static constructors are code used to run initialization modules or classes before main (). The static destructor is the code that is executed after main () returns, usually used to release system resources.

The order of sequential static initialization of static construction is implicitly within the module

The order of importing declaration is determined. Each module will call its own static constructor after it is dependent on the module. In addition to this rule, the order in which the module static constructor is executed is uncertain.

The loop (loop dependence) in the import declaration is allowed, as long as the two modules contain a static constructor or a destructive function. If this rule will generate an exception at runtime.

The sequence of static configurations in a module is inside the module, and the static configuration will be performed in the order of the words they appear.

The sequential sequential sequential sequential sequential sequential sequential sequential sequence will be performed in the reverse of the constructor. The static destructor is performed only when the static constructor of the module is successfully executed.

转载请注明原文地址:https://www.9cbs.com/read-59926.html

New Post(0)