C# Class LeMP.StandardMacros

Show file Open project: qwertie/ecsharp Class Usage Examples

Public Methods

Method Description
IsExpressionContext ( IMacroContext ctx ) : bool
IsExpressionContext ( LNode parent, int index ) : bool
KeyNameComponentOf ( LNode name ) : Symbol

Retrieves the "key" name component for the nameof(...) macro.

The key name component of global::Foo!int.Bar!T(x) (in C# notation global::Foo<int>.Bar<T>(x)) is Bar. This example tree has the structure ((((global::Foo)!int).Bar)!T)(x)).

MaybeRemoveNoOpFromRunSeq ( VList runSeq ) : VList
NextStatementMayBeReachable ( LNode stmt ) : bool

Given a statement, this method attempts to decide if the immediately following statement (if any) is reachable.

The goal of this code is to avoid the dreaded compiler warning "Unreachable code detected". This is just a heuristic since we don't have access to proper reachability analysis. In fact, it's no doubt buggy.

NextTempName ( IMacroContext ctx, LNode value ) : Symbol
NextTempName ( IMacroContext ctx, string prefix = "tmp_" ) : Symbol
Replace ( LNode stmt, LNode>.Pair patterns, int &replacementCount ) : LNode
Replace ( VList stmts, LNode>.Pair patterns, int &replacementCount ) : VList

Searches a list of expressions/statements for one or more patterns, and performs replacements.

LNodeExt.MatchesPattern is used for matching.

ReplaceCaptures ( LNode outputSpec, LNode>.MMap captures ) : LNode

Finds capture variables like $x and replaces them with values from captures (e.g. captures[(Symbol)"x"] for $x)

UseSymbolsCore ( VList symbolAttrs, VList options, VList body, IMacroContext context, bool inType ) : LNode
unroll ( LNode var, VList cases, LNode body, IMessageSink sink ) : LNode

Protected Methods

Method Description
LooksLikeSimpleValue ( LNode value ) : bool
MaybeAddTempVarDecl ( IMacroContext ctx, LNode value, WList output ) : LNode

Private Methods

Method Description
@unless ( LNode node, IMessageSink sink ) : LNode
AddCsLineDirectives ( LNode node, IMacroContext context ) : LNode
AddLineDirectives ( VList nodes, bool stmtContext, int &sourceLine_ ) : VList
AlgebraicDataType ( LNode classDecl, IMacroContext context ) : LNode
AutoStripBraces ( LNode node ) : LNode
BackingField ( LNode prop, IMessageSink sink ) : LNode
ChooseArgName ( Symbol fieldName ) : Symbol
ChooseFieldName ( Symbol propName ) : Symbol
ColonEquals ( LNode node, IMessageSink sink ) : LNode
DSOCM_DistributeAttributes ( VList attrs, LNode &newArg, LNode &propOrFieldDecl ) : void
DetectMissingVoidReturn ( IMacroContext context, LNode lastStmt ) : bool
DetectSetOrCreateMember ( LNode arg, Symbol &relevantAttribute, Symbol &fieldName, Symbol &paramName, LNode &newArg, LNode &propOrFieldDecl ) : bool
DoDeconstruct ( LNode arg, IMacroContext context, bool printErrorOnFailure ) : void
DollarSignIdentity ( LNode node, IMacroContext context ) : LNode
DollarSignVariable ( LNode node, IMacroContext context ) : LNode
GetAssertMethod ( IMacroContext context ) : LNode
GetCases ( VList body, IMessageSink sink ) : VList>>.VList

Given the contents of case statement like `matchCode` or `switch`, this method gets a list of the cases.

GetFnAndClassName ( IMacroContext context, LNode &@class, LNode &fn ) : Symbol
GetFnAndClassNameString ( IMacroContext context ) : string
GetNamespaces ( LNode multiName ) : IEnumerable
In ( LNode node, IMacroContext context ) : LNode
IsCaseLabel ( LNode @case ) : bool
IsDefaultLabel ( LNode stmt ) : bool
IsVar ( LNode arg, LNode &type, Symbol &name, LNode &defaultValue ) : bool
MaybeInitTupleMakers ( object>.IDictionary properties ) : LNode>>.IList
MergeIdentifiers ( LNode left, LNode right ) : LNode
Namespace ( LNode node, IMacroContext context ) : LNode
NullCoalesceSet ( LNode node, IMessageSink sink ) : LNode
QuickBind ( LNode node, IMessageSink sink ) : LNode
RangeExcl ( LNode node, IMacroContext context ) : LNode
RangeIncl ( LNode node, IMacroContext context ) : LNode
ReduceBooleanExpr ( LNode node ) : LNode
Reject ( IMessageSink sink, LNode at, string msg ) : LNode
ReplaceAt ( bool &modified, TokenTree &tokens, int i, Token newToken ) : void
ReplaceInTokenTree ( TokenTree &tokens, InternalList Replacements ) : bool

Replaces Ids with Ids or Literals in token trees.

ScanForVariables ( LNode code ) : LNode>.Dictionary
SetOrCreateMember ( LNode fn, IMessageSink sink ) : LNode
SetSyntaxVariables ( LNode>.IDictionary captures, IMacroContext context ) : void
StaticIf ( LNode @if, IMacroContext context ) : LNode
TempVarDecl ( IMacroContext ctx, LNode value, LNode &tmpVarName ) : LNode
TempVarDecl ( IMacroContext ctx, LNode value, LNode &tmpVarName, string prefix ) : LNode
TransformOnCatch ( LNode node, LNode firstArg, LNode rest, LNode on_handler ) : LNode
TryReplaceHere ( LNode node, LNode pattern, LNode replacement, LNode>.MMap captures, LNode>.Pair allPatterns ) : LNode
TryReplaceHere ( LNode node, LNode>.Pair patterns, LNode>.MMap temp ) : LNode
Tuple ( LNode node, IMacroContext context ) : LNode
TupleType ( LNode node, IMacroContext context ) : LNode
UnpackTuple ( LNode node, IMacroContext context ) : LNode
UsingMulti ( LNode stmt, IMacroContext context ) : LNode
ValidateOnStmt ( LNode node, IMacroContext context, VList &restOfStmts, LNode &firstArg ) : LNode
WarnAboutMissingDollarSigns ( LNode argList, IMacroContext context, LNode pattern, LNode replacement ) : void
_assert ( LNode node, IMacroContext context ) : LNode
concatId ( LNode node, IMessageSink sink ) : LNode
ecs ( LNode node, IMacroContext context ) : LNode
includeFile ( LNode node, IMacroContext context ) : LNode
includeFileBinary ( LNode node, IMacroContext context ) : LNode
includeFileText ( LNode node, IMacroContext context ) : LNode
match ( LNode node, IMacroContext context ) : LNode
matchCode ( LNode node, IMacroContext context ) : LNode
on_finally ( LNode node, IMacroContext context ) : LNode
on_return ( LNode node, IMacroContext context ) : LNode
on_throw ( LNode node, IMacroContext context ) : LNode
on_throw_catch ( LNode node, IMacroContext context ) : LNode
replace ( LNode node, IMacroContext context ) : LNode
replaceFn ( LNode node, IMacroContext context1 ) : LNode
runSequence ( LNode node, IMacroContext context ) : LNode
saveAndRestore ( LNode node, IMacroContext context ) : LNode
scope ( LNode node, IMacroContext context ) : LNode
setTupleType ( LNode node, IMacroContext context ) : LNode
staticMatches ( LNode node, IMacroContext context ) : LNode
static_deconstruct ( LNode node, IMacroContext context ) : LNode
static_if ( LNode @if, IMacroContext context ) : LNode
static_matchCode ( LNode node, IMacroContext context ) : LNode
static_tryDeconstruct ( LNode node, IMacroContext context ) : LNode
stringify ( LNode node, IMacroContext context ) : LNode
treeEquals ( LNode node, IMacroContext context ) : LNode
unroll ( LNode node, IMacroContext context ) : LNode
useDefaultTupleTypes ( LNode node, IMacroContext context ) : LNode
useSequenceExpressions ( LNode node, IMacroContext context ) : LNode
useSymbols ( LNode input, IMacroContext context ) : LNode
with ( LNode fn, IMacroContext context ) : LNode

Method Details

IsExpressionContext() public static method

public static IsExpressionContext ( IMacroContext ctx ) : bool
ctx IMacroContext
return bool

IsExpressionContext() public static method

public static IsExpressionContext ( LNode parent, int index ) : bool
parent LNode
index int
return bool

KeyNameComponentOf() public static method

Retrieves the "key" name component for the nameof(...) macro.
The key name component of global::Foo!int.Bar!T(x) (in C# notation global::Foo<int>.Bar<T>(x)) is Bar. This example tree has the structure ((((global::Foo)!int).Bar)!T)(x)).
public static KeyNameComponentOf ( LNode name ) : Symbol
name LNode
return Symbol

LooksLikeSimpleValue() protected static method

protected static LooksLikeSimpleValue ( LNode value ) : bool
value LNode
return bool

MaybeAddTempVarDecl() protected static method

protected static MaybeAddTempVarDecl ( IMacroContext ctx, LNode value, WList output ) : LNode
ctx IMacroContext
value LNode
output WList
return LNode

MaybeRemoveNoOpFromRunSeq() public static method

public static MaybeRemoveNoOpFromRunSeq ( VList runSeq ) : VList
runSeq VList
return VList

NextStatementMayBeReachable() public static method

Given a statement, this method attempts to decide if the immediately following statement (if any) is reachable.
The goal of this code is to avoid the dreaded compiler warning "Unreachable code detected". This is just a heuristic since we don't have access to proper reachability analysis. In fact, it's no doubt buggy.
public static NextStatementMayBeReachable ( LNode stmt ) : bool
stmt LNode
return bool

NextTempName() public static method

public static NextTempName ( IMacroContext ctx, LNode value ) : Symbol
ctx IMacroContext
value LNode
return Symbol

NextTempName() public static method

public static NextTempName ( IMacroContext ctx, string prefix = "tmp_" ) : Symbol
ctx IMacroContext
prefix string
return Symbol

Replace() public static method

public static Replace ( LNode stmt, LNode>.Pair patterns, int &replacementCount ) : LNode
stmt LNode
patterns LNode>.Pair
replacementCount int
return LNode

Replace() public static method

Searches a list of expressions/statements for one or more patterns, and performs replacements.
LNodeExt.MatchesPattern is used for matching.
public static Replace ( VList stmts, LNode>.Pair patterns, int &replacementCount ) : VList
stmts VList A list of expressions/statements in which to search.
patterns LNode>.Pair Each pair consists of (A) something to search /// for and (B) a replacement expression. Part A can use the substitution /// operator with an identifier inside (e.g. $Foo) to "capture" any /// subexpression, and part B can use the same substitution (e.g. $Foo) /// to insert the captured subexpression(s) into the output.
replacementCount int Number of replacements that occurred.
return VList

ReplaceCaptures() public static method

Finds capture variables like $x and replaces them with values from captures (e.g. captures[(Symbol)"x"] for $x)
public static ReplaceCaptures ( LNode outputSpec, LNode>.MMap captures ) : LNode
outputSpec LNode
captures LNode>.MMap
return LNode

UseSymbolsCore() public static method

public static UseSymbolsCore ( VList symbolAttrs, VList options, VList body, IMacroContext context, bool inType ) : LNode
symbolAttrs VList
options VList
body VList
context IMacroContext
inType bool
return LNode

unroll() public static method

public static unroll ( LNode var, VList cases, LNode body, IMessageSink sink ) : LNode
var LNode
cases VList
body LNode
sink IMessageSink
return LNode