/// <summary> /// Tries to create a type of the given type /// </summary> /// <param name="name">The name of the type</param> private BaseType CreateType(string name) { //Split the type name var typeParts = SplitTypeName(name); BaseType type = null; if (TypeSystem.FromString(typeParts[0], out var primitiveType)) { type = new PrimitiveType(primitiveType); } else if (typeParts[0] == "Ref") { if (ExtractElementType(typeParts[1], out var elementTypeName)) { var elementType = FindType(elementTypeName); if (elementType != null) { type = new ArrayType(elementType); } } else if (typeParts[1] == "Null") { type = new NullType(); } else { if (typeParts.Count >= 2) { var className = ""; bool isFirst = true; for (var i = 1; i < typeParts.Count; i++) { if (isFirst) { isFirst = false; } else { className += "."; } className += typeParts[i]; } var classMetadata = this.classMetadataProvider.GetMetadata(className); if (classMetadata != null) { type = new ClassType(classMetadata); } } } } if (type != null) { this.types.Add(name, type); } return(type); }
/// <summary> /// Finds the array type for the given element type /// </summary> /// <param name="elementType">The element type</param> /// <param name="tryToConstruct">Indicates if to try to construct the type if does not exist.</param> /// <returns>The type or null</returns> public ArrayType FindArrayType(BaseType elementType, bool tryToConstruct = true) { return(this.FindType(TypeSystem.ArrayTypeName(elementType), tryToConstruct) as ArrayType); }
/// <summary> /// Creates a new external function /// </summary> /// <typeparam name="TDelegate">The type of the delegate</typeparam> /// <param name="name">The name of the function</param> /// <param name="parameters">The parameters</param> /// <param name="returnType">The return type</param> /// <param name="funcDelegate">The delegate for the function</param> public static FunctionDefinition NewExternal <TDelegate>(string name, IList <BaseType> parameters, BaseType returnType, TDelegate funcDelegate) { return(new FunctionDefinition( name, parameters, returnType, Marshal.GetFunctionPointerForDelegate(funcDelegate))); }