本文整理汇总了C#中QualifiedType类的典型用法代码示例。如果您正苦于以下问题:C# QualifiedType类的具体用法?C# QualifiedType怎么用?C# QualifiedType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QualifiedType类属于命名空间,在下文中一共展示了QualifiedType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsStdType
private bool IsStdType(QualifiedType type)
{
var typePrinter = new CppTypePrinter(Driver.TypeDatabase);
var typeName = type.Visit(typePrinter);
return typeName.Contains("std::");
}
示例2: VisitFunctionDecl
public override bool VisitFunctionDecl(Function function)
{
if (!VisitDeclaration(function))
return false;
if (function.IsReturnIndirect)
{
var indirectParam = new Parameter()
{
Kind = ParameterKind.IndirectReturnType,
QualifiedType = function.ReturnType,
Name = "return",
};
function.Parameters.Insert(0, indirectParam);
function.ReturnType = new QualifiedType(new BuiltinType(
PrimitiveType.Void));
}
if (function.HasThisReturn)
{
// This flag should only be true on methods.
var method = (Method) function;
var classType = new QualifiedType(new TagType(method.Namespace),
new TypeQualifiers {IsConst = true});
function.ReturnType = new QualifiedType(new PointerType(classType));
}
// TODO: Handle indirect parameters
return true;
}
示例3: ChangeToInterfaceType
private static void ChangeToInterfaceType(QualifiedType type)
{
var tagType = type.Type.SkipPointerRefs() as TagType;
if (tagType != null)
{
var @class = tagType.Declaration as Class;
if (@class != null)
{
var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class);
if (@interface != null)
tagType.Declaration = @interface;
}
}
}
示例4: VisitMethodDecl
public override bool VisitMethodDecl(Method method)
{
if (!method.IsConstructor)
return false;
if (method.IsCopyConstructor)
return false;
if (method.Parameters.Count != 1)
return false;
var parameter = method.Parameters[0];
// TODO: disable implicit operators for C++/CLI because they seem not to be support parameters
if (!Driver.Options.IsCSharpGenerator)
{
var pointerType = parameter.Type as PointerType;
if (pointerType != null && !pointerType.IsReference)
return false;
}
var qualifiedPointee = parameter.Type.SkipPointerRefs();
Class castFromClass;
if (qualifiedPointee.TryGetClass(out castFromClass))
{
var castToClass = method.OriginalNamespace as Class;
if (castToClass == null)
return false;
if (castFromClass == castToClass)
return false;
}
var operatorKind = method.IsExplicit
? CXXOperatorKind.ExplicitConversion
: CXXOperatorKind.Conversion;
var qualifiedCastToType = new QualifiedType(new TagType(method.Namespace));
var conversionOperator = new Method
{
Name = Operators.GetOperatorIdentifier(operatorKind),
Namespace = method.Namespace,
Kind = CXXMethodKind.Conversion,
SynthKind = FunctionSynthKind.ComplementOperator,
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType,
OperatorKind = operatorKind
};
var p = new Parameter(parameter);
Class @class;
if (p.Type.SkipPointerRefs().TryGetClass(out @class))
p.QualifiedType = new QualifiedType(new TagType(@class), parameter.QualifiedType.Qualifiers);
p.DefaultArgument = null;
conversionOperator.Parameters.Add(p);
((Class) method.Namespace).Methods.Add(conversionOperator);
return true;
}
示例5: CheckType
/// <summary>
/// Generates a new typedef for the given type if necessary and returns the new type.
/// </summary>
/// <param name="namespace">The namespace the typedef will be added to.</param>
/// <param name="type">The type to check.</param>
/// <returns>The new type.</returns>
private QualifiedType CheckType(DeclarationContext @namespace, QualifiedType type)
{
if (type.Type.IsDependent)
return type;
var pointerType = type.Type as PointerType;
if (pointerType == null)
return type;
var functionType = pointerType.Pointee as FunctionType;
if (functionType == null)
return type;
List<Typedef> typedefs;
if (!allTypedefs.TryGetValue(@namespace.QualifiedName, out typedefs))
{
typedefs = new List<Typedef>();
allTypedefs.Add(@namespace.QualifiedName, typedefs);
}
var typedef = FindMatchingTypedef(typedefs, functionType);
if (typedef == null)
{
for (int i = 0; i < functionType.Parameters.Count; i++)
{
functionType.Parameters[i].Name = string.Format("_{0}", i);
}
typedef = new TypedefDecl
{
Access = AccessSpecifier.Public,
Name = string.Format("__AnonymousDelegate{0}", typedefs.Count),
Namespace = @namespace,
QualifiedType = type,
IsSynthetized = true
};
typedefs.Add(new Typedef
{
Context = @namespace,
Declaration = typedef
});
}
var typedefType = new TypedefType
{
Declaration = typedef
};
return new QualifiedType(typedefType);
}
示例6: ChangeToInterfaceType
private static void ChangeToInterfaceType(ref QualifiedType type)
{
var tagType = (type.Type.GetFinalPointee() ?? type.Type) as TagType;
if (tagType != null)
{
var @class = tagType.Declaration as Class;
if (@class != null)
{
var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class);
if (@interface != null)
{
type.Type = (Type) type.Type.Clone();
((TagType) (type.Type.GetFinalPointee() ?? type.Type)).Declaration = @interface;
}
}
}
}
示例7: VisitMethodDecl
public override bool VisitMethodDecl(Method method)
{
if (AlreadyVisited(method) || !method.IsGenerated || !method.IsConstructor ||
method.IsCopyConstructor || method.Parameters.Count != 1)
return false;
var parameter = method.Parameters[0];
// TODO: disable implicit operators for C++/CLI because they seem not to be support parameters
if (!Driver.Options.IsCSharpGenerator)
{
var pointerType = parameter.Type as PointerType;
if (pointerType != null && !pointerType.IsReference)
return false;
}
var qualifiedPointee = parameter.Type.GetFinalPointee() ?? parameter.Type;
Class castFromClass;
var castToClass = method.OriginalNamespace as Class;
if (qualifiedPointee.TryGetClass(out castFromClass))
{
if (castToClass == null || castToClass.IsAbstract)
return false;
if (ConvertsBetweenDerivedTypes(castToClass, castFromClass))
return false;
}
if (castToClass != null && castToClass.IsAbstract)
return false;
var operatorKind = method.IsExplicit
? CXXOperatorKind.ExplicitConversion
: CXXOperatorKind.Conversion;
var qualifiedCastToType = new QualifiedType(new TagType(method.Namespace));
var conversionOperator = new Method
{
Name = Operators.GetOperatorIdentifier(operatorKind),
Namespace = method.Namespace,
Kind = CXXMethodKind.Conversion,
SynthKind = FunctionSynthKind.ComplementOperator,
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType,
OperatorKind = operatorKind,
IsExplicit = method.IsExplicit
};
conversionOperator.Parameters.Add(new Parameter(parameter) { DefaultArgument = null });
((Class) method.Namespace).Methods.Add(conversionOperator);
return true;
}
示例8: VisitFunctionDecl
public override bool VisitFunctionDecl(Function function)
{
if (!VisitDeclaration(function))
return false;
if (function.IsReturnIndirect)
{
var indirectParam = new Parameter()
{
Kind = ParameterKind.IndirectReturnType,
QualifiedType = function.ReturnType,
Name = "return",
};
function.Parameters.Insert(0, indirectParam);
function.ReturnType = new QualifiedType(new BuiltinType(
PrimitiveType.Void));
}
var method = function as Method;
if (function.HasThisReturn)
{
// This flag should only be true on methods.
var classType = new QualifiedType(new TagType(method.Namespace),
new TypeQualifiers {IsConst = true});
function.ReturnType = new QualifiedType(new PointerType(classType));
}
// Deleting destructors (default in v-table) accept an i32 bitfield as a
// second parameter.in MS ABI.
if (method != null && method.IsDestructor && Driver.Options.IsMicrosoftAbi)
{
method.Parameters.Add(new Parameter
{
Kind = ParameterKind.ImplicitDestructorParameter,
QualifiedType = new QualifiedType(new BuiltinType(PrimitiveType.Int)),
Name = "delete"
});
}
// TODO: Handle indirect parameters
return true;
}
示例9: VisitMethodDecl
public override bool VisitMethodDecl(Method method)
{
if (!method.IsConstructor)
return false;
if (method.IsCopyConstructor)
return false;
if (method.Parameters.Count != 1)
return false;
var parameter = method.Parameters[0];
var parameterType = parameter.Type as PointerType;
if (parameterType == null)
return false;
if (!parameterType.IsReference)
return false;
var qualifiedPointee = parameterType.QualifiedPointee;
Class castFromClass;
if (!qualifiedPointee.Type.TryGetClass(out castFromClass))
return false;
var castToClass = method.OriginalNamespace as Class;
if (castToClass == null)
return false;
if (castFromClass == castToClass)
return false;
var operatorKind = method.IsExplicit
? CXXOperatorKind.ExplicitConversion
: CXXOperatorKind.Conversion;
var castToType = new TagType(castToClass);
var qualifiedCastToType = new QualifiedType(castToType);
var conversionOperator = new Method()
{
Name = Operators.GetOperatorIdentifier(operatorKind),
Namespace = castFromClass,
Kind = CXXMethodKind.Conversion,
IsSynthetized = true,
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType
};
conversionOperator.OperatorKind = operatorKind;
castFromClass.Methods.Add(conversionOperator);
return true;
}
示例10: GetInterfaceType
private static QualifiedType GetInterfaceType(QualifiedType type)
{
var tagType = type.Type as TagType;
if (tagType == null)
{
var pointerType = type.Type as PointerType;
if (pointerType != null)
tagType = pointerType.Pointee as TagType;
}
if (tagType != null)
{
var @class = tagType.Declaration as Class;
if (@class != null)
{
var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class);
if (@interface != null)
return new QualifiedType(new TagType(@interface));
}
}
return type;
}
示例11: GetOrCreateProperty
Property GetOrCreateProperty(Class @class, string name, QualifiedType type)
{
var prop = @class.Properties.FirstOrDefault(property => property.Name == name
&& property.QualifiedType.Equals(type));
var prop2 = @class.Properties.FirstOrDefault(property => property.Name == name);
if (prop == null && prop2 != null)
Driver.Diagnostics.Debug("Property {0}::{1} already exists (type: {2})",
@class.Name, name, type.Type.ToString());
if (prop != null)
return prop;
prop = new Property
{
Name = name,
Namespace = @class,
QualifiedType = type
};
@class.Properties.Add(prop);
return prop;
}
示例12: __CopyValue
private static void* __CopyValue(QualifiedType.__Internal native)
{
var ret = Marshal.AllocHGlobal(8);
*(QualifiedType.__Internal*) ret = native;
return ret.ToPointer();
}
示例13: GetUnderlyingType
private static Type GetUnderlyingType(QualifiedType type)
{
TagType tagType = type.Type as TagType;
if (tagType != null)
return type.Type;
// TODO: we should normally check pointer types for const;
// however, there's some bug, probably in the parser, that returns IsConst = false for "const Type& arg"
// so skip the check for the time being
PointerType pointerType = type.Type as PointerType;
return pointerType != null ? pointerType.Pointee : type.Type;
}
示例14: QualifiedType
internal QualifiedType(QualifiedType.Internal native)
: this(&native)
{
}
示例15: GenerateDelegateSignature
private string GenerateDelegateSignature(IEnumerable<Parameter> @params, QualifiedType returnType)
{
var typePrinter = new CSharpTypePrinter(Driver);
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
var typesBuilder = new StringBuilder();
if (!returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{
typesBuilder.Insert(0, returnType.Type.CSharpType(typePrinter));
typesBuilder.Append('_');
}
foreach (var parameter in @params)
{
typesBuilder.Append(parameter.CSharpType(typePrinter));
typesBuilder.Append('_');
}
if (typesBuilder.Length > 0)
typesBuilder.Remove(typesBuilder.Length - 1, 1);
var delegateName = typesBuilder.Replace("global::System.", string.Empty).Replace(
"*", "Ptr").Replace('.', '_').ToString();
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
delegateName = "Action_" + delegateName;
else
delegateName = "Func_" + delegateName;
typePrinter.PopContext();
return delegateName;
}