本文整理汇总了C#中ExpressionStatement.SetContainingBlock方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatement.SetContainingBlock方法的具体用法?C# ExpressionStatement.SetContainingBlock怎么用?C# ExpressionStatement.SetContainingBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionStatement
的用法示例。
在下文中一共展示了ExpressionStatement.SetContainingBlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddInitializationTo
protected static void AddInitializationTo(ICollection<Statement> statements, Expression source, Expression target, TypeExpression targetType, BlockStatement containingBlock)
{
VccInitializer initializer = source as VccInitializer;
if (initializer != null) {
VccArrayTypeExpression arrayType = initializer.arrayTypeExpression ?? targetType as VccArrayTypeExpression;
if (arrayType != null) {
initializer.AddInitializingElementAssignmentsTo(statements, target, arrayType);
} else if (initializer.IsOfStructuredType) {
VccStructuredTypeDeclaration structType = initializer.GetStructuredTypeDecl();
if (structType != null) initializer.AddInitializingFieldAssignmentsTo(statements, target, structType);
}
} else {
// It is not an initializer
// If the expression is a string and the target is a char array, in which case we treat it as an array initializer.
VccByteStringLiteral stringLiteral = source as VccByteStringLiteral;
VccArrayTypeExpression arrayType = targetType as VccArrayTypeExpression;
if (stringLiteral != null && arrayType != null) {
string val = stringLiteral.Value as string;
if (val != null) {
if (arrayType.Size == null) {
CompileTimeConstant ctc = new CompileTimeConstant(val.Length + 1, stringLiteral.SourceLocation);
ctc.SetContainingExpression(stringLiteral);
arrayType.ResetSizeWhenProvidedByInitializer(ctc);
}
int size = arrayType.SizeAsInt32;
VccInitializer newInitializer = VccInitializer.fromStringWithPatchedZeros(val, size, stringLiteral);
// No need to assign the array type expression field, because we know the element type is char.
if (newInitializer != null) {
newInitializer.AddInitializingElementAssignmentsTo(statements, target, arrayType);
}
}
} else {
// If the target is a union, we will try to treat the constant as an initializer.
CompileTimeConstant ctc = source as CompileTimeConstant;
VccUnionDeclaration unionType = MiniResolve(containingBlock.ContainingNamespaceDeclaration, targetType as VccNamedTypeExpression) as VccUnionDeclaration;
if (ctc != null && unionType != null) {
List<Expression> exprs = new List<Expression> {ctc};
VccInitializer newInitializer = new VccInitializer(exprs, false, source.SourceLocation);
newInitializer.SetContainingBlock(containingBlock);
newInitializer.AddInitializingFieldAssignmentsTo(statements, target, unionType);
} else {
// otherwise, generate an assignment.
ExpressionStatement elementAssignment = new ExpressionStatement(new Assignment(new TargetExpression(target), source, source.SourceLocation));
elementAssignment.SetContainingBlock(containingBlock);
statements.Add(elementAssignment);
}
}
}
}