internal void Visit(Compilation compilation) { var type = new TypeDefinition("default", name.value, TypeAttributes.Public); if (basetype != null) { type.BaseType = compilation.GetTypeReference(basetype); } else { type.BaseType = compilation.Module.TypeSystem.Object; } foreach (var member in members) { member.Visit(compilation, this, type); } // empty ctor var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; var method = new MethodDefinition(".ctor", methodAttributes, compilation.Module.TypeSystem.Void); method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); var methodRef = new MethodReference(".ctor", compilation.Module.TypeSystem.Void, type.BaseType) { HasThis = true }; method.Body.Instructions.Add(Instruction.Create(OpCodes.Call, methodRef)); method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); type.Methods.Add(method); compilation.AddType(type); }
public CppWriter(Compilation compilation) { _compilation = compilation; SetWellKnownTypeSignatureName(WellKnownType.Void, "void"); SetWellKnownTypeSignatureName(WellKnownType.Boolean, "uint8_t"); SetWellKnownTypeSignatureName(WellKnownType.Char, "uint16_t"); SetWellKnownTypeSignatureName(WellKnownType.SByte, "int8_t"); SetWellKnownTypeSignatureName(WellKnownType.Byte, "uint8_t"); SetWellKnownTypeSignatureName(WellKnownType.Int16, "int16_t"); SetWellKnownTypeSignatureName(WellKnownType.UInt16, "uint16_t"); SetWellKnownTypeSignatureName(WellKnownType.Int32, "int32_t"); SetWellKnownTypeSignatureName(WellKnownType.UInt32, "uint32_t"); SetWellKnownTypeSignatureName(WellKnownType.Int64, "int64_t"); SetWellKnownTypeSignatureName(WellKnownType.UInt64, "uint64_t"); SetWellKnownTypeSignatureName(WellKnownType.IntPtr, "intptr_t"); SetWellKnownTypeSignatureName(WellKnownType.UIntPtr, "uintptr_t"); SetWellKnownTypeSignatureName(WellKnownType.Single, "float"); SetWellKnownTypeSignatureName(WellKnownType.Double, "double"); // TODO: For now, ensure that all types/methods referenced by unmanaged helpers are present var stringType = _compilation.TypeSystemContext.GetWellKnownType(WellKnownType.String); AddInstanceFields(stringType); var stringArrayType = stringType.MakeArrayType(); _compilation.AddType(stringArrayType); _compilation.MarkAsConstructed(stringArrayType); }