private static void WriteLock(LanguageWriter w, ILockStatement statement) { w.Write("{"); w.WriteIndent(); w.WriteLine(); Scope.VariableData data = new Scope.VariableData("<lock_statement>" + WriteLock_counter++.ToString(), true); data.disp_name = "lock"; w.scope[data.name] = data; // msclr::lock を初期化 w.WriteReference("msclr", "", null); w.Write("::"); w.WriteReference("lock", "#include <msclr/lock.h> で使用して下さい", null); w.Write(" "); w.WriteDeclaration(data.disp_name); w.Write("("); ExpressionWriter.WriteExpression(w, statement.Expression, false); w.Write(");"); w.WriteLine(); // 中身を書込 if (statement.Body != null) { WriteBlock(w, statement.Body); } w.WriteOutdent(); w.Write("}"); w.WriteLine(); }
private static void WriteMemoryInitialize(LanguageWriter w, IMemoryInitializeStatement state) { w.Write("::"); w.WriteReference("memset", "Crt 関数 #include <memory.h>", null); w.Write("("); ExpressionWriter.WriteExpression(w, state.Offset, false); w.Write(", "); ExpressionWriter.WriteExpression(w, state.Value, false); w.Write(", "); ExpressionWriter.WriteExpression(w, state.Length, false); w.Write(");"); w.WriteLine(); }
private static void WriteMemoryCopy(LanguageWriter w, IMemoryCopyStatement state) { w.Write("::"); w.WriteReference("memcpy", "Crt 関数 #include <memory.h>", null); w.Write("("); ExpressionWriter.WriteExpression(w, state.Destination, false); w.Write(", "); ExpressionWriter.WriteExpression(w, state.Source, false); w.Write(", "); ExpressionWriter.WriteExpression(w, state.Length, false); w.Write(");"); w.WriteLine(); }
//=========================================================== // 追加 //=========================================================== private static void WriteStackAllocate(LanguageWriter w, IStackAllocateExpression exp) { TypeRef type = new TypeRef(exp.Type); w.Write("("); type.WriteNameWithRef(w); w.Write("*)::"); w.WriteReference("_alloca", "Crt 関数 #include <malloc.h>", null); w.Write("("); w.WriteKeyword("sizeof"); w.Write("("); type.WriteName(w); w.Write(")*"); WriteExpression(w, exp.Expression, PREC_BI_MUL > GetExpressionPrecedence(exp.Expression)); w.Write(")"); }
private void WriteCustomAttribute(ICustomAttribute attr) { IMethodReference meth_ref = attr.Constructor; TypeRef decltype = new TypeRef(meth_ref.DeclaringType); string name = decltype.Name; // 参照付きで名前を指定 writer.WriteReference( name.EndsWith("Attribute")?name.Substring(0, name.Length - 9):name, string.Format("/* 属性 コンストラクタ */\r\n{0}::{1}({2});", decltype.FullName, decltype.Name, LanguageWriter.GetDesc(meth_ref.Parameters) ), meth_ref ); if (attr.Arguments.Count != 0) { writer.Write("("); writer.WriteExpressionCollection(attr.Arguments); writer.Write(")"); } }
private static void WriteModify(LanguageWriter w, TypeRef modifier, TypeRef elemType, bool required) { if (modifier.tref != null && modifier.tref.Namespace == "System.Runtime.CompilerServices") { switch (modifier.tref.Name) { case "IsVolatile": if (elemType.IsPointer) { elemType.WriteNameWithRef(w); w.WriteKeyword("volatile"); } else { w.WriteKeyword("volatile"); w.Write(" "); elemType.WriteNameWithRef(w); } return; case "IsConst": if (elemType.IsPointer) { elemType.WriteNameWithRef(w); w.WriteKeyword("const"); } else { //#warning RefOnStack の場合には const は要らない → refOnStack で呼び出す側で、自分で之を取り除くようにした w.WriteKeyword("const"); w.Write(" "); elemType.WriteNameWithRef(w); } return; case "IsLong": if (elemType.IsType("System", "Int32")) { w.WriteReference("long", elemType.FullName, elemType.tref); return; } else if (elemType.IsType("System", "UInt32")) { w.WriteReference("unsigned long", elemType.FullName, elemType.tref); return; } else if (elemType.IsType("System", "Double")) { w.WriteReference("long double", elemType.FullName, elemType.tref); return; } break; case "IsExplicitlyDereferenced": IReferenceType reftype = elemType.type as IReferenceType; if (reftype != null) { w.WriteKeyword("pin_ptr"); w.Write("<"); new TypeRef(reftype.ElementType).WriteNameWithRef(w); w.Write(">"); return; } break; case "CallConvStdcall": elemType.WriteNameWithRef(w); w.Write(" "); w.WriteKeyword("__stdcall"); return; case "CallConvCdecl": elemType.WriteNameWithRef(w); w.Write(" "); w.WriteKeyword("__cdecl"); return; case "CallConvFastcall": elemType.WriteNameWithRef(w); w.Write(" "); w.WriteKeyword("__fastcall"); return; case "CallConvThiscall": elemType.WriteNameWithRef(w); w.Write(" "); w.WriteKeyword("__thiscall"); return; case "IsBoxed": IOptionalModifier mod = elemType.type as IOptionalModifier; if (mod == null) { break; } TypeRef modifier2 = new TypeRef(mod.Modifier); if (!modifier2.IsValueType) { break; } if (!new TypeRef(mod.ElementType).IsType("System", "ValueType")) { break; } modifier2.WriteName(w); w.Write("^"); return; } } elemType.WriteNameWithRef(w); w.Write("<"); w.WriteKeyword(required?"modreq":"modopt"); w.Write(" "); w.WriteReference(modifier.Name, modifier.FullName, modifier.tref); w.Write(">"); return; }
public string WriteName(LanguageWriter w) { if (tref != null) { string name = tref.Name.Replace(".", "::").Replace("+", "::"); string special; if (tref.Namespace == "System" && specialTypeNames.TryGetValue(name, out special)) { name = special; } name = NameMangling.UnDecorateName(name); w.WriteReference(name, this.FullName, tref); ITypeCollection genericArguments = tref.GenericArguments; if (genericArguments.Count > 0) { w.Write("<"); bool first = true; foreach (IType type1 in genericArguments) { if (first) { first = false; } else { w.Write(", "); } new TypeRef(type1).WriteNameWithRef(w); } w.Write(">"); } return(name); } IArrayType type2 = type as IArrayType; if (type2 != null) { w.WriteKeyword("array"); w.Write("<"); new TypeRef(type2.ElementType).WriteNameWithRef(w); if (type2.Dimensions.Count > 1) { w.Write(", "); w.WriteAsLiteral(type2.Dimensions.Count); } w.Write(">"); } IPointerType type4 = type as IPointerType; if (type4 != null) { new TypeRef(type4.ElementType).WriteNameWithRef(w); w.Write("*"); } IReferenceType type3 = type as IReferenceType; if (type3 != null) { new TypeRef(type3.ElementType).WriteNameWithRef(w); w.Write("%"); } IOptionalModifier modifier2 = type as IOptionalModifier; if (modifier2 != null) { WriteModify(w, new TypeRef(modifier2.Modifier), new TypeRef(modifier2.ElementType), false); } IRequiredModifier modifier = type as IRequiredModifier; if (modifier != null) { WriteModify(w, new TypeRef(modifier.Modifier), new TypeRef(modifier.ElementType), true); } IFunctionPointer fptr = type as IFunctionPointer; if (fptr != null) { w.Write("("); new TypeRef(fptr.ReturnType.Type).WriteNameWithRef(w); w.Write(" (*)("); bool first = true; foreach (IParameterDeclaration declaration in fptr.Parameters) { if (first) { first = false; } else { w.Write(", "); } new TypeRef(declaration.ParameterType).WriteNameWithRef(w); } w.Write("))"); } IGenericParameter parameter = type as IGenericParameter; if (parameter != null) { w.WriteReference(parameter.Name, "/* ジェネリックパラメータ */ " + parameter.Name, null); } IGenericArgument argument = type as IGenericArgument; if (argument != null) { new TypeRef(argument.Resolve()).WriteNameWithRef(w); } if (type is IValueTypeConstraint) { w.WriteKeyword("value class"); } else if (type is IDefaultConstructorConstraint) { w.Write("<DefaultConstructorConstraint>"); } return("<不明な型>"); }