private void WritePropertyDefinition(PapyrusPropertyDefinition prop) { pexWriter.Write(prop.Name); pexWriter.Write(prop.TypeName); pexWriter.Write(prop.Documentation); pexWriter.Write(prop.Userflags); pexWriter.Write(prop.Flags); if (prop.IsAuto) { pexWriter.Write(prop.AutoName); } else { if (prop.HasGetter) { WriteMethod(prop.GetMethod); } if (prop.HasSetter) { WriteMethod(prop.SetMethod); } } }
private void ReadProperties(PapyrusAssemblyDefinition asm, PapyrusTypeDefinition typeDef) { var propDefs = new Collection <PapyrusPropertyDefinition>(); var propertyCount = pexReader.ReadInt16(); for (var i = 0; i < propertyCount; i++) { var prop = new PapyrusPropertyDefinition(asm); prop.Name = pexReader.ReadStringRef(); prop.TypeName = pexReader.ReadStringRef(); prop.Documentation = pexReader.ReadStringRef(); prop.Userflags = pexReader.ReadInt32(); prop.Flags = pexReader.ReadByte(); if (prop.IsAuto) { prop.AutoName = pexReader.ReadString(); } else { if (prop.HasGetter) { prop.GetMethod = ReadMethod(asm); prop.GetMethod.IsGetter = true; prop.GetMethod.PropName = prop.Name.Value; } if (prop.HasSetter) { prop.SetMethod = ReadMethod(asm); prop.SetMethod.IsSetter = true; prop.SetMethod.PropName = prop.Name.Value; } } propDefs.Add(prop); } typeDef.Properties = propDefs; }
private List <PapyrusPropertyDefinition> CreateProperties( IEnumerable <PapyrusAssemblyDefinition> papyrusAssemblyCollection, TypeDefinition type, PapyrusTypeDefinition papyrusType, PapyrusAssemblyDefinition pex) { var propList = new List <PapyrusPropertyDefinition>(); foreach (var prop in type.Properties) { var properties = attributeReader.ReadPapyrusAttributes(prop); var propertyTypeName = Utility.GetPapyrusReturnType(prop.PropertyType); if (EnumDefinitions.Any(i => i.FullName == prop.PropertyType.FullName)) { propertyTypeName = "Int"; } var papyrusPropertyDefinition = new PapyrusPropertyDefinition(pex, prop.Name, propertyTypeName) { Documentation = "".Ref(pex), Userflags = properties.UserFlagsValue }; var result = propertyAnalyzer.Analyze(prop); if (result.IsAutoVar) { papyrusPropertyDefinition.IsAuto = true; papyrusPropertyDefinition.AutoName = result.AutoVarName; } else { if (prop.SetMethod != null) { papyrusPropertyDefinition.HasSetter = true; papyrusPropertyDefinition.SetMethod = CreatePapyrusMethodDefinition(papyrusAssemblyCollection, pex, papyrusType, prop.SetMethod, delegatePairDefinition, processorOptions); propertyMethods.Add(prop.SetMethod); } if (prop.GetMethod != null) { papyrusPropertyDefinition.HasGetter = true; papyrusPropertyDefinition.GetMethod = CreatePapyrusMethodDefinition(papyrusAssemblyCollection, pex, papyrusType, prop.GetMethod, delegatePairDefinition, processorOptions); propertyMethods.Add(prop.GetMethod); } if (prop.SetMethod == null && prop.GetMethod == null) { papyrusPropertyDefinition.IsAuto = true; papyrusPropertyDefinition.AutoName = papyrusType.Fields.FirstOrDefault( f => f.Name.Value.Contains("_" + prop.Name + "_") && f.Name.Value.EndsWith("_BackingField")).Name.Value; } } propList.Add(papyrusPropertyDefinition); } return(propList); }
/// <summary> /// Writes the method. /// </summary> /// <param name="method">The method.</param> /// <param name="type">The type.</param> /// <param name="asm">The asm.</param> /// <param name="indent">The indent.</param> /// <param name="isGetter">if set to <c>true</c> [is getter].</param> /// <param name="isSetter">if set to <c>true</c> [is setter].</param> private void WriteMethod(PapyrusMethodDefinition method, PapyrusTypeDefinition type, PapyrusAssemblyDefinition asm, int indent, PapyrusPropertyDefinition prop = null, bool isGetter = false, bool isSetter = false) { // SetGlobalIndent(indent); if (!isGetter && !isSetter) { if (method.Documentation != null && !string.IsNullOrEmpty(method.Documentation.Value)) { WriteDoc(method.Documentation, indent); } Append("public " + (method.IsGlobal ? "static " : "") + (method.IsNative ? "extern " : "") + ((string)method.ReturnTypeName).Replace("None", "void") + " " + (string)method.Name , indent); Append("("); Append(string.Join(",", method.Parameters.Select(i => (string)i.TypeName + " " + (string)i.Name))); AppendLine(")"); } AppendLine("{", indent); //if (isGetter) //{ // if (prop != null) // { // prop. // } // // type.Fields.FirstOrDefault(f=>f.Name.Value.Contains()); // AppendLine("return <backing_field>;", indent + 1); //} //else if (isSetter) //{ // AppendLine("<backing_field> = value;", indent + 1); //} //else { if (method.HasBody) { var debug = asm.DebugInfo.MethodDescriptions.FirstOrDefault( m => method.Name != null && m.Name.Value == method.Name.Value); if (debug != null) { AppendLine("// DEBUG LINE NUMBER: " + string.Join(",", debug.BodyLineNumbers.ToArray()), indent + 1); } foreach (var var in method.GetVariables()) { if (var.Name.Value.ToLower() == "::nonevar") { continue; } var typeName = (string)var.TypeName; if (typeName.Contains("#")) { AppendLine("// Struct Variable: " + typeName, indent + 1); AppendLine(typeName.Split('#').LastOrDefault() + " " + (string)var.Name + ";", indent + 1); } else { AppendLine(typeName + " " + (string)var.Name + ";", indent + 1); } } //var flowGraphBuilder = new PapyrusControlFlowGraphBuilder(method); //var graph = flowGraphBuilder.Build(); //graph.ComputeDominance(); //graph.ComputeDominanceFrontier(); //var nodes = graph.Nodes.Skip(2).ToList(); //var count = nodes.Count; foreach (var instruction in method.Body.Instructions) { var instructionString = WriteInstruction(instruction, method, type); foreach ( var row in instructionString.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { AppendLine("/* " + instruction.Offset + " */ " + row, indent + 1); } } //List<PapyrusInstruction> targetEnd = new List<PapyrusInstruction>(); //foreach (var n in nodes) //{ // var end = n.End; // //if (count > 1) // // AppendLine("/* ====== Node Start ====== */", 1); // foreach (var instruction in n.Instructions) // { // Append("/* " + instruction.Offset + " */ ", 1); // WriteInstruction(indent, instruction, method, type, asm); // } // if (end != null && IsJump(end.OpCode)) // { // var direction = int.Parse(end.GetArg(IsJumpf(end.OpCode) || IsJumpt(end.OpCode) ? 1 : 0)); // if (direction < 0) // { // // LOOP? // } // else // { // // BRANCHING // } // } //} } } AppendLine("}", indent); }