D language debugging, version control and static assertion

xiaoxiao2021-03-06  41

Debug, version control, and static assertion D Support from the same set of code to build multiple versions and various debug levels, the method is to use the following characteristics:

Debug instructions

Commissioning feature

Staff

Version description

Version feature

Version statement

Static assertion

Debugspecification

Debugattribute

DebugStatement

VersionSpecification

Versionattribute

VersionStatement

Staticassert

The predefined version is in order to improve the consistency of the usage, and D predefined several versions of the namespace and the marker namespace. The version flag does not conflict with other flags in the code, which is located in a separate namespace. The predefined version of the flag is globally, that is, they can be used for all compiled and imported modules.

Digitalmars

Digital Mars is a compiler provider

X86

Intel and AMD 32 BIT processors

AMD64

AMD 64 BIT processor

Windows

Microsoft Windows System

Win32

Microsoft 32 Bit Windows System

Win64

Microsoft 64 Bit Windows System

linux

All Linux systems

Littlendian

Word order, low priority

BigenDian

Word sequence, high priority

D_inlineasm

Realized the inline assembly

None

Undefined; used to disable a piece of code

If a new implementation occurs, you may join a new meaningful version of the flag.

D language is inevitable over time. Therefore, the namespace consisting of the version of the "D_" header is retained as a name space as a logo of D language specification or new feature.

The version number of the compiler provider can be a predefined, form is after the provider logo, plus version number, such as: Version (DigitalMars_Funky_extension) // DigitalMars interesting {...}

Be sure to use the correct version number for the right purpose. For example, the identifier of the provider is used when using a provider's feature; the flag of the operating system is used when using the feature specific to the operating system, and the like.

Description

Debug instructions

Debug = flag;

DEBUG = integer;

Version description

Version = Identifier;

Version = integer;

Debugspecification

Debug = Identifier;

Debug = integer;

VersionSpecification

Version = Identifier;

Version = integer;

Version instructions do not declare symbols, but set a compiling version, with command line options

-Version's functionality is the same. Version Description Use to support compilation with version feature and version statements.

Version Description and Debug Description For the modules they are located. Only predefined instructions are located in the global scope, and they are specified by the command line option.

Version instructions can be scored in a direct manner to a group, for example:

Version (Professional)

{

Version = featurea;

Version = Featureb;

Version = featurec;

}

Version (HomeEdition)

{

Version = featurea;

}

...

Version (Featureb)

{

... Realize Feature B ...

}

The debug statement usually developers will build two programs, a release, a debug version. The debug version typically includes additional error detection code, test suite, friendly output code, and so on. The statement of the debug statement is compiled with condition. This is the #1fdef debug / #ndif debug / #ndif. Commissioning statement:

Commissioning predicate statement

Debug predicate statement ELSE statement

Debug predicate

Debug statement

Debug (integer)

Debug (Mark)

DebugStatement:

Debugpredicate Statement

Debugpredicate Statement Else Statement

Debugpredicate

Debug Statement

Debug (Integer)

Debug (Identifier)

If the -debug option is specified, the debug statement is compiled into the executable.

If the N <= integer in the -debug (n) option specified, the DEBUG (integer) statement is compiled into the executable.

If the flag in the -debug (flag) option is compiled, you will compile the Debug in the executable.

If the statement is a statement block, the statement block does not introduce a new scope. E.g:

INT K;

Debug

{INT I;

INT K; / / error, K has been defined

i = 3;

}

x = i; // Use the i above

The version statement uses a source code to generate a variety of different versions is a common practice. Although d can be controlled by placing different versions in different modules, if only a few lines of code or the entire program is a module, this is very annoying.

Version statement:

Version predicate statement

Version predicate statement ELSE statement

Version predicate

Version (integer)

Version (marker)

VersionStatement:

VersionPredicate Statement

VersionPredicate Statement Else Statement

VersionPredicate

Version (Integer)

Version (Identifier)

According to the specified

Integer or

Signature, adopted

Version statement. Both forms pass compilers

The -version option specifies. in case

The statement is a statement block, then each statement block does not introduce a new scope, for example:

INT K;

Version (DEMO) // Presentation This piece of code will be used

{INT I;

INT K; / / error, K has been defined

i = 3;

}

x = i; // Use the i above

The version statement can also be selected by version feature. (Translation: Version = DEMO; pointing out using a demo version.)

The version statement can be nested.

If all version predicates are false, use optional else clauses (translation: if any):

Version (x86)

{

... // Realize the customized inline assembly version

}

Else

{

... // Use the default, inefficient version

}

Although debugging and version statements are on the surface, they are used for different purposes. The debug statement is used to add debugging code that should not appear in the release. The version statement is used to enhance portability and provide a variety of distributions.

Commissioning feature

Commissioning characteristics:

Debug

Debug (integer)

Debug (Mark)

Debugattribute:

Debug

Debug (Integer)

Debug (Identifier)

People usually build two versions of programs, a release, a debug version of the debug version including additional error check code, test code, aesthetic print code, etc. You can choose whether to use debug code at compile: Class Foo

{

INT A, B;

Debug:

Int flag;

}

The meaning of the condition is that if the code is not adopted, it still needs syntax, but does not perform semantic inspection or processing. Do not add symbols to the symbol table without performing type checking, no code is generated, and imports will not be performed. You can build different versions by assigning different parameters to debug:

Debug (n) {} // If the debug level <= n is used this code

DEBUG (Mark) {} // If the debug keyword is the flag, use this code.

This is equivalent to using command line parameters

-debug = n and

-debug = flag.

Version feature

Version characteristics:

Version (integer)

Version (marker)

VersionaTribute:

Version (Integer)

Version (Identifier)

Version feature is very similar to the debug feature and overlap each other in many respects. But their purpose is not the same. The debug feature is used to build a debug version of the program, and the version feature uses the same source code to generate multiple release versions.

For example, a program may have two versions, a full version (FULL), a demo (DEMO):

Class foo

{

INT A, B;

Version (Full)

{

Int extrafunctionality ()

{

...

Return 1; // Support additional features

}

}

Else // demo

{

Int extrafunctionality ()

{

Return 0; // Does not support additional functionality

}

}

}

Different versions can be built by specifying different parameters to Version:

Version (n) {} // If version level> = n is used this code

Version (Mark) {} // If the version keyword is the flag, use this code.

This is equivalent to using command line parameters

-version = n and

-version = flag.

Static assertion

Static assertion:

static assert;

Staticassert:

Static Assert (Expression);

The expression will be calculated at compile time and convert to a Boolean value. If it is true, it is ignored static assertions. If it is false, the compile will fail and give an error diagnosis.

Unlike the assertion expression, static assertions will always be calculated by the compiler unless they appear in a debugging or version statement that is not specified.

Void foo ()

{

IF (0)

{

askERT (0); // Never execute

static assert (0); // always executed

}

Version (bar)

{

Static assert (0); // Only defined BAR will not execute

}

}

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

New Post(0)