public override object VisitFieldDeclaration (ICSharpCode.NRefactory.Ast.FieldDeclaration fieldDeclaration, object data) { foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration varDecl in fieldDeclaration.Fields) { DomField field = new DomField (); field.Name = varDecl.Name; field.Documentation = RetrieveDocumentation (fieldDeclaration.StartLocation.Line); field.Location = ConvertLocation (fieldDeclaration.StartLocation); field.BodyRegion = ConvertRegion (varDecl.StartLocation, varDecl.EndLocation); field.Modifiers = ConvertModifiers (fieldDeclaration.Modifier); if (typeStack.Peek ().ClassType == ClassType.Enum) { field.ReturnType = new DomReturnType (typeStack.Peek ()); } else { field.ReturnType = ConvertReturnType (fieldDeclaration.TypeReference); } // Enum fields have an empty type. if (field.ReturnType != null && string.IsNullOrEmpty (field.ReturnType.FullName)) field.ReturnType = null; AddAttributes (field, fieldDeclaration.Attributes); field.DeclaringType = typeStack.Peek (); if (field.DeclaringType.ClassType == ClassType.Enum) { field.Modifiers |= Modifiers.Const; field.Modifiers |= Modifiers.SpecialName; field.Modifiers |= Modifiers.Public; } typeStack.Peek ().Add (field); } return null; }
void BuildAttribute(XmlElement element) { var compUnit = this.CompilationUnit as PythonCompilationUnit; Console.WriteLine("Attribute({0})", element.GetAttribute("name")); var location = GetDomLocation(element); var field = new DomField(); field.Location = location; field.Name = element.GetAttribute("name"); var mod = Modifiers.None; if (field.Name.StartsWith("_")) { mod |= Modifiers.Private; } else { mod |= Modifiers.Public; } field.Modifiers = mod; compUnit.Add(field); }
public static DomField ReadField(BinaryReader reader, INameDecoder nameTable) { DomField result = new DomField(); ReadMemberInformation(reader, nameTable, result); result.ReturnType = ReadReturnType(reader, nameTable); return(result); }
public DomType Load(GomBinaryReader reader) { DomField result = new DomField(); LoaderHelper.ParseShared(reader, result); reader.BaseStream.Position = 0x12; short typeOffset = reader.ReadInt16(); reader.BaseStream.Position = typeOffset; result.GomType = reader.ReadGomType(); return(result); }
IEnumerable <IField> BuildAttributes(IEnumerable <PythonAttribute> attributes) { foreach (PythonAttribute pyAttr in attributes) { var domAttr = new DomField() { Name = pyAttr.Name, BodyRegion = pyAttr.Region, Location = pyAttr.Region.Start, ReturnType = new DomReturnType() { Name = pyAttr.Name, // FIXME: Get inferred type Namespace = Module.FullName, }, }; m_AllWrapped.Add(domAttr); yield return(domAttr); } }
public void ReadWriteFieldTest () { DomField input = new DomField (); input.Name = "TestField"; input.Location = new DomLocation (5, 10); input.Documentation = "testDocumentation"; input.Modifiers = Modifiers.Static; input.ReturnType = new DomReturnType ("System.String"); MemoryStream ms = new MemoryStream (); BinaryWriter writer = new BinaryWriter (ms); DomPersistence.Write (writer, DefaultNameEncoder, input); byte[] bytes = ms.ToArray (); DomField result = DomPersistence.ReadField (CreateReader (bytes), DefaultNameDecoder); Assert.AreEqual ("TestField", result.Name); Assert.AreEqual ("testDocumentation", result.Documentation); Assert.AreEqual (new DomLocation (5, 10), result.Location); Assert.AreEqual (Modifiers.Static, result.Modifiers); Assert.AreEqual ("System.String", result.ReturnType.FullName); }
public void ReadWriteFieldTest() { DomField input = new DomField(); input.Name = "TestField"; input.Location = new DomLocation(5, 10); input.Documentation = "testDocumentation"; input.Modifiers = Modifiers.Static; input.ReturnType = new DomReturnType("System.String"); MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); DomPersistence.Write(writer, DefaultNameEncoder, input); byte[] bytes = ms.ToArray(); DomField result = DomPersistence.ReadField(CreateReader(bytes), DefaultNameDecoder, null); Assert.AreEqual("TestField", result.Name); Assert.AreEqual("testDocumentation", result.Documentation); Assert.AreEqual(new DomLocation(5, 10), result.Location); Assert.AreEqual(Modifiers.Static, result.Modifiers); Assert.AreEqual("System.String", result.ReturnType.FullName); }
public void ReadWriteFieldTest2() { DomField input = new DomField(); input.Name = null; input.Location = DomLocation.Empty; input.Documentation = null; input.Modifiers = Modifiers.None; input.ReturnType = null; MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); DomPersistence.Write(writer, DefaultNameEncoder, input); byte[] bytes = ms.ToArray(); DomField result = DomPersistence.ReadField(CreateReader(bytes), DefaultNameDecoder, null); Assert.AreEqual(null, result.Name); Assert.AreEqual(null, result.Documentation); Assert.AreEqual(DomLocation.Empty, result.Location); Assert.AreEqual(Modifiers.None, result.Modifiers); Assert.AreEqual(null, result.ReturnType); }
public override void Visit (Field f) { var field = new DomField (); field.Name = f.MemberName.Name; field.Documentation = RetrieveDocumentation (f.Location.Row); field.Location = Convert (f.MemberName.Location); field.Modifiers = ConvertModifiers (f.ModFlags); field.ReturnType = ConvertReturnType (f.TypeName); AddAttributes (field, f.OptAttributes); field.DeclaringType = typeStack.Peek (); typeStack.Peek ().Add (field); if (f.Declarators != null) { foreach (var decl in f.Declarators) { field = new DomField (); field.Name = decl.Name.Value; field.Location = Convert (decl.Name.Location); field.Modifiers = ConvertModifiers (f.ModFlags); field.ReturnType = ConvertReturnType (f.TypeName); AddAttributes (field, f.OptAttributes); field.DeclaringType = typeStack.Peek (); typeStack.Peek ().Add (field); } } }
static void GenerateCU(XmlParsedDocument doc) { if (doc.XDocument == null || doc.XDocument.RootElement == null) { doc.Add(new Error(ErrorType.Error, 1, 1, "No root node found.")); return; } XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName("x", "Class")]; if (rootClass == null) { doc.Add(new Error(ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute.")); return; } bool isApplication = doc.XDocument.RootElement.Name.Name == "Application"; string rootNamespace, rootType, rootAssembly; XamlG.ParseXmlns(rootClass.Value, out rootType, out rootNamespace, out rootAssembly); CompilationUnit cu = new CompilationUnit(doc.FileName); doc.CompilationUnit = cu; DomRegion rootRegion = doc.XDocument.RootElement.Region; if (doc.XDocument.RootElement.IsClosed) { rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End; } DomType declType = new DomType(cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType, doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion); cu.Add(declType); DomMethod initcomp = new DomMethod(); initcomp.Name = "InitializeComponent"; initcomp.Modifiers = Modifiers.Public; initcomp.ReturnType = DomReturnType.Void; declType.Add(initcomp); DomField _contentLoaded = new DomField("_contentLoaded"); _contentLoaded.ReturnType = new DomReturnType("System.Boolean"); if (isApplication) { return; } cu.Add(new DomUsing(DomRegion.Empty, "System")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Controls")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Documents")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Input")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Media")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Media.Animation")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Shapes")); cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Controls.Primitives")); // Dictionary<string,string> namespaceMap = new Dictionary<string, string> (); // namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml"; XName nameAtt = new XName("x", "Name"); foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) { XAttribute name = el.Attributes [nameAtt]; if (name != null && name.IsComplete) { string type = ResolveType(el); if (type == null || type.Length == 0) { doc.Add(new Error(ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'.")); } else { declType.Add(new DomField(name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType(type))); } } } }
void BuildAttribute (XmlElement element) { var compUnit = this.CompilationUnit as PythonCompilationUnit; Console.WriteLine ("Attribute({0})", element.GetAttribute ("name")); var location = GetDomLocation (element); var field = new DomField (); field.Location = location; field.Name = element.GetAttribute ("name"); var mod = Modifiers.None; if (field.Name.StartsWith ("_")) mod |= Modifiers.Private; else mod |= Modifiers.Public; field.Modifiers = mod; compUnit.Add (field); }
static DomType ReadTypeInternal(BinaryReader reader, INameDecoder nameTable) { uint typeCount = ReadUInt(reader, 1000); if (typeCount > 1) { CompoundType compoundResult = new CompoundType(); while (typeCount-- > 0) { compoundResult.AddPart(ReadTypeInternal(reader, nameTable)); } return(compoundResult); } DomType result = new DomType(); ReadMemberInformation(reader, nameTable, result); // bool verbose = result.Name == "CopyDelegate"; // if (verbose) System.Console.WriteLine("read type:" + result.Name); result.TypeModifier = (TypeModifier)reader.ReadUInt32(); result.BodyRegion = ReadRegion(reader, nameTable); string compilationUnitFileName = ReadString(reader, nameTable); result.CompilationUnit = new CompilationUnit(compilationUnitFileName); result.Namespace = ReadString(reader, nameTable); result.ClassType = (ClassType)reader.ReadUInt32(); result.BaseType = ReadReturnType(reader, nameTable); // implemented interfaces long count = ReadUInt(reader, 5000); // if (verbose) System.Console.WriteLine("impl. interfaces:" + count); while (count-- > 0) { result.AddInterfaceImplementation(ReadReturnType(reader, nameTable)); } // innerTypes // if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position); count = ReadUInt(reader, 10000); // if (verbose) System.Console.WriteLine("inner types:" + count); while (count-- > 0) { DomType innerType = ReadTypeInternal(reader, nameTable); innerType.DeclaringType = result; result.Add(innerType); } // fields // if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position); count = ReadUInt(reader, 10000); // if (verbose) System.Console.WriteLine("fields:" + count); while (count-- > 0) { DomField field = ReadField(reader, nameTable); field.DeclaringType = result; result.Add(field); } // methods // if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position); count = ReadUInt(reader, 10000); // if (verbose) System.Console.WriteLine("methods:" + count); while (count-- > 0) { DomMethod method = ReadMethod(reader, nameTable); method.DeclaringType = result; result.Add(method); } // properties // if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position); count = ReadUInt(reader, 10000); // if (verbose) System.Console.WriteLine("properties:" + count); while (count-- > 0) { DomProperty property = ReadProperty(reader, nameTable); property.DeclaringType = result; result.Add(property); } // events // if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position); count = ReadUInt(reader, 10000); // if (verbose) System.Console.WriteLine("events:" + count); while (count-- > 0) { DomEvent evt = ReadEvent(reader, nameTable); evt.DeclaringType = result; result.Add(evt); } // type parameters count = ReadUInt(reader, 500); while (count-- > 0) { TypeParameter tp = ReadTypeParameter(reader, nameTable); result.AddTypeParameter(tp); } return(result); }
public override void Visit (Const f) { DomField field = new DomField (); field.Name = f.MemberName.Name; field.Documentation = RetrieveDocumentation (f.Location.Row); field.Location = Convert (f.MemberName.Location); field.Modifiers = ConvertModifiers (f.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.Fixed; field.ReturnType = ConvertReturnType (f.TypeName); AddAttributes (field, f.OptAttributes); field.DeclaringType = typeStack.Peek (); typeStack.Peek ().Add (field); }
public override void Visit (EnumMember f) { DomField field = new DomField (); field.Name = ConvertQuoted (f.MemberName.Name); field.Documentation = RetrieveDocumentation (f.Location.Row); // return types for enum fields are == null field.Location = Convert (f.MemberName.Location); field.Modifiers = MonoDevelop.Projects.Dom.Modifiers.Const | MonoDevelop.Projects.Dom.Modifiers.SpecialName| MonoDevelop.Projects.Dom.Modifiers.Public; AddAttributes (field, f.OptAttributes, f); field.DeclaringType = typeStack.Peek (); typeStack.Peek ().Add (field); }
public static DomField ReadField (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable) { DomField result = new DomField (); ReadMemberInformation (reader, nameTable, objectTable, result); result.ReturnType = ReadReturnType (reader, nameTable, objectTable); return result; }
static void GenerateCU (XmlParsedDocument doc) { if (doc.XDocument == null || doc.XDocument.RootElement == null) { doc.Add (new Error (ErrorType.Error, 1, 1, "No root node found.")); return; } XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")]; if (rootClass == null) { doc.Add (new Error (ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute.")); return; } bool isApplication = doc.XDocument.RootElement.Name.Name == "Application"; string rootNamespace, rootType, rootAssembly; XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly); CompilationUnit cu = new CompilationUnit (doc.FileName); doc.CompilationUnit = cu; DomRegion rootRegion = doc.XDocument.RootElement.Region; if (doc.XDocument.RootElement.IsClosed) rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End; DomType declType = new DomType (cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType, doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion); cu.Add (declType); DomMethod initcomp = new DomMethod (); initcomp.Name = "InitializeComponent"; initcomp.Modifiers = Modifiers.Public; initcomp.ReturnType = DomReturnType.Void; declType.Add (initcomp); DomField _contentLoaded = new DomField ("_contentLoaded"); _contentLoaded.ReturnType = new DomReturnType ("System.Boolean"); if (isApplication) return; cu.Add (new DomUsing (DomRegion.Empty, "System")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes")); cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives")); // Dictionary<string,string> namespaceMap = new Dictionary<string, string> (); // namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml"; XName nameAtt = new XName ("x", "Name"); foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) { XAttribute name = el.Attributes [nameAtt]; if (name != null && name.IsComplete) { string type = ResolveType (el); if (type == null || type.Length == 0) doc.Add (new Error (ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'.")); else declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType (type))); } } }
public void ReadWriteFieldTest2 () { DomField input = new DomField (); input.Name = null; input.Location = DomLocation.Empty; input.Documentation = null; input.Modifiers = Modifiers.None; input.ReturnType = null; MemoryStream ms = new MemoryStream (); BinaryWriter writer = new BinaryWriter (ms); DomPersistence.Write (writer, DefaultNameEncoder, input); byte[] bytes = ms.ToArray (); DomField result = DomPersistence.ReadField (CreateReader (bytes), DefaultNameDecoder); Assert.AreEqual (null, result.Name); Assert.AreEqual (null, result.Documentation); Assert.AreEqual (DomLocation.Empty, result.Location); Assert.AreEqual (Modifiers.None, result.Modifiers); Assert.AreEqual (null, result.ReturnType); }
public override void Visit (Const f) { DomField field = new DomField (); field.Name = ConvertQuoted (f.MemberName.Name); field.Documentation = RetrieveDocumentation (f.Location.Row); field.Location = Convert (f.MemberName.Location); field.Modifiers = ConvertModifiers (f.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.Const; field.ReturnType = ConvertReturnType (f.TypeName); AddAttributes (field, f.OptAttributes, f); field.DeclaringType = typeStack.Peek (); typeStack.Peek ().Add (field); if (f.Declarators != null) { foreach (var decl in f.Declarators) { field = new DomField (); field.Name = ConvertQuoted (decl.Name.Value); field.Location = Convert (decl.Name.Location); field.Modifiers = ConvertModifiers (f.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.Const; field.ReturnType = ConvertReturnType (f.TypeName); AddAttributes (field, f.OptAttributes, f); field.DeclaringType = typeStack.Peek (); typeStack.Peek ().Add (field); } } }
IEnumerable<IField> BuildAttributes(IEnumerable<PythonAttribute> attributes) { foreach (PythonAttribute pyAttr in attributes) { var domAttr = new DomField () { Name = pyAttr.Name, BodyRegion = pyAttr.Region, Location = pyAttr.Region.Start, ReturnType = new DomReturnType () { Name = pyAttr.Name, // FIXME: Get inferred type Namespace = Module.FullName, }, }; m_AllWrapped.Add (domAttr); yield return domAttr; } }