当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionStatement.SetContainingBlock方法代码示例

本文整理汇总了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);
       }
     }
       }
 }
开发者ID:edgar-pek,项目名称:VCDryad,代码行数:49,代码来源:Expressions.cs


注:本文中的ExpressionStatement.SetContainingBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。