@ -25,10 +25,10 @@ namespace Mono.VisualC.Tools.Generator {
@@ -25,10 +25,10 @@ namespace Mono.VisualC.Tools.Generator {
public static readonly string [ ] genericTypeArgs = new string [ ] { "T" , "U" , "V" , "W" , "X" , "Y" , "Z" } ;
public string Source { get ; set ; }
public string Dir { get ; set ; }
public string Dir { get ; set ; }
public bool AbiTest { get ; set ; }
public bool Validation { get ; set ; }
public string Library { get ; set ; }
public string Library { get ; set ; }
private string nspace ;
public string Namespace {
@ -51,33 +51,24 @@ namespace Mono.VisualC.Tools.Generator {
@@ -51,33 +51,24 @@ namespace Mono.VisualC.Tools.Generator {
//private CodeUnit currentUnit;
//private CodeUnit enumerations;
//private CodeUnit unions;
private Dictionary < string , Property > properties ;
private Dictionary < string , Property > properties ;
private int enumCount = 0 ;
private int unionCount = 0 ;
private HashSet < string > fileList ;
public static void Main ( string [ ] args )
public static void Main ( string [ ] args )
{
bool help = false ;
Generator gen = new Generator ( ) ;
gen . Validation = true ;
var p = new OptionSet ( ) {
{ "h|?|help" , "Show this help message" , v = > help = v ! = null } ,
{ "f=" , "Set the xml outputted by gccxml to parse" , v = > gen . Source = v } ,
{ "o=" , "Set the output directory" , v = > gen . Dir = v } ,
{ "ns=" , "Set the namespace" , v = > gen . Namespace = v } ,
{ "lib=" , "Additional reference libraries" , v = > gen . Library = v } ,
{ "lang=" , "Language of the outputted library (C#, VB, etc)" , v = > gen . Provider = CodeDomProvider . CreateProvider ( v ) } ,
{ "testabi" , "Test the Itanium name mangling abi against the bindings" , v = > gen . AbiTest = v ! = null } ,
{ "n" , "Don't validate" , v = > gen . Validation = ! ( v ! = null ) } ,
} ;
var p = new OptionSet { { "h|?|help" , "Show this help message" , v = > help = v ! = null } , { "f=" , "Set the xml outputted by gccxml to parse" , v = > gen . Source = v } , { "o=" , "Set the output directory" , v = > gen . Dir = v } , { "ns=" , "Set the namespace" , v = > gen . Namespace = v } , { "lib=" , "Additional reference libraries" , v = > gen . Library = v } , { "lang=" , "Language of the outputted library (C#, VB, etc)" , v = > gen . Provider = CodeDomProvider . CreateProvider ( v ) } , { "testabi" , "Test the Itanium name mangling abi against the bindings" , v = > gen . AbiTest = v ! = null } , { "n" , "Don't validate" , v = > gen . Validation = ! ( v ! = null ) } } ;
List < string > extra = null ;
try {
extra = p . Parse ( args ) ;
} catch ( OptionException ) {
extra = p . Parse ( args ) ;
} catch ( OptionException ) {
Console . WriteLine ( "Try `generator --help' for more information." ) ;
return ;
}
@ -107,16 +98,14 @@ namespace Mono.VisualC.Tools.Generator {
@@ -107,16 +98,14 @@ namespace Mono.VisualC.Tools.Generator {
if ( gen . Provider = = null )
gen . Provider = new CSharpCodeProvider ( ) ;
gen . Options = new CodeGeneratorOptions ( ) {
BlankLinesBetweenMembers = false
} ;
gen . Options = new CodeGeneratorOptions { BlankLinesBetweenMembers = false } ;
gen . Run ( ) ;
}
public Generator ( )
{
Classes = new Dictionary < string , string > ( ) ;
Classes = new Dictionary < string , string > ( ) ;
UnknownTypes = new HashSet < string > ( ) ;
Tree = new CodeUnit { ManagedNamespace = Namespace } ;
@ -189,25 +178,20 @@ namespace Mono.VisualC.Tools.Generator {
@@ -189,25 +178,20 @@ namespace Mono.VisualC.Tools.Generator {
XmlNode node = xmldoc . SelectSingleNode ( "/GCC_XML" ) ;
Entry . typelist = new Dictionary < string , Dictionary < string , Entry > > ( ) ;
Entry . idlist = new Dictionary < string , Entry > ( ) ;
return Preprocess ( node ) ;
return Preprocess ( node ) ;
}
int typecount = 0 ;
List < Entry > Preprocess ( XmlNode parent )
List < Entry > Preprocess ( XmlNode parent )
{
List < Entry > data = new List < Entry > ( ) ;
foreach ( XmlNode node in parent . ChildNodes ) {
Dictionary < string , string > entry = new Dictionary < string , string > ( ) ;
Dictionary < string , string > entry = new Dictionary < string , string > ( ) ;
foreach ( XmlAttribute att in node . Attributes ) {
entry [ att . Name ] = att . Value ;
}
Entry e = new Entry ( ) {
id = "" ,
type = node . Name ,
name = "" ,
reftype = "" ,
attributes = entry } ;
Entry e = new Entry { id = "" , type = node . Name , name = "" , reftype = "" , attributes = entry } ;
if ( entry . ContainsKey ( "name" ) )
e . id = e . name = entry [ "name" ] ;
@ -242,17 +226,12 @@ namespace Mono.VisualC.Tools.Generator {
@@ -242,17 +226,12 @@ namespace Mono.VisualC.Tools.Generator {
void PreprocessClasses ( List < Entry > entries )
{
entries . RemoveAll ( o = > ( o . type = = "Class" | | o . type = = "Struct" ) & &
( o . IsTrue ( "incomplete" ) | |
! o . HasValue ( "name" ) | |
( Entry . idlist [ o [ "file" ] ] . name . StartsWith ( "/" ) )
) ) ;
entries . RemoveAll ( o = > ( o . type = = "Class" | | o . type = = "Struct" ) & & ( o . IsTrue ( "incomplete" ) | | ! o . HasValue ( "name" ) | | ( Entry . idlist [ o [ "file" ] ] . name . StartsWith ( "/" ) ) ) ) ;
}
void ProcessClasses ( List < Entry > entries )
{
foreach ( Entry clas in entries . Where ( o = > o . type = = "Class" | | o . type = = "Struct" ) )
{
foreach ( Entry clas in entries . Where ( o = > o . type = = "Class" | | o . type = = "Struct" ) ) {
//onsole.WriteLine (clas.name);
//bool bb;
//if (clas.name.StartsWith ("QGraphicsBlurEffect"))
@ -266,7 +245,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -266,7 +245,7 @@ namespace Mono.VisualC.Tools.Generator {
// FIXME: better way to do this (GCC-XML output doesn't seem to leave much choice)
CppType [ ] replaceArgs = null ;
CppType [ ] replaceArgs = null ;
var templated = currentType . Modifiers . OfType < CppModifiers . TemplateModifier > ( ) . SingleOrDefault ( ) ;
if ( templated ! = null ) {
clas . isTemplate = true ;
@ -276,25 +255,19 @@ namespace Mono.VisualC.Tools.Generator {
@@ -276,25 +255,19 @@ namespace Mono.VisualC.Tools.Generator {
replaceArgs = templated . Types ;
string [ ] ras = new string [ replaceArgs . Length ] ;
string [ ] letters = new string [ replaceArgs . Length ] ;
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 ) ,
clas . computedName ,
string . Join ( ", " , ras ) ) ;
Console . Error . WriteLine ( "Warning: Creating generic type {0}<{1}> from the instantiated template {2} by replacing {3} (very buggy!!!)" , baseName , string . Join ( "," , letters ) , clas . computedName , string . Join ( ", " , ras ) ) ;
clas . computedName = baseName ;
} else if ( IsCreated ( currentType , true , out nested ) )
continue ;
clas . atom = new Class ( clas . computedName ) {
StaticCppLibrary = string . Format ( "{0}.Libs.{1}" , Namespace , Library )
} ;
clas . atom = new Class ( clas . computedName ) { StaticCppLibrary = string . Format ( "{0}.Libs.{1}" , Namespace , Library ) } ;
GetContainer ( clas , Tree ) . Atoms . AddLast ( clas . atom ) ;
@ -311,13 +284,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -311,13 +284,7 @@ namespace Mono.VisualC.Tools.Generator {
// FIXME: Handle when base class name is fully qualified
foreach ( Entry bs in clas . children . Where ( o = > o . type = = "Base" ) ) {
clas . Class . Bases . Add ( new Class . BaseClass {
Name = bs . Base . name ,
Access = bs . CheckValue ( "access" , "public" ) ? Access . Public :
bs . CheckValue ( "access" , "protected" ) ? Access . Protected :
Access . Private ,
IsVirtual = bs . IsTrue ( "virtual" )
} ) ;
clas . Class . Bases . Add ( new Class . BaseClass { Name = bs . Base . name , Access = bs . CheckValue ( "access" , "public" ) ? Access . Public : bs . CheckValue ( "access" , "protected" ) ? Access . Protected : Access . Private , IsVirtual = bs . IsTrue ( "virtual" ) } ) ;
}
Dictionary < MethodSignature , string > methods = new Dictionary < MethodSignature , string > ( ) ;
@ -349,9 +316,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -349,9 +316,7 @@ namespace Mono.VisualC.Tools.Generator {
// Now we're processing a method...
if ( ! member . CheckValue ( "access" , "public" ) | |
( member . HasValue ( "overrides" ) & & ! dtor ) | |
! member . IsTrue ( "extern" ) )
if ( ! member . CheckValue ( "access" , "public" ) | | ( member . HasValue ( "overrides" ) & & ! dtor ) | | ! member . IsTrue ( "extern" ) )
continue ;
string mname = member . name ;
@ -363,18 +328,11 @@ namespace Mono.VisualC.Tools.Generator {
@@ -363,18 +328,11 @@ namespace Mono.VisualC.Tools.Generator {
retType = replaceType ( retType , replaceArgs [ i ] , genericTypeArgs [ i ] ) ;
}
var methodAtom = new Method ( dtor ? "Destruct" : mname ) {
RetType = retType ,
IsVirtual = member . IsTrue ( "virtual" ) ,
IsStatic = member . IsTrue ( "static" ) ,
IsConst = member . IsTrue ( "const" ) ,
IsConstructor = ctor ,
IsDestructor = dtor
} ;
var methodAtom = new Method ( dtor ? "Destruct" : mname ) { RetType = retType , IsVirtual = member . IsTrue ( "virtual" ) , IsStatic = member . IsTrue ( "static" ) , IsConst = member . IsTrue ( "const" ) , IsConstructor = ctor , IsDestructor = dtor } ;
if ( AbiTest )
methodAtom . Mangled = new NameTypePair < Type > { Name = member . attributes [ "mangled" ] , Type = typeof ( ItaniumAbi ) } ;
methodAtom . Mangled = new NameTypePair < Type > { Name = member . attributes [ "mangled" ] , Type = typeof ( ItaniumAbi ) } ;
List < CppType > argTypes = new List < CppType > ( ) ;
int c = 0 ;
@ -421,8 +379,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -421,8 +379,7 @@ namespace Mono.VisualC.Tools.Generator {
// 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 ( ) & &
clas . Members . Where ( o = > o . name = = mname ) . FirstOrDefault ( ) = = null ) {
if ( methodAtom . IsConst & & ! retType . Equals ( CppTypes . Void ) & & ! methodAtom . Parameters . Any ( ) & & clas . Members . Where ( o = > o . name = = mname ) . FirstOrDefault ( ) = = null ) {
var pname = methodAtom . FormattedName ;
Property propertyAtom ;
@ -439,8 +396,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -439,8 +396,7 @@ namespace Mono.VisualC.Tools.Generator {
// 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 & &
clas . Members . Where ( o = > o . name = = mname ) . FirstOrDefault ( ) = = null ) {
if ( mname . ToLower ( ) . StartsWith ( "set" ) & & retType . Equals ( CppTypes . Void ) & & methodAtom . Parameters . Count = = 1 & & clas . Members . Where ( o = > o . name = = mname ) . FirstOrDefault ( ) = = null ) {
string getterName = mname . Substring ( 3 ) . TrimStart ( '_' ) . ToLower ( ) ;
@ -715,13 +671,8 @@ namespace Mono.VisualC.Tools.Generator {
@@ -715,13 +671,8 @@ namespace Mono.VisualC.Tools.Generator {
Assembly Validate ( )
{
var compileParams = new CompilerParameters {
GenerateInMemory = true ,
IncludeDebugInformation = true ,
WarningLevel = 0 ,
TreatWarningsAsErrors = false
} ;
compileParams . ReferencedAssemblies . Add ( typeof ( CppLibrary ) . Assembly . Location ) ;
var compileParams = new CompilerParameters { GenerateInMemory = true , IncludeDebugInformation = true , WarningLevel = 0 , TreatWarningsAsErrors = false } ;
compileParams . ReferencedAssemblies . Add ( typeof ( CppLibrary ) . Assembly . Location ) ;
CompilerResults results = Provider . CompileAssemblyFromFile ( compileParams , fileList . ToArray ( ) ) ;
var errors = results . Errors . Cast < CompilerError > ( ) . Where ( e = > ! e . IsWarning ) ;
@ -750,8 +701,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -750,8 +701,7 @@ namespace Mono.VisualC.Tools.Generator {
void TestAbi ( Assembly assembly )
{
var classes = assembly . GetExportedTypes ( ) . Select ( t = > new { Name = Regex . Replace ( t . Name , "\\`.$" , "" ) , Interface = t . GetNestedType ( "I" + t . Name ) } )
. Where ( k = > k . Interface ! = null ) ;
var classes = assembly . GetExportedTypes ( ) . Select ( t = > new { Name = Regex . Replace ( t . Name , "\\`.$" , "" ) , Interface = t . GetNestedType ( "I" + t . Name ) } ) . Where ( k = > k . Interface ! = null ) ;
var abi = new ItaniumAbi ( ) ;
foreach ( var klass in classes ) {
@ -759,7 +709,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -759,7 +709,7 @@ namespace Mono.VisualC.Tools.Generator {
foreach ( var method in klass . Interface . GetMethods ( ) ) {
var testAttribute = ( AbiTestAttribute ) method . GetCustomAttributes ( typeof ( AbiTestAttribute ) , false ) . FirstOrDefault ( ) ;
var testAttribute = ( AbiTestAttribute ) method . GetCustomAttributes ( typeof ( AbiTestAttribute ) , false ) . FirstOrDefault ( ) ;
string expected = testAttribute . MangledName ;
string actual = abi . GetMangledMethodName ( klass . Name , method ) ;
@ -784,8 +734,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -784,8 +734,7 @@ namespace Mono.VisualC.Tools.Generator {
Entry ns = entry . Namespace ;
if ( ns . type = = "Namespace" )
nsname = ns . name ;
else if ( ns . type = = "Class" | | ns . type = = "Struct" )
nsname = ns . name ; else if ( ns . type = = "Class" | | ns . type = = "Struct" )
nsname = new CppType ( ns . name ) . ElementTypeName ;
else
throw new NotSupportedException ( "Unknown context: " + ns . type ) ;
@ -833,8 +782,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -833,8 +782,7 @@ namespace Mono.VisualC.Tools.Generator {
Entry ns = entry . Namespace ;
if ( ns . type = = "Namespace" )
nsname = ns . name ;
else if ( ns . type = = "Class" | | ns . type = = "Struct" )
nsname = ns . name ; else if ( ns . type = = "Class" | | ns . type = = "Struct" )
nsname = new CppType ( ns . name ) . ElementTypeName ;
else
throw new NotSupportedException ( "Unknown context: " + ns . type ) ;
@ -922,7 +870,8 @@ namespace Mono.VisualC.Tools.Generator {
@@ -922,7 +870,8 @@ namespace Mono.VisualC.Tools.Generator {
enumAtom . Items . Add ( new Enumeration . Item { Name = m . name , Value = Convert . ToInt32 ( m . attributes [ "init" ] ) } ) ;
}
CodeContainer nested = GetContainer ( entry , Tree ) ; //GetContainer (root, enm, currentUnit);
CodeContainer nested = GetContainer ( entry , Tree ) ;
//GetContainer (root, enm, currentUnit);
nested . Atoms . AddLast ( enumAtom ) ;
}
@ -987,7 +936,8 @@ namespace Mono.VisualC.Tools.Generator {
@@ -987,7 +936,8 @@ namespace Mono.VisualC.Tools.Generator {
unionAtom . Atoms . AddLast ( field ) ;
}
CodeContainer nested = GetContainer ( entry , Tree ) ; //GetContainer (root, union, currentUnit);
CodeContainer nested = GetContainer ( entry , Tree ) ;
//GetContainer (root, union, currentUnit);
nested . Atoms . AddLast ( unionAtom ) ;
if ( orphans ! = null ) {
@ -1058,15 +1008,8 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1058,15 +1008,8 @@ namespace Mono.VisualC.Tools.Generator {
var ccu = new CodeCompileUnit ( ) ;
var ns = new CodeNamespace ( Namespace ) ;
var cls = new CodeTypeDeclaration ( "Libs" ) {
TypeAttributes = TypeAttributes . NotPublic | TypeAttributes . Sealed | TypeAttributes . Class ,
IsPartial = true ,
IsClass = true
} ;
var field = new CodeMemberField ( typeof ( CppLibrary ) , Library ) {
Attributes = MemberAttributes . Public | MemberAttributes . Static ,
InitExpression = new CodeObjectCreateExpression ( typeof ( CppLibrary ) , new CodePrimitiveExpression ( Library ) )
} ;
var cls = new CodeTypeDeclaration ( "Libs" ) { TypeAttributes = TypeAttributes . NotPublic | TypeAttributes . Sealed | TypeAttributes . Class , IsPartial = true , IsClass = true } ;
var field = new CodeMemberField ( typeof ( CppLibrary ) , Library ) { Attributes = MemberAttributes . Public | MemberAttributes . Static , InitExpression = new CodeObjectCreateExpression ( typeof ( CppLibrary ) , new CodePrimitiveExpression ( Library ) ) } ;
cls . Members . Add ( field ) ;
ns . Types . Add ( cls ) ;
ccu . Namespaces . Add ( ns ) ;
@ -1075,7 +1018,8 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1075,7 +1018,8 @@ namespace Mono.VisualC.Tools.Generator {
}
void GenerateUnknownTypeStubs ( )
{ / *
{
/ *
var ccu = new CodeCompileUnit ( ) ;
var ns = new CodeNamespace ( Namespace ) ;
@ -1092,7 +1036,6 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1092,7 +1036,6 @@ namespace Mono.VisualC.Tools.Generator {
ccu . Namespaces . Add ( ns ) ;
SaveFile ( ccu , "UnknownTypes" ) ;
* /
var ukt = UnknownTypes . ToArray ( ) ;
foreach ( var unknownType in ukt ) {
CodeContainer container = Tree ;
@ -1111,9 +1054,9 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1111,9 +1054,9 @@ namespace Mono.VisualC.Tools.Generator {
foreach ( var param in type . Modifiers . OfType < CppModifiers . TemplateModifier > ( ) ) {
if ( param . Types ! = null ) {
foreach ( var t in param . Types )
atom . TemplateArguments . Add ( genericTypeArgs [ i + + ] ) ;
atom . TemplateArguments . Add ( genericTypeArgs [ i + + ] ) ;
} else
atom . TemplateArguments . Add ( genericTypeArgs [ i + + ] ) ;
atom . TemplateArguments . Add ( genericTypeArgs [ i + + ] ) ;
}
if ( orphans ! = null ) {
@ -1151,16 +1094,12 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1151,16 +1094,12 @@ namespace Mono.VisualC.Tools.Generator {
static CppType replaceType ( CppType inType , CppType toReplace , string tn )
{
// FIXME: The order of some modifiers is not significant.. is this a problem?
if ( /* inType.ElementType == toReplace.ElementType && */
( ( inType . Namespaces ! = null & & toReplace . Namespaces ! = null & & inType . Namespaces . SequenceEqual ( toReplace . Namespaces ) ) | |
inType . Namespaces = = null & & toReplace . Namespaces = = null ) & &
inType . ElementTypeName = = toReplace . ElementTypeName & &
inType . Modifiers . StartsWith ( toReplace . Modifiers ) )
if ( /* inType.ElementType == toReplace.ElementType && */ ( ( inType . Namespaces ! = null & & toReplace . Namespaces ! = null & & inType . Namespaces . SequenceEqual ( toReplace . Namespaces ) ) | | inType . Namespaces = = null & & toReplace . Namespaces = = null ) & & inType . ElementTypeName = = toReplace . ElementTypeName & & inType . Modifiers . StartsWith ( toReplace . Modifiers ) )
return new CppType ( CppTypes . Typename , tn , inType . Modifiers . Skip ( toReplace . Modifiers . Count ) . ToArray ( ) ) ;
foreach ( var tempMod in inType . Modifiers . OfType < CppModifiers . TemplateModifier > ( ) )
for ( int i = 0 ; i < tempMod . Types . Length ; i + + )
tempMod . Types [ i ] = replaceType ( tempMod . Types [ i ] , toReplace , tn ) ;
tempMod . Types [ i ] = replaceType ( tempMod . Types [ i ] , toReplace , tn ) ;
return inType ;
}
@ -1184,7 +1123,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1184,7 +1123,7 @@ namespace Mono.VisualC.Tools.Generator {
bool typeFound = false ;
type . ElementType = CppTypes . Unknown ;
for ( int i = 0 ; i < type . Modifiers . Count ; i + + ) {
if ( type . Modifiers [ i ] ! = CppModifiers . Template )
if ( type . Modifiers [ i ] ! = CppModifiers . Template )
type . Modifiers . RemoveAt ( i ) ;
}
@ -1196,9 +1135,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1196,9 +1135,7 @@ namespace Mono.VisualC.Tools.Generator {
place = GetPath ( type . Namespaces ) ;
if ( place ! = null ) {
typeFound = place . Atoms . OfType < Class > ( ) . Where ( c = > c . Name = = type . ElementTypeName ) . Any ( ) | |
place . Atoms . OfType < Enumeration > ( ) . Where ( e = > e . Name = = type . ElementTypeName ) . Any ( ) | |
place . Atoms . OfType < Union > ( ) . Where ( u = > u . Name = = type . ElementTypeName ) . Any ( ) ;
typeFound = place . Atoms . OfType < Class > ( ) . Where ( c = > c . Name = = type . ElementTypeName ) . Any ( ) | | place . Atoms . OfType < Enumeration > ( ) . Where ( e = > e . Name = = type . ElementTypeName ) . Any ( ) | | place . Atoms . OfType < Union > ( ) . Where ( u = > u . Name = = type . ElementTypeName ) . Any ( ) ;
var sameNamedNamespace = place . Atoms . OfType < Namespace > ( ) . Where ( ns = > ns . Name = = type . ElementTypeName ) . SingleOrDefault ( ) ;
if ( sameNamedNamespace ! = null ) {
@ -1278,29 +1215,38 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1278,29 +1215,38 @@ namespace Mono.VisualC.Tools.Generator {
string name = entry . name = = "" ? "unknown" : entry . name ;
switch ( entry . type ) {
case "ArrayType" : return findType ( entry . Base , modifiers . Modify ( CppModifiers . Array ) ) ;
case "PointerType" : return findType ( entry . Base , modifiers . Modify ( CppModifiers . Pointer ) ) ;
case "ReferenceType" : return findType ( entry . Base , modifiers . Modify ( CppModifiers . Reference ) ) ;
case "ArrayType" :
return findType ( entry . Base , modifiers . Modify ( CppModifiers . Array ) ) ;
case "PointerType" :
return findType ( entry . Base , modifiers . Modify ( CppModifiers . Pointer ) ) ;
case "ReferenceType" :
return findType ( entry . Base , modifiers . Modify ( CppModifiers . Reference ) ) ;
case "CvQualifiedType" :
return findType ( entry . Base ,
modifiers . Modify ( ( from c in entry . attributes
return findType ( entry . Base , modifiers . Modify ( ( from c in entry . attributes
where c . Key = = "const" & & c . Value = = "1"
select CppModifiers . Const )
. DefaultIfEmpty ( CppModifiers . Volatile )
. First ( ) ) ) ;
case "Typedef" : return findType ( entry . Base , 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 ( entry ) ) ;
case "Enumeration" : return modifiers . CopyTypeFrom ( ProcessEnum ( entry ) ) ;
select CppModifiers . Const ) . DefaultIfEmpty ( CppModifiers . Volatile ) . First ( ) ) ) ;
case "Typedef" :
return findType ( entry . Base , 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 ( entry ) ) ;
case "Enumeration" :
return modifiers . CopyTypeFrom ( ProcessEnum ( entry ) ) ;
// FIXME: support function pointers betters
case "FunctionType" : return modifiers . CopyTypeFrom ( CppTypes . Void ) ;
case "MethodType" : return modifiers . CopyTypeFrom ( CppTypes . Void ) ;
case "Constructor" : return CppTypes . Unknown ;
case "FunctionType" :
return modifiers . CopyTypeFrom ( CppTypes . Void ) ;
case "MethodType" :
return modifiers . CopyTypeFrom ( CppTypes . Void ) ;
case "Constructor" :
return CppTypes . Unknown ;
}
throw new NotImplementedException ( "Unknown type node: " + entry . type ) ;
@ -1350,7 +1296,7 @@ namespace Mono.VisualC.Tools.Generator {
@@ -1350,7 +1296,7 @@ namespace Mono.VisualC.Tools.Generator {
string fname ( string name )
{
return name . Replace ( "<" , "_" ) . Replace ( ">" , "_" ) . Replace ( ":" , "_" ) . Replace ( "*" , "_" ) . Replace ( "," , "_" ) . Replace ( " " , "_" ) + "." + Provider . FileExtension ;
return name . Replace ( "<" , "_" ) . Replace ( ">" , "_" ) . Replace ( ":" , "_" ) . Replace ( "*" , "_" ) . Replace ( "," , "_" ) . Replace ( " " , "_" ) + "." + Provider . FileExtension ;
}
}
}