/// <inheritdoc/> public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration) { IType type = propertyDeclaration.ReturnType.GetResolveResult().Type; if (propertyDeclaration.Getter != null) { Formatter.AppendIndented(String.Empty); TypeVisitor.FormatTypeDelaration(type); Formatter.Append(" get_"); Formatter.Append(propertyDeclaration.NameToken.Name); Formatter.AppendLine("();"); } if (propertyDeclaration.Setter != null) { Formatter.AppendIndented("void set_"); Formatter.Append(propertyDeclaration.NameToken.Name); Formatter.Append("("); TypeVisitor.FormatTypeDelaration(type); Formatter.AppendLine(" x_value );"); } ICSharpCode.Decompiler.IL.ILFunction inst = propertyDeclaration.Getter.Annotation <ICSharpCode.Decompiler.IL.ILFunction>(); String hiddenName = MyIlVisitor.GetHiddenPropertyName(inst.Body as ICSharpCode.Decompiler.IL.BlockContainer); if (!String.IsNullOrEmpty(hiddenName)) { Formatter.AppendIndented(String.Empty); TypeVisitor.FormatTypeDelaration(type); Formatter.Append(" "); Formatter.Append(hiddenName); Formatter.AppendLine(";"); } }
/// <inheritdoc/> public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration) { IType type = typeDeclaration.Annotation <TypeResolveResult>().Type; Formatter.NameSpace = type.Namespace; switch (typeDeclaration.ClassType) { case ClassType.Enum: Formatter.AppendIndented("enum "); break; case ClassType.Interface: Formatter.AppendIndented("class "); break; case ClassType.Struct: Formatter.AppendIndented("struct "); break; default: Formatter.AppendIndented("class "); break; } TypeVisitor.FormatType(type); if (typeDeclaration.ClassType == ClassType.Enum) { OutputEnumValues(typeDeclaration); } else { Formatter.Append(";"); } Formatter.AppendLine(String.Empty); }
/// <summary> /// Add headers to output /// </summary> public override void AddHeaders() { Formatter.AppendLine("#pragma once"); Formatter.AppendLine("#include \"DotnetTypes.h\""); Formatter.AppendLine("#include <DotNetLibrarySupport.h>"); Formatter.AppendLine("using namespace DotnetLibrary;"); Formatter.AppendLine("using namespace DotnetLibrarySupport;"); Formatter.AppendLine(String.Empty); }
/// <inheritdoc/> public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration) { Formatter.AppendIndented("static "); operatorDeclaration.ReturnType.AcceptVisitor(this); Formatter.Append(" "); Formatter.Append(Operators[operatorDeclaration.OperatorType]); WriteCommaSeparatedListInParenthesis(operatorDeclaration.Parameters); Formatter.AppendLine(";"); }
/// <inheritdoc/> public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration) { Formatter.AppendIndented(String.Empty); WriteModifiers(methodDeclaration.ModifierTokens); IType type = methodDeclaration.ReturnType.GetResolveResult().Type; TypeVisitor.FormatTypeDelaration(type); Formatter.Append(" "); WriteMethodHeader(methodDeclaration.NameToken.Name, methodDeclaration.Parameters); if (methodDeclaration.Body.IsNull) { Formatter.Append(" = 0"); } Formatter.AppendLine(";"); }
/// <summary> /// Output all values in an enum. /// Append the enum name to end to ensure they are unique. /// </summary> /// <param name="typeDeclaration">enum declaration</param> private void OutputEnumValues(TypeDeclaration typeDeclaration) { EnumName = typeDeclaration.Name; Formatter.AddOpenBrace(); bool first = true; foreach (var member in typeDeclaration.Members) { if (!first) { Formatter.AppendLine(","); } member.AcceptVisitor(this); first = false; } Formatter.AddCloseBrace(true); }
/// <summary> /// Output using namespaces /// </summary> private void WriteUsingNamespaces() { Formatter.CloseNamespace(); foreach (String ns in namespaces.Values) { Formatter.Append("using namespace "); if (String.IsNullOrEmpty(ns)) { Formatter.Append("UNNAMED"); } else { Formatter.Append(ns + "_NS"); } Formatter.AppendLine(";"); } }
/// <inheritdoc/> public override void VisitFieldDeclaration(FieldDeclaration fieldDeclaration) { VariableInitializer variable = fieldDeclaration.Variables.First <VariableInitializer>(); Formatter.AppendIndented(String.Empty); var sym = fieldDeclaration.GetSymbol() as IEntity; if (sym != null && sym.IsStatic) { Formatter.Append("static "); } IType type = fieldDeclaration.ReturnType.GetResolveResult().Type; TypeVisitor.FormatTypeDelaration(type); Formatter.Append(" "); WriteCommaSeparatedList(fieldDeclaration.Variables); Formatter.AppendLine(";"); }
/// <inheritdoc/> public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { bool isStatic = (constructorDeclaration.Modifiers & Modifiers.Static) != 0; TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration; String name = null; if (type != null && type.Name != constructorDeclaration.Name) { name = type.NameToken.Name; } else { name = constructorDeclaration.NameToken.Name; } Formatter.AppendIndented(String.Empty); if (!isStatic) { IType type2 = constructorDeclaration.GetResolveResult().Type; WriteMethodHeader(name, constructorDeclaration.Parameters); Formatter.AppendLine(";"); } else { Formatter.Append("static Boolean "); Formatter.AppendName(name); Formatter.AppendLine("_Static();"); Formatter.AppendIndented("static Boolean "); Formatter.AppendName(name); Formatter.AppendLine("_Initilized;"); } HadConstructor = true; if (constructorDeclaration.Parameters.Count == 0) { HadDefaultConstructor = true; } }
/// <summary> /// Add header to .h file /// </summary> public override void AddHeaders() { Formatter.AppendLine("#pragma once"); Formatter.AppendLine("#include \"TranslatedProtos.h\""); declarations.Clear(); }