This commit is contained in:
Andreia Gaita 2011-01-31 03:38:18 +00:00
Родитель 2ef67cfd0b
Коммит ff8c9bc877
1 изменённых файлов: 0 добавлений и 442 удалений

Просмотреть файл

@ -433,242 +433,6 @@ namespace Mono.VisualC.Tools.Generator {
}
}
//void ProcessClasses (XmlDocument xmldoc)
//{
// // FIXME: Figure out how to eliminate struct noise
// XmlNodeList classes = xmldoc.SelectNodes ("/GCC_XML/Class[not(@incomplete)]" /* |/GCC_XML/Struct[not(@incomplete)]" */);
// foreach (XmlNode clas in classes) {
// var f = xmldoc.SelectSingleNode ("/GCC_XML/File[@id='" + clas.Attributes["file"].Value + "']/@name");
// if (f != null && f.Value.StartsWith ("/"))
// continue;
// if (clas.Attributes ["name"] == null || clas.Attributes ["name"].Value == "")
// continue;
// //currentUnit = new CodeUnit { ManagedNamespace = Namespace };
// string name = clas.Attributes ["name"].Value;
// Console.WriteLine ("\t\t" + name);
// string ns = GetNamespace (xmldoc.DocumentElement, clas);
// CppType currentType = new CppType (clas.Name.ToLower (), ns != null? ns + "::" + name : name);
// IEnumerable<CodeAtom> nested = null;
// // FIXME: better way to do this (GCC-XML output doesn't seem to leave much choice)
// CppType [] replaceArgs = null;
// var templated = currentType.Modifiers.OfType<CppModifiers.TemplateModifier> ().SingleOrDefault ();
// if (templated != null) {
// string baseName = currentType.ElementTypeName;
// if (CheckType (currentType, true, out nested))
// continue;
// replaceArgs = templated.Types;
// string [] ras = new string [replaceArgs.Length];
// string [] letters = new string [replaceArgs.Length];
// for (int i = 0; i < replaceArgs.Length; i++) {
// letters [i] = genericTypeArgs [i];
// ras [i] = string.Format ("{0} with {1}", replaceArgs [i].ToString (), letters [i]);
// }
// Console.Error.WriteLine ("Warning: Creating generic type {0}<{1}> from the instantiated template {2} by replacing {3} (very buggy!!!)", baseName, string.Join (",", letters), name, string.Join (", ", ras));
// name = baseName;
// } else if (CheckType (currentType, true, out nested))
// continue;
// var classAtom = new Class (name) {
// StaticCppLibrary = string.Format ("{0}.Libs.{1}", Namespace, Library)
// };
// GetContainer (xmldoc.DocumentElement, clas, Tree).Atoms.AddLast (classAtom);
// //GetContainer (xmldoc.DocumentElement, clas, currentUnit).Atoms.AddLast (classAtom);
// if (nested != null) {
// foreach (var orphan in nested)
// classAtom.Atoms.AddLast (orphan);
// }
// // add tempate type args
// if (replaceArgs != null) {
// for (int i = 0; i < replaceArgs.Length; i++)
// classAtom.TemplateArguments.Add (genericTypeArgs [i]);
// }
// // FIXME: Handle when base class name is fully qualified
// foreach (XmlNode baseNode in clas.SelectNodes ("Base")) {
// classAtom.Bases.Add (new Class.BaseClass {
// Name = find (xmldoc.DocumentElement, baseNode.Attributes ["type"]).Attributes ["name"].Value,
// Access = baseNode.Attributes ["access"].Value == "public"? Access.Public :
// baseNode.Attributes ["access"].Value == "protected"? Access.Protected :
// Access.Private,
// IsVirtual = baseNode.Attributes ["virtual"].Value == "1"
// });
// }
// //string size = clas.Attributes["size"].Value;
// var members = clas.Attributes["members"].Value.Split (' ').Where (id => !id.Equals (string.Empty)).ToArray ();
// Dictionary<MethodSignature,string> methods = new Dictionary<MethodSignature, string> ();
// foreach (string id in members) {
// XmlNode n = xmldoc.SelectSingleNode ("/GCC_XML/*[@id='" + id + "']");
// bool ctor = false;
// bool dtor = false;
// int fieldCount = 0;
// switch (n.Name) {
// case "Constructor":
// ctor = true;
// break;
// case "Destructor":
// dtor = true;
// break;
// case "Method":
// break;
// case "Field":
// CppType fieldType = findType (xmldoc.DocumentElement, n.Attributes["type"]);
// string fieldName = "field" + fieldCount++;
// if (n.Attributes ["name"] != null && n.Attributes ["name"].Value != "")
// fieldName = n.Attributes ["name"].Value;
// classAtom.Atoms.AddLast (new Field (fieldName, fieldType));
// continue;
// default:
// continue;
// }
// // Now we're processing a method...
// if (n.Attributes ["access"] == null || n.Attributes ["access"].Value != "public" ||
// (n.Attributes ["overrides"] != null && n.Attributes ["overrides"].Value != "" && !dtor) ||
// n.Attributes ["extern"] == null || n.Attributes ["extern"].Value != "1")
// continue;
// string mname = n.Attributes ["name"].Value;
// CppType retType = findType (xmldoc.DocumentElement, n.Attributes ["returns"]);
// if (replaceArgs != null) {
// for (int i = 0; i < replaceArgs.Length; i++)
// retType = replaceType (retType, replaceArgs [i], genericTypeArgs [i]);
// }
// var methodAtom = new Method (dtor? "Destruct" : mname) {
// RetType = retType,
// IsVirtual = n.Attributes ["virtual"] != null && n.Attributes ["virtual"].Value == "1",
// IsStatic = n.Attributes ["static"] != null && n.Attributes ["static"].Value == "1",
// IsConst = n.Attributes ["const"] != null && n.Attributes ["const"].Value == "1",
// IsConstructor = ctor,
// IsDestructor = dtor
// };
// if (AbiTest)
// methodAtom.Mangled = new NameTypePair<Type> { Name = n.Attributes ["mangled"].Value, Type = typeof (ItaniumAbi) };
// XmlNodeList argNodes = n.SelectNodes ("Argument");
// CppType [] argTypes = new CppType [argNodes.Count];
// int c = 0;
// foreach (XmlNode arg in argNodes) {
// string argname;
// if (arg.Attributes ["name"] == null)
// argname = "arg" + c;
// else
// argname = arg.Attributes ["name"].Value;
// CppType argtype = findType (xmldoc.DocumentElement, arg.Attributes ["type"].Value);
// if (replaceArgs != null) {
// for (int i = 0; i < replaceArgs.Length; i++)
// argtype = replaceType (argtype, replaceArgs [i], genericTypeArgs [i]);
// }
// methodAtom.Parameters.Add (new NameTypePair<CppType> { Name = argname, Type = argtype });
// argTypes [c] = argtype;
// // tee hee
// c++;
// }
// // Try to filter out duplicate methods
// MethodSignature sig = new MethodSignature (methodAtom.FormattedName, argTypes);
// string conflictingSig;
// if (methods.TryGetValue (sig, out conflictingSig)) {
// // FIXME: add comment to explain why it's commented out
// string demangled = n.Attributes ["demangled"].Value;
// Console.Error.WriteLine ("Warning: Method \"{0}\" in class {1} omitted because it conflicts with \"{2}\"", demangled, name, conflictingSig);
// methodAtom.Comment = string.Format ("FIXME:Method \"{0}\" omitted because it conflicts with \"{1}\"", demangled, conflictingSig);
// methodAtom.CommentedOut = true;
// } else
// methods.Add (sig, n.Attributes ["demangled"].Value);
// // Record unknown types in parameters and return type
// CheckType (methodAtom.RetType);
// foreach (var arg in methodAtom.Parameters)
// CheckType (arg.Type);
// // Detect if this is a property...
// // if it's const, returns a value, has no parameters, and there is no other method with the same name
// // in this class assume it's a property getter (for now?)
// if (methodAtom.IsConst && !retType.Equals (CppTypes.Void) && !methodAtom.Parameters.Any () &&
// findMethod (xmldoc.DocumentElement, members, "@id != '" + id + "' and @name = '" + mname + "'") == null) {
// var pname = methodAtom.FormattedName;
// Property propertyAtom;
// if (properties.TryGetValue (pname, out propertyAtom)) {
// propertyAtom.Getter = methodAtom;
// } else {
// propertyAtom = new Property (pname) { Getter = methodAtom };
// properties.Add (pname, propertyAtom);
// classAtom.Atoms.AddLast (propertyAtom);
// }
// continue;
// }
// // if it's name starts with "set", does not return a value, and has one arg (besides this ptr)
// // and there is no other method with the same name...
// if (mname.ToLower ().StartsWith ("set") && retType.Equals (CppTypes.Void) && methodAtom.Parameters.Count == 1 &&
// findMethod (xmldoc.DocumentElement, members, "@id != '" + id + "' and @name = '" + mname + "'") == null) {
// string getterName = "translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" +
// mname.Substring (3).TrimStart ('_').ToLower () + "'";
// string pname = methodAtom.FormattedName.Substring (3);
// Property propertyAtom = null;
// // ...AND there is a corresponding getter method that returns the right type, then assume it's a property setter
// bool doIt = false;
// if (properties.TryGetValue (pname, out propertyAtom)) {
// doIt = propertyAtom.Getter != null && propertyAtom.Getter.RetType.Equals (methodAtom.Parameters [0].Type);
// } else {
// XmlNode getter = findMethod (xmldoc.DocumentElement, members, getterName);
// doIt = (getter != null && findType (xmldoc.DocumentElement, getter.Attributes ["returns"]).Equals (methodAtom.Parameters [0].Type));
// }
// if (doIt) {
// if (propertyAtom != null) {
// propertyAtom.Setter = methodAtom;
// } else {
// propertyAtom = new Property (pname) { Setter = methodAtom };
// properties.Add (pname, propertyAtom);
// classAtom.Atoms.AddLast (propertyAtom);
// }
// // set the method's arg name to "value" so that the prop setter works right
// var valueParam = methodAtom.Parameters [0];
// valueParam.Name = "value";
// methodAtom.Parameters [0] = valueParam;
// continue;
// }
// }
// classAtom.Atoms.AddLast (methodAtom);
// }
// //SaveFile (currentUnit.WrapperToCodeDom (Provider), name);
// }
//}
Assembly Validate ()
{
var compileParams = new CompilerParameters { GenerateInMemory = true, IncludeDebugInformation = true, WarningLevel = 0, TreatWarningsAsErrors = false };
@ -749,30 +513,6 @@ namespace Mono.VisualC.Tools.Generator {
return nsname;
}
//string GetNamespace (XmlNode root, XmlNode n)
//{
// XmlNode ns = find (root, n.Attributes ["context"]);
// if (ns == null)
// return null;
// string nsname;
// if (ns.Name == "Namespace")
// nsname = ns.Attributes ["name"].Value;
// else if (ns.Name == "Class" || ns.Name == "Struct")
// nsname = new CppType (ns.Attributes ["name"].Value).ElementTypeName;
// else
// throw new NotSupportedException ("Unknown context: " + ns.Name);
// if (nsname == "::")
// return null;
// string parent = GetNamespace (root, ns);
// if (parent != null)
// return parent + "::" + nsname;
// return nsname;
//}
CodeContainer GetContainer (Entry entry, CodeContainer def)
{
string nsname;
@ -800,34 +540,6 @@ namespace Mono.VisualC.Tools.Generator {
return container;
}
//CodeContainer GetContainer (XmlNode root, XmlNode n, CodeContainer def)
//{
// XmlNode ns = find (root, n.Attributes ["context"]);
// if (ns == null)
// return def;
// string nsname;
// if (ns.Name == "Namespace")
// nsname = ns.Attributes ["name"].Value;
// else if (ns.Name == "Class" || ns.Name == "Struct")
// nsname = new CppType (ns.Attributes ["name"].Value).ElementTypeName;
// else
// throw new NotSupportedException ("Unknown context: " + ns.Name);
// if (nsname == "::")
// return def;
// CodeContainer parent = GetContainer (root, ns, def);
// CodeContainer container = parent.Atoms.OfType<CodeContainer> ().Where (a => a.Name == nsname).SingleOrDefault ();
// if (container == null) {
// container = new Namespace (nsname);
// parent.Atoms.AddLast (container);
// }
// return container;
//}
public CodeContainer GetPath (string [] pathNames)
{
return GetPath (Tree, pathNames, false);
@ -878,43 +590,6 @@ namespace Mono.VisualC.Tools.Generator {
return enumType;
}
//CppType ProcessEnum (XmlNode root, XmlNode enm)
//{
// bool hasName = false;
// string ename = "Enum" + enumCount++;
// if (enm.Attributes ["name"] != null && enm.Attributes ["name"].Value != "") {
// hasName = true;
// ename = enm.Attributes ["name"].Value;
// }
// CppType enumType = new CppType (CppTypes.Enum, ename);
// if (hasName) {
// string ns = GetNamespace (root, enm);
// if (ns != null)
// enumType = new CppType (CppTypes.Enum, ns + "::" + ename);
// }
// IEnumerable<CodeAtom> dontCare;
// if (!hasName || !CheckType (enumType, true, out dontCare)) {
// Enumeration enumAtom = new Enumeration (ename);
// foreach (XmlNode v in enm.SelectNodes ("EnumValue"))
// enumAtom.Items.Add (new Enumeration.Item { Name = v.Attributes ["name"].Value, Value = Convert.ToInt32 (v.Attributes ["init"].Value) });
// //GetContainer (root, enm, flatUnit).Atoms.AddLast (enumAtom);
// CodeContainer nested = GetContainer (root, enm, Tree);//GetContainer (root, enm, currentUnit);
// //if (hasName && !(nested is Class)) // assume it might be used by other classes
// // GetContainer (root, enm, enumerations).Atoms.AddLast (enumAtom);
// //else
// nested.Atoms.AddLast (enumAtom);
// }
// return enumType;
//}
CppType ProcessUnion (Class clas, Entry entry, List<Entry> removed)
{
string fullName = entry.name;
@ -948,58 +623,6 @@ namespace Mono.VisualC.Tools.Generator {
return unionType;
}
//CppType ProcessUnion (XmlNode root, XmlNode union)
//{
// bool hasName = false;
// string uname = "Union" + unionCount++;
// if (union.Attributes ["name"] != null && union.Attributes ["name"].Value != "") {
// hasName = true;
// uname = union.Attributes ["name"].Value;
// }
// CppType unionType = new CppType (CppTypes.Union, uname);
// if (hasName) {
// string ns = GetNamespace (root, union);
// if (ns != null)
// unionType = new CppType (CppTypes.Union, ns + "::" + uname);
// }
// IEnumerable<CodeAtom> orphans = null;
// if (!hasName || !CheckType (unionType, true, out orphans)) {
// Union unionAtom = new Union (uname);
// if (union.Attributes["members"] != null) {
// foreach (string id in union.Attributes["members"].Value.Split (' ').Where (id => !id.Equals (string.Empty))) {
// XmlNode n = root.SelectSingleNode ("/GCC_XML/*[@id = '" + id + "']");
// // FIXME: Support union constructors/destructors?
// if (n.Name != "Field")
// continue;
// Field field = new Field (n.Attributes ["name"].Value, findType (root, n.Attributes ["type"]));
// unionAtom.Atoms.AddLast (field);
// }
// }
// //GetContainer (root, union, flatUnit).Atoms.AddLast (unionAtom);
// CodeContainer nested = GetContainer (root, union, Tree);//GetContainer (root, union, currentUnit);
// //if (hasName && !(nested is Class)) // assume it might be used by other classes
// // GetContainer (root, union, unions).Atoms.AddLast (unionAtom);
// //else
// nested.Atoms.AddLast (unionAtom);
// if (orphans != null) {
// foreach (var orphan in orphans)
// unionAtom.Atoms.AddLast (orphan);
// }
// }
// return unionType;
//}
void GenerateStaticLibField ()
{
string name = "Lib_" + Library;
@ -1180,29 +803,6 @@ namespace Mono.VisualC.Tools.Generator {
return typeFound;
}
//static XmlNode find (XmlNode root, XmlAttribute att)
//{
// if (att != null)
// return find (root, att.Value);
// return null;
//}
//static XmlNode find (XmlNode root, string id)
//{
// XmlNode n = root.SelectSingleNode ("/GCC_XML/*[@id='" + id + "']");
// //if (n.Name == "Typedef")
// // return n;
// if (n.Attributes["type"] != null)
// return find (root, n.Attributes["type"].Value);
// return n;
//}
//static XmlNode findMethod (XmlNode root, string [] members, string predicate)
//{
// string isMember = "@id = '" + string.Join ("' or @id = '", members) + "'";
// return root.SelectSingleNode (string.Format ("/GCC_XML/Method[({0}) and ({1})]", predicate, isMember));
//}
CppType findType (Class clas, Entry entry, List<Entry> removed)
{
if (entry == null)
@ -1275,48 +875,6 @@ namespace Mono.VisualC.Tools.Generator {
throw new NotImplementedException ("Unknown type node: " + entry.type);
}
//CppType findType (XmlNode root, XmlAttribute att)
//{
// if (att != null)
// return findType (root, att.Value);
// return CppTypes.Void;
//}
//CppType findType (XmlNode root, string id)
//{
// return findType (root, id, new CppType ());
//}
//CppType findType (XmlNode root, string id, CppType modifiers)
//{
// XmlNode n = root.SelectSingleNode ("/GCC_XML/*[@id='" + id + "']");
// string name = "unknown";
// if (n.Attributes ["name"] != null)
// name = n.Attributes ["name"].Value;
// switch (n.Name) {
// case "ArrayType": return findType (root, n.Attributes ["type"].Value, modifiers.Modify (CppModifiers.Array));
// case "PointerType": return findType (root, n.Attributes ["type"].Value, modifiers.Modify (CppModifiers.Pointer));
// case "ReferenceType": return findType (root, n.Attributes ["type"].Value, modifiers.Modify (CppModifiers.Reference));
// case "CvQualifiedType":
// return findType (root, n.Attributes ["type"].Value,
// modifiers.Modify (n.Attributes ["const"] != null && n.Attributes ["const"].Value == "1"? CppModifiers.Const : CppModifiers.Volatile));
// case "Typedef": return findType (root, n.Attributes ["type"].Value, modifiers);
// case "FundamentalType": return modifiers.CopyTypeFrom (new CppType (name));
// case "Class": return modifiers.CopyTypeFrom (new CppType (CppTypes.Class, name));
// case "Struct": return modifiers.CopyTypeFrom (new CppType (CppTypes.Struct, name));
// case "Union": return modifiers.CopyTypeFrom (ProcessUnion (root, n));
// case "Enumeration": return modifiers.CopyTypeFrom (ProcessEnum (root, n));
// // FIXME: support function pointers betters
// case "FunctionType": return modifiers.CopyTypeFrom (CppTypes.Void);
// case "MethodType": return modifiers.CopyTypeFrom (CppTypes.Void);
// }
// throw new NotImplementedException ("Unknown type node: " + n.Name);
//}
string fname (string name)
{
return name.Replace ("<", "_").Replace (">", "_").Replace (":", "_").Replace ("*", "_").Replace (",", "_").Replace (" ", "_") + "." + Provider.FileExtension;