Table of Contents

Class ConditionalCompilationBlocks

Namespace
RDCore.SDK.Semantics
Assembly
RDCore.SDK.dll

The shape of the #If blocks of a module (MS-VBAL §3.4): which source ranges are the branches of one block, whatever they evaluate to.

public sealed class ConditionalCompilationBlocks
Inheritance
ConditionalCompilationBlocks
Inherited Members

Remarks

A name can be declared in each branch of a #If block and be one declaration, whichever branch compiles: the branches are alternatives of one another. A name declared twice in the same branch - or twice with no #If at all - is not an alternative of itself, but a duplicate. Telling them apart takes no constant to be evaluated, only where each branch begins and ends; it is the structure that the evaluation of the constants (PrecompilerLiveBranchEvaluator) then chooses a branch of.

Properties

None

A module with no #If block: nothing is an alternative of anything.

public static ConditionalCompilationBlocks None { get; }

Property Value

ConditionalCompilationBlocks

Methods

AreAlternatives(SourcePosition, SourcePosition)

Whether the declarations at first and second are in different branches of one block, so that at most one of them is ever compiled.

public bool AreAlternatives(SourcePosition first, SourcePosition second)

Parameters

first SourcePosition

Where the first is declared.

second SourcePosition

Where the second is declared.

Returns

bool

BranchCount(int, Func<SourceRange, bool>)

How many branches a block has: its #If, each #ElseIf, and its #Else, whatever they hold, an empty one included. A branch that holds nothing holds no position: BranchesAt(SourcePosition, Func<SourceRange, bool>) gives no ordinal of it.

public int BranchCount(int block, Func<SourceRange, bool> counted)

Parameters

block int

The ordinal of the block, as BranchesAt(SourcePosition, Func<SourceRange, bool>) gives it with the same counted.

counted Func<SourceRange, bool>

Which blocks are counted, as BranchesAt(SourcePosition, Func<SourceRange, bool>) counts them.

Returns

int

Exceptions

ArgumentOutOfRangeException

No counted block has that ordinal.

BranchesAt(SourcePosition, Func<SourceRange, bool>)

The branches that hold what is written at position, the outermost first: for each block that holds it, which block it is and which of its branches. Neither says where the block is written, only how many blocks come before it and how many branches before the one that holds it.

public IReadOnlyList<(int Block, int Branch)> BranchesAt(SourcePosition position, Func<SourceRange, bool> counted)

Parameters

position SourcePosition

Where it is written.

counted Func<SourceRange, bool>

Which blocks are counted, by the range from the start of the first branch to the end of the last: a block that is not counted holds nothing, and is not counted in the ordinal of those after it.

Returns

IReadOnlyList<(int Block, int Branch)>

For each block that holds the position, its ordinal among the blocks counted, in the order they are written, and the ordinal of the branch - the #If, each #ElseIf, then the #Else; nothing when no counted block holds it.

Remarks

Two declarations with the same branches are compiled together, whatever the constants are; a declaration moved into a branch, out of one or to another is compiled when other constants say so (MS-VBAL §3.4).

HasElse(int, Func<SourceRange, bool>)

Whether a block has an #Else branch, so that exactly one of its branches is compiled, whatever the constants are (MS-VBAL §3.4). A block without one compiles none of its branches when no condition is true.

public bool HasElse(int block, Func<SourceRange, bool> counted)

Parameters

block int

The ordinal of the block, as BranchesAt(SourcePosition, Func<SourceRange, bool>) gives it with the same counted.

counted Func<SourceRange, bool>

Which blocks are counted, as BranchesAt(SourcePosition, Func<SourceRange, bool>) counts them.

Returns

bool

Exceptions

ArgumentOutOfRangeException

No counted block has that ordinal.

IsConditional(SourcePosition)

Whether what is written at position is in a branch of a block, and so compiled only when that branch is live.

public bool IsConditional(SourcePosition position)

Parameters

position SourcePosition

Where it is written.

Returns

bool

Of(ImmutableArray<SyntaxNode>)

The blocks of a module, read off its precompiler trivia, nested ones included.

public static ConditionalCompilationBlocks Of(ImmutableArray<SyntaxNode> precompilerTrivia)

Parameters

precompilerTrivia ImmutableArray<SyntaxNode>

The module's ModuleParseResult.PrecompilerTrivia.

Returns

ConditionalCompilationBlocks