本文整理汇总了C#中AstType.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# AstType.Clone方法的具体用法?C# AstType.Clone怎么用?C# AstType.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstType
的用法示例。
在下文中一共展示了AstType.Clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryPatchTemplateToObjectType
/// <summary>
/// Converts template types to Object type (useful for inline methods and template specialization types)
/// </summary>
/// <param name="type"></param>
/// <param name="newType"></param>
/// <returns>Returns if the type is actually changed or not</returns>
public static bool TryPatchTemplateToObjectType(AstType type, out AstType newType)
{
newType = (AstType)type.Clone();
string name = "";
if (type is SimpleType)
{
SimpleType st = type as SimpleType;
name = st.Identifier;
if (Cache.GetTemplateTypes().Contains(name))
{
newType = new SimpleType("Object");
return true;
}
else
{
if (st.TypeArguments.Any())
{
List<AstType> args = new List<AstType>();
bool converted = false;
foreach (AstType t in st.TypeArguments)
{
AstType discard;
if (TryPatchTemplateToObjectType(t, out discard))
{
converted = true;
args.Add(new SimpleType("Object"));
}
else
args.Add((AstType)t.Clone());
}
SimpleType nType = (SimpleType)st.Clone();
nType.TypeArguments.Clear();
nType.TypeArguments.AddRange(args.ToArray());
newType = nType;
return converted;
}
}
}
if (type is PtrType)
{
if ((type as PtrType).Target is SimpleType)
{
SimpleType pst = (type as PtrType).Target as SimpleType;
AstType tmp;
bool converted = TryPatchTemplateToObjectType(pst, out tmp);
newType = new PtrType(tmp);
return converted;
}
}
return false;
}
示例2: MergeTypes
static AstType MergeTypes (AstType x, AstType y)
{
if (TypesEqual (x, y)) {
return x.Clone ();
}
return new PrimitiveType ("object");
}
示例3: GetDefaultValueExpression
Expression GetDefaultValueExpression (AstType astType)
{
var type = ctx.ResolveType (astType);
if ((type.IsReferenceType ?? false) || type.Kind == TypeKind.Dynamic)
return new NullReferenceExpression ();
var typeDefinition = type.GetDefinition ();
if (typeDefinition != null) {
switch (typeDefinition.KnownTypeCode) {
case KnownTypeCode.Boolean:
return new PrimitiveExpression (false);
case KnownTypeCode.Char:
return new PrimitiveExpression ('\0');
case KnownTypeCode.SByte:
case KnownTypeCode.Byte:
case KnownTypeCode.Int16:
case KnownTypeCode.UInt16:
case KnownTypeCode.Int32:
return new PrimitiveExpression (0);
case KnownTypeCode.Int64:
return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0L) };
case KnownTypeCode.UInt32:
return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0U) };
case KnownTypeCode.UInt64:
return new Choice {
new PrimitiveExpression (0), new PrimitiveExpression (0U), new PrimitiveExpression (0UL)
};
case KnownTypeCode.Single:
return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0F) };
case KnownTypeCode.Double:
return new Choice {
new PrimitiveExpression (0), new PrimitiveExpression (0F), new PrimitiveExpression (0D)
};
case KnownTypeCode.Decimal:
return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0M) };
case KnownTypeCode.NullableOfT:
return new NullReferenceExpression ();
}
if (type.Kind == TypeKind.Struct)
return new ObjectCreateExpression (astType.Clone ());
}
return new DefaultValueExpression (astType.Clone ());
}
示例4: GetNotNullTypeCheck
static Expression GetNotNullTypeCheck (string id, AstType type)
{
return new IsExpression {
Expression = new IdentifierExpression (id),
Type = type.Clone (),
};
}