void CXBindingsGenerator::DoCreateChildDependencyList(CXBindingsArrayString& dependencyList , const std::string& parentType , CXBindingsChildInfo& childInfo , CXBindings& grammar , CXBindingsGeneratorOptions& options )
{
	CXBindingsStringStringMap& properties = childInfo.properties;

	std::string type = properties["type" ];

	//wxLogMessage( "\t Type is : ") + type  ;

	if( type.empty() )
		return;

	type = GetRealType( type , options );

	CXBindingsArrayString::iterator it = std::find( dependencyList.begin() , dependencyList.end(), type );
	if( it != dependencyList.end() || type ==parentType) 
		return;
	

//	CXBindingsStringStringMap& types = m_genfile->GetTypeInfo().GetTypes();
//	CXBindingsStringStringMap::iterator it = types.find( type );
//
//	if( it != types.end() )
//		return;
	
	//wxLogMessage( "\t Type (2) is : ") + type  ;
	
	// else find the objectInfo related to this type in the CXBindingsInterpreterInfo */
	CXBindingsInfo& info = grammar.GetInfo();
	CXBindingsArrayString genOrder = info.GetGeneration().GetObjects();
	CXBindingsArrayString templates = info.GetGeneration().GetTemplates();

	for( unsigned int i = 0; i < genOrder.size() ; ++i ){

		CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects;
		CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]];

		for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) {
			std::string objName = objectsInfo[j].properties["name" ];

			objName = GetRealType( objName , options );

			if( objName == type )  {
				DoCreateObjectDependencyList( dependencyList , objectsInfo[j] , grammar , options );
				return;
			}
		}
		
	}

	dependencyList.push_back( type );
}
void CXBindingsCppObjectsGenerator::DoGetIncludesListFor( CXBindingsArrayString& local_includes , CXBindingsArrayString& object_imports ,CXBindingsArrayString& currentObjects , CXBindingsFileInfo& file  , CXBindingsGeneratorOptions& options)
{
    for( unsigned int i = 0; i < file.bases.size() ; ++i ) {
        std::string pName = file.bases[i].first;

        CXBindingsArrayString::iterator it = std::find( currentObjects.begin(), currentObjects.end(), pName );
        if( it == currentObjects.end() ) {
            currentObjects.push_back(pName);
            DoGetIncludesListFor( local_includes, object_imports , currentObjects , file.bases[i].second , options );
            it = std::find( currentObjects.begin(), currentObjects.end(), pName );
            currentObjects.erase(it);
        }

        std::string inc = "#include \"" + pName + ".h\"\n" ;
        it = std::find( local_includes.begin(), local_includes.end(), inc );
        if( it == local_includes.end() ) {
            local_includes.push_back("#include \"" + pName + ".h\"\n") ;
            pName = GetRealType(pName,options);
            object_imports.push_back("class " + pName + ";\n") ;
        }
    }

    for( unsigned int i = 0; i < file.dependencies.size() ; ++i )
    {
        if( m_objectFiles[file.dependencies[i].second] != (options.ns + "_globals") && !m_objectFiles[file.dependencies[i].second].empty() )  {
            std::string inc = "#include \"" + file.dependencies[i].second + ".h\"\n";

            CXBindingsArrayString::iterator it = std::find( local_includes.begin(), local_includes.end(), inc );
            if( it == local_includes.end() ) {

                it = std::find( local_includes.begin(), local_includes.end(), file.dependencies[i].first );
                if( it == local_includes.end() ) {
                    currentObjects.push_back(file.dependencies[i].first);

                    CXBindingsFileInfoMap::iterator oi = m_objectInfos.find(file.dependencies[i].second);
                    if( oi != m_objectInfos.end() )
                        DoGetIncludesListFor( local_includes, object_imports , currentObjects , oi->second , options );

                    it = std::find( currentObjects.begin(), currentObjects.end(), file.dependencies[i].first );
                    if( it != currentObjects.end() )
                        currentObjects.erase(it);
                }

                local_includes.push_back( "#include \"" + file.dependencies[i].second + ".h\"\n"  ) ;
                std::string dependency = GetRealType( file.dependencies[i].second, options );
                object_imports.push_back( "class " + dependency + ";\n");
            }
        }
    }
}
void CXBindingsGenerator::DoCreateContainerDependencyList( CXBindingsArrayString& dependencyList  , const std::string& realName, CXBindingsChildContainerInfo& containerInfo , CXBindings& grammar , CXBindingsGeneratorOptions& options )
{
	CXBindingsArrayGrammarRuleInfo& crules = containerInfo.rules;

	for( unsigned int j = 0; j < crules.size() ; ++j ) {
		std::string type = crules[j].type.content;
		std::string make = crules[j].make;

		type = GetRealType( type , options );
		CXBindingsArrayString::iterator it = std::find( dependencyList.begin() , dependencyList.end(), type );	
		if( (make == "import"|| make == "child_enumerator" || make == "typedef" ) && it != dependencyList.end() )   {
			dependencyList.push_back( type );
		}
	}
	
	CXBindingsArrayGrammarCategoryInfo& categories = containerInfo.categories;

	for( unsigned int i = 0; i < categories.size() ; ++i )
		DoCreateCategoryDependencyList( dependencyList , realName , categories[i] , grammar , options );

	CXBindingsArrayGrammarChildInfo& childs = containerInfo.childs;

	for( unsigned int j = 0; j < childs.size() ; ++j ) {
		DoCreateChildDependencyList( dependencyList , realName , childs[j] , grammar , options );
	}
}
CXBindingsArrayString CXBindingsGenerator::DoCreateDependencyList( CXBindingsGeneratorOptions& options )
{
	/* for each element in the info object of the grammar */
	CXBindings& grammar = m_interpreterInfo.grammar;
	CXBindingsInfo& info = grammar.GetInfo();
	CXBindingsArrayString genOrder = info.GetGeneration().GetObjects();
	CXBindingsArrayString templates = info.GetGeneration().GetTemplates();
	
	/* The first thing to do is to estabilsh the generation objects dependecy list
	 * So that object will be generated in the right order...
	 */
	CXBindingsArrayString dependencies;
	
	for( unsigned int i = 0; i < genOrder.size() ; ++i ){

		CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects;
		CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]];

		for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) {
			DoCreateObjectDependencyList( dependencies , objectsInfo[j] , grammar , options );
			
			std::string name = objectsInfo[j].properties["name" ];

			name = GetRealType( name , options );

			if( templates[i] == "global_scope")   
				m_objectFiles[name] = options.ns + "_globals" ;
			else
				m_objectFiles[name] = name;
		}
	}
	
	return dependencies;
}
Пример #5
0
void gl_InitializeActorLights()
{
	for(unsigned int i=0;i<LightAssociations.Size();i++)
	{
		const PClass * ti = PClass::FindClass(LightAssociations[i].ActorName());
		if (ti)
		{
			ti = GetRealType(ti);
			AActor * defaults = GetDefaultByType(ti);
			if (defaults)
			{
				FInternalLightAssociation * iasso = new FInternalLightAssociation(&LightAssociations[i]);

				if (!defaults->lightassociations)
				{
					TDeletingArray<FInternalLightAssociation*> *p =new TDeletingArray<FInternalLightAssociation*>;
					defaults->lightassociations = p;
					AssoDeleter.Push(p);
				}
				TDeletingArray<FInternalLightAssociation *> * lights = gl_GetActorLights(defaults);
				if (iasso->Light()==NULL)
				{
					// The definition was not valid.
					delete iasso;
				}
				else
				{
					lights->Push(iasso);
				}
			}
		}
	}
	// we don't need the parser data for the light associations anymore
	LightAssociations.Clear();
	LightAssociations.ShrinkToFit();

	StateLights.Resize(ParsedStateLights.Size()+1);
	for(unsigned i=0; i<ParsedStateLights.Size();i++)
	{
		if (ParsedStateLights[i] != NAME_None)
		{
			StateLights[i] = (FLightDefaults*)-1;	// something invalid that's not NULL.
			for(unsigned int j=0;j<LightDefaults.Size();j++)
			{
				if (LightDefaults[j]->GetName() == ParsedStateLights[i])
				{
					StateLights[i] = LightDefaults[j];
					break;
				}
			}
		}
		else StateLights[i] = NULL;
	}
	StateLights[StateLights.Size()-1] = NULL;	// terminator
	ParsedStateLights.Clear();
	ParsedStateLights.ShrinkToFit();
}
void CXBindingsGenerator::DoCreateObjectDependencyList( CXBindingsArrayString& dependencyList , CXBindingsObjectInfo& objectInfo , CXBindings& grammar , CXBindingsGeneratorOptions& options )
{
	// Object dependencies are defined by their childs, child containers and categories.
	// Dependencies names are extracted from the related rule information for each object.
	
	CXBindingsStringStringMap& properties = objectInfo.properties;

	if( properties["name"].empty()  )
		CXB_THROW( "Error object with no name cannot continue...")  ;

	//wxLogMessage( "\t Calculating object dependencies for object ") + properties["name" ]  ;

	std::string realName = properties["name" ];
	realName = GetRealType( realName  , options );
	
	CXBindingsArrayString::iterator it = std::find( dependencyList.begin() , dependencyList.end(), realName );
		
	if( it != dependencyList.end() )
		return;

	// STEP 1 : CHECK CHILD CONTAINERS AND RULES
	//wxLogMessage( "\t STEP 1 : Checking for existing child containers dependencies ... ")  ;
        CXBindingsArrayGrammarChildContainerInfo& ccInfo = objectInfo.childs;
	
	//std::string msg = std::string::Format( "\t\t Found %d childcontainers...") , ccInfo.size()  ;
	//wxLogMessage( msg );
	
	for( unsigned int i = 0; i < ccInfo.size() ; ++i ) 
		DoCreateContainerDependencyList( dependencyList , realName , ccInfo[i] , grammar , options );
		
	//wxLogMessage( "\t END STEP 1")  ;
	
	// STEP 2 : CHECK CATEGORIES AND RULES
	//wxLogMessage( "\t STEP 2 : Checking for existing dependencies in the child categories ... ")  ;
        CXBindingsArrayGrammarCategoryInfo& catInfo = objectInfo.categories;
	
	//msg = std::string::Format( "\t\t Found %d categories...") , catInfo.size()  ;
	//wxLogMessage( msg );
	
	for( unsigned int i = 0; i < catInfo.size() ; ++i ) 
		DoCreateCategoryDependencyList( dependencyList , realName , catInfo[i] , grammar , options );
	
	CXBindingsArrayGrammarChildInfo& childs = objectInfo.childInfos;
	for( unsigned int j = 0; j < childs.size() ; ++j ) {
		DoCreateChildDependencyList( dependencyList , realName , childs[j] , grammar , options );
	}
		
	//wxLogMessage( "\t END STEP 2")  ;

	// Add me in the dependencyList

	dependencyList.push_back( realName );

}
CXBindingsFileInfo CXBindingsCppObjectsGenerator::DoGenerateRuleCodeFor( CXBindingsRuleInfo& ruleInfo , CXBindings& , CXBindingsGeneratorOptions& options )
{
    CXBindingsFileInfo res;

    //wxLogMessage( "\t\t Rule make is : ") + ruleInfo.make  ;
    //wxLogMessage( "\t\t Rule name is : ") + ruleInfo.name.content  ;
    //wxLogMessage( "\t\t Rule type is : ") + ruleInfo.type.content  ;



    CXBindingsStringStringMap& types = m_genfile->GetTypeInfo().GetTypes();
    std::string realType = ruleInfo.type.content;
    std::string typeTemplate = ruleInfo.type.stemplate;

    CXBindingsGeneratorFileTemplate* arrayTemplate = NULL;

    CXBindingsStringStringMap::iterator it = types.find( realType );

    realType = GetRealType( realType  , options );

    std::string typeExt = realType;
    if( !IsKnownType( realType ) )
        typeExt = GetRealType( realType , options );

    if( it != types.end() ) {
        realType = it->second;
        typeExt = realType;
    }

    std::string savedType = typeExt;

    if( typeTemplate == "array")    {
        typeExt = "std::vector< " + typeExt + " >" ;
        arrayTemplate = m_genfile->FindTemplate( "array_addons")  ;
    }


    if( ruleInfo.make == "import")    {

        // We have to add here all informations about the object from which this one is derived
        // this information is contained in the realType variable

        /* for each element in the info object of the grammar */
        CXBindings& grammar = m_interpreterInfo.grammar;
        CXBindingsInfo& info = grammar.GetInfo();
        CXBindingsArrayString genOrder = info.GetGeneration().GetObjects();

        /* The first thing to do is to estabilsh the generation objects dependecy list
         * So that object will be generated in the right order...
         */
        CXBindingsArrayString dependencies;

        for( unsigned int i = 0; i < genOrder.size() ; ++i ) {

            CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects;
            CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]];

            for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) {

                std::string name = objectsInfo[j].properties["name" ];

                name = GetRealType( name , options );

                if( name == savedType )  {
                    std::pair< std::string , CXBindingsFileInfo> inf( name , m_objectInfos[name] );
                    res.bases.push_back( inf );

                    return res;
                }

            }
        }

        std::pair< std::string , CXBindingsFileInfo> inf( savedType , m_objectInfos[savedType] );
        res.bases.push_back( inf );

        return res;
    }

    std::string nameExt = ruleInfo.name.content;
    nameExt = GetPropertyExtension( nameExt , options );
    SetMacro( "name_extension" , nameExt)  ;

    SetMacro( "name" , ruleInfo.name.content)  ;
    SetMacro( "type" , typeExt)  ;
    SetMacro( "real_type" , savedType)  ;
    SetMacro( "variable" , ruleInfo.variable.content)  ;

    CXBindingsGeneratorFileTemplate* rTemplate = m_genfile->FindTemplate( ruleInfo.make );

    if( rTemplate == NULL )
        CXB_THROW( "Error cannot find template : " + ruleInfo.make)  ;

    if( ruleInfo.make == "property" || ruleInfo.make ==  "attribute" )    {
        std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt );
        res.properties.push_back( mpair );
    }

    if( ruleInfo.make == "property" || ruleInfo.make == "attribute" || ruleInfo.make == "variant_accessor"  || ruleInfo.make == "variant_array_accessor")  {
        std::pair< std::string , std::string > mpair( ruleInfo.name.content , savedType );
        res.dependencies.push_back( mpair );
    }

    CXBindingsArrayGrammarGeneratorFileObjectPart& objects = rTemplate->GetObjects();

    for( unsigned int i = 0; i < objects.size() ; ++i ) {

        std::string content = objects[i].GetContent();
        DoReplaceMacros( content );

        if( objects[i].GetFile() =="header")
        {
            if( objects[i].GetPermission() == "private")
                res.headerPrivateInfo += content;
            else if( objects[i].GetPermission() == "protected")
                res.headerProtectedInfo += content;
            else
                res.headerPublicInfo += content;
        }
        else
            res.srcInfo += content;
    }

    if( arrayTemplate != NULL ) {
        CXBindingsArrayGrammarGeneratorFileObjectPart& objectsArray = arrayTemplate->GetObjects();

        for( unsigned int i = 0; i < objectsArray.size() ; ++i ) {

            std::string content = objectsArray[i].GetContent();
            DoReplaceMacros( content );

            if( objectsArray[i].GetFile() =="header")
            {
                if( objectsArray[i].GetPermission() == "private")
                    res.headerPrivateInfo += content;
                else if( objectsArray[i].GetPermission() == "protected")
                    res.headerProtectedInfo += content;
                else
                    res.headerPublicInfo += content;
            }
            else
                res.srcInfo += content;
        }
    }

    return res;

}
bool CXBindingsCppObjectsGenerator::DoGenerateCode( CXBindingsGeneratorOptions& options )
{
    /* for each element in the info object of the grammar */
    CXBindings& grammar = m_interpreterInfo.grammar;
    CXBindingsInfo& info = grammar.GetInfo();
    CXBindingsArrayString genOrder = info.GetGeneration().GetObjects();
    CXBindingsArrayString templates = info.GetGeneration().GetTemplates();

    /* The first thing to do is to estabilsh the generation objects dependecy list
     * So that object will be generated in the right order...
     */
    CXBindingsArrayString dependencies = DoCreateDependencyList( options );

    /** @todo here generate object in their dependencies order is this really usefull .??? */
    for( unsigned int k = 0; k < dependencies.size() ; ++k ) {
        for( unsigned int i = 0; i < genOrder.size() ; ++i ) {

            CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects;
            CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]];

            for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) {

                std::string realName = objectsInfo[j].properties["name"];
                realName = GetRealType( realName , options );

                if( realName == dependencies[k] )  {
                    DoGenerateCodeFor( objectsInfo[j] , grammar , options );
                    break;
                }
            }
        }
    }

    /** The last step is to generate the globals file and the other files for given objects */

    std::string hdrDir = options.genDir + "/include" ;
    std::string srcDir = options.genDir + "/src" ;
    CXBindingsMakeDirRecursively(hdrDir+"/") ;
    CXBindingsMakeDirRecursively(srcDir+"/") ;

    /* First generate globals file definitions */
    std::string global_file = GetMacro( "global_file")  ;
    std::string global_file_src = GetMacro( "global_file_src")  ;
    std::string filename = options.ns + "_globals" ;
    SetMacro( "filename" , filename) ;
    SetMacro( "globals_code" , m_globalInfo.headerPublicInfo) ;
    SetMacro( "globals_code_src" , m_globalInfo.srcInfo) ;

    DoReplaceMacros( global_file );
    DoReplaceMacros( global_file_src );
    SaveFile( hdrDir + "/" + filename + ".h"  , global_file );
    SaveFile( srcDir + "/" + filename + ".cpp"  , global_file_src) ;

    // Generate additional files
    CXBindingsArrayGrammarGeneratorFileAddin& addins = m_genfile->GetAddins();
    for( unsigned int i = 0; i < addins.size() ; ++i ) {
        std::string fname = addins[i].GetName();
        std::string header = addins[i].GetHeader();
        std::string source = addins[i].GetSource();

        if( !header.empty() ) {
            DoReplaceMacros( header );
            SaveFile( hdrDir + "/" + fname + ".h"  , header)  ;
        }
        if( !source.empty() ) {
            DoReplaceMacros( source );
            SaveFile( srcDir + "/" + fname + ".cpp"  , source) ;
        }
    }

    // Save generated objects code
    CXBindingsFileInfoMap::iterator it = m_objectInfos.begin();
    for( ; it != m_objectInfos.end() ; ++it )
    {
        if( m_objectFiles[it->first] !=filename && !m_objectFiles[it->first].empty() )
        {
            std::string srcFile = srcDir + "/" + m_objectFiles[it->first] + ".cpp" ;
            std::string hdrFile = hdrDir + "/" + m_objectFiles[it->first] + ".h" ;

            if( !it->second.srcInfo.empty() ) {
                SaveFile( srcFile , it->second.srcInfo );
            }

            SaveFile( hdrFile , it->second.headerPublicInfo );
        }

    }
    return false;
}
void CXBindingsCppObjectsGenerator::DoGenerateCodeFor(
    CXBindingsObjectInfo& objectInfo ,
    CXBindings& grammar ,
    CXBindingsGeneratorOptions& options )
{

    // STEP 0 : APPEND OBJECT PROPERTIES IN THE MACRO MAP
    CXBindingsStringStringMap& properties = objectInfo.properties;

    //wxLogMessage( "\t STEP O : Calculating Object preliminar informations : ") + properties["name" ]  ;

    //wxLogMessage( "\t\t STEP O.1 : Appending Object macro : ") + properties["name" ]  ;

    if( properties["name"].empty() )
        CXB_THROW( "Error object with no name cannot continue...")  ;

    std::string objectName = properties["name" ];
    objectName = GetRealType( objectName , options );

    std::string upName;
    upName += objectName;
    to_upper( upName );

    SetMacro( "object" , objectName);
    SetMacro( "OBJECT" , upName) ;

    // @todo here the file is not preoprely set
    /* First set up some macros for the given file */
    // filename macros
    std::string filename = m_objectFiles[objectName];
    SetMacro( "filename" , filename) ;

    // STEP 1 : CHECK CHILD CONTAINERS AND RULES
    //wxLogMessage( "\t STEP 1 : Checking for existing rules in the child containers ... ")  ;
    CXBindingsArrayGrammarChildContainerInfo& ccInfo = objectInfo.childs;

    //std::string msg = std::string::Format( "\t\t Found %d childcontainers...") , ccInfo.size()  ;
    //wxLogMessage( msg );

    CXBindingsFileInfo objectFileInfo;

    for( unsigned int i = 0; i < ccInfo.size() ; ++i ) {
        objectFileInfo += DoGenerateChildContainerCodeFor( ccInfo[i] , grammar , options );
    }

    //wxLogMessage( "\t END STEP 1")  ;

    // STEP 2 : CHECK CATEGORIES AND RULES
    //wxLogMessage( "\t STEP 2 : Checking for existing rules in the child categories ... ")  ;
    CXBindingsArrayGrammarCategoryInfo& catInfo = objectInfo.categories;

    //msg = std::string::Format( "\t\t Found %d categories...") , catInfo.size()  ;
    //wxLogMessage( msg );

    for( unsigned int i = 0; i < catInfo.size() ; ++i ) {
        objectFileInfo += DoGenerateCategoryCodeFor( catInfo[i] , grammar , options );
    }

    //wxLogMessage( "\t END STEP 2")  ;

    CXBindingsArrayGrammarChildInfo& childs = objectInfo.childInfos;
    for( unsigned int j = 0; j < childs.size() ; ++j ) {

        CXBindingsFileInfo ruleContent = DoGenerateChildRuleCodeFor( childs[j] , grammar , options );
        objectFileInfo += ruleContent;
    }

    //wxLogMessage( "\t STEP 3 : create additional object macros for the given object if exists ... ")  ;

    // Append codes in the childs_header_public_code
    std::string childs_header_public_code = objectFileInfo.headerPublicInfo;
    SetMacro( "childs_header_public_code" , childs_header_public_code);

    std::string childs_header_private_code;
    childs_header_private_code = objectFileInfo.headerPrivateInfo;
    SetMacro( "childs_header_private_code" , childs_header_private_code) ;

    std::string childs_header_protected_code;
    childs_header_protected_code = objectFileInfo.headerProtectedInfo,
    SetMacro( "childs_header_protected_code" , childs_header_protected_code) ;

    std::string childs_src_code = objectFileInfo.srcInfo;
    SetMacro( "childs_src_code" , childs_src_code) ;

    // Finally build the missing macrods for doc comments and other parameters info
    CXBindingsFileParametersMacros params;

    /* once all parameters list have been generated, we need to create the macros of derived
     * objects. This is very important in order to treat the inherit template from the various
     * rules/
     */
    std::string object_bases;
    std::string object_bases_default_ctor;
    std::string object_bases_init_list;
    std::string object_bases_copy_list;
    std::string object_bases_list;

    for( unsigned int i = 0; i < objectFileInfo.bases.size() ; ++i ) {
        std::string pName = objectFileInfo.bases[i].first;
        CXBindingsFileInfo& inf = objectFileInfo.bases[i].second;

        pName = GetRealType( pName , options );

        CXBindingsFileParametersMacros localp;
        localp.parameters_eqeqop_list = params.parameters_eqeqop_list;
        DoCreateParametersMacrosFor( inf , localp , options );

        params.parameters_doc_list += localp.parameters_doc_list;
        params.parameters_ctor_list += localp.parameters_ctor_list;
        params.parameters_eqop_list += localp.parameters_eqop_list;
        params.parameters_eqeqop_list = localp.parameters_eqeqop_list;

        //wxLogMessage( localp.parameters_doc_list );

        if( i != 0 ) {
            object_bases += " , public "  + pName;
            object_bases_list += " , "  + pName;
            object_bases_default_ctor += ",\n\t\t" + pName + "()" ;
            object_bases_copy_list += ",\n\t\t" + pName + "(rhs)" ;
            object_bases_init_list += ",\n\t\t" + pName + "(" + localp.parameters_ctor_list2 + ")" ;
        }
        else {
            object_bases += " public "  + pName;
            object_bases_list += pName;
            object_bases_default_ctor += "\t\t" + pName + "()" ;
            object_bases_copy_list += "\t\t" + pName + "(rhs)" ;
            object_bases_init_list += " \t\t" + pName + "(" + localp.parameters_ctor_list2 + ")" ;
        }
    }

    if( object_bases.empty() ) {
        object_bases = "public $(base_object)" ;
        object_bases_default_ctor = "\t\t$(base_object)()" ;
        object_bases_copy_list = "\t\t$(base_object)()" ;
        object_bases_list = "$(base_object)" ;
        object_bases_init_list = "\t\t$(base_object)()" ;
    }

    SetMacro( "object_bases" , object_bases ) ;
    SetMacro( "object_bases_list" , object_bases_list) ;
    SetMacro( "object_bases_default_ctor" , object_bases_default_ctor) ;
    SetMacro( "object_bases_init_list" , object_bases_init_list) ;
    SetMacro( "object_bases_copy_list" , object_bases_copy_list) ;

    DoCreateParametersMacrosFor( objectFileInfo , params , options );

    if( params.parameters_eqeqop_list.empty() )
        params.parameters_eqeqop_list = "\t\ttrue";

    SetMacro( "parameters_doc_list" , params.parameters_doc_list ) ;
    SetMacro( "parameters_ctor_list" , params.parameters_ctor_list ) ;
    SetMacro( "parameters_dtor_list" , params.parameters_dtor_list ) ;
    SetMacro( "parameters_init_list" , params.parameters_init_list ) ;
    SetMacro( "parameters_default_init_list" , params.parameters_default_init_list ) ;
    SetMacro( "parameters_copy_list" , params.parameters_copy_list ) ;
    SetMacro( "parameters_eqop_list" , params.parameters_eqop_list ) ;
    SetMacro( "parameters_eqeqop_list" , params.parameters_eqeqop_list ) ;
    SetMacro( "parameters_property_table" , params.parameters_property_table ) ;

    if( params.parameters_doc_list.empty() ) {
        SetMacro( "object_ctors" , "$(object_simple_ctor_header)" )  ;
    } else {
        SetMacro( "object_ctors" , "$(object_complex_ctor_header)" )  ;
    }
    /* The next step is very important !
     * First we have to establish all direct dependencies in the given property list
     * and all dependencies of the given bases.
     * Once this is done, we can get the dependency list and include list to put in the
     * source file*/

    std::string local_includes = "#include \"" + options.ns + "_globals"  + ".h\"\n" ;
    std::string object_imports;

    CXBindingsArrayString lc;
    CXBindingsArrayString oi;

    CXBindingsArrayString currObj;
    currObj.push_back(objectName);
    DoGetIncludesListFor(lc,oi,currObj,objectFileInfo,options);

    for( unsigned int i = 0; i < lc.size() ; ++i ) {
        local_includes += lc[i];
        object_imports += oi[i];
    }

    if( filename != options.ns + "_globals")
    {
        object_imports += "class " + objectName + ";\n" ;
    }

    SetMacro( "local_includes" , local_includes) ;
    SetMacro( "object_imports" , object_imports) ;
    //wxLogMessage( "\t\t\t local_includes is :") + local_includes  ;
    //wxLogMessage( "\t\t\t object_imports is :") + object_imports  ;


    //wxLogMessage( "\t END STEP 3...")  ;

    // STEP 4 : CHECK EXISTING RULES IN THE GIVEN OBJECT
    //wxLogMessage( "\t STEP 4 : Checking for existing rules in the object ... ")  ;
    CXBindingsArrayGrammarRuleInfo& rules = objectInfo.rules;

    //msg = std::string::Format( "\t\t Found %d rules...") , rules.size()  ;
    //wxLogMessage( msg );

    CXBindingsFileInfo FinalInfo;

    for( unsigned int i = 0; i < rules.size() ; ++i ) {

        CXBindingsFileInfo ruleContent = DoGenerateRuleCodeFor( rules[i] , grammar , options );
        FinalInfo += ruleContent;
    }

    if( filename ==options.ns + "_globals")
        m_globalInfo += objectFileInfo;

    objectFileInfo.headerPublicInfo = stdEmptyString;
    objectFileInfo.headerProtectedInfo = stdEmptyString;
    objectFileInfo.headerPrivateInfo = stdEmptyString;
    objectFileInfo.srcInfo = stdEmptyString;

    FinalInfo += objectFileInfo;
    //std::cout << objectName << std::endl;
    m_objectInfos[objectName] = FinalInfo;

    //wxLogMessage( "\t END STEP 4...")  ;
}
CXBindingsHandlerFileInfo CXBindingsCppHandlersGenerator::DoGenerateRuleCodeFor( CXBindingsRuleInfo& ruleInfo , CXBindings& grammar , CXBindingsGeneratorOptions& options )
{
	CXBindingsHandlerFileInfo res;

	//wxLogMessage( "\t\t Rule make is : ") + ruleInfo.make  ;
	//wxLogMessage( "\t\t Rule name is : ") + ruleInfo.name.content  ;
	//wxLogMessage( "\t\t Rule type is : ") + ruleInfo.type.content  ;
	
	CXBindingsStringStringMap& types = m_genfile->GetTypeInfo().GetTypes();
	std::string realType = ruleInfo.type.content;
	
	//wxLogMessage( "\t\t Real type is : ") + realType  ;
	
	if( ruleInfo.make =="object")  
		realType = ruleInfo.name.content;
	
	std::string typeTemplate = ruleInfo.type.stemplate;
	CXBindingsStringStringMap::iterator it = types.find( realType );

	std::string typeExt = GetRealType( realType  , options );
//	if( !IsKnownType( realType ) )
//		typeExt = GetRealType( realType  , options );
//	
	if( it != types.end() ) {
		typeExt = it->second;
		//typeExt = realType;
	}
	
	//wxLogMessage( "\t\t Real type is : ") + realType  ;
	
	if( boost::contains(realType,":") )  
		realType = after_first(realType,':')  ; 
	
	//wxLogMessage( "\t\t Real type is : ") + realType  ;
	
	std::string savedType = realType;
	// Find here type corrspondances
	std::string rType = FindRealTypeFor( realType );
	
	if( ruleInfo.make =="object")  
		rType = "object" ;
	
	if( ruleInfo.make =="child_enumerator")  
		rType = "enum" ;

	if( typeTemplate == "array")    {
		//realType = "std::vector< ") + realType + wxT(" >" ;
		rType = "array"  + rType;
	}
	
	
	//wxLogMessage( "Registering type for : ") + ruleInfo.name.content + " type is :") + realType + wxT(" ") + rType + wxT(" rule make is :"  + ruleInfo.make  ;
	m_types[ruleInfo.name.content] = rType;

	if( ruleInfo.make == "import")    {
		
		// We have to add here all informations about the object from which this one is derived
		// this information is contained in the realType variable

		/* for each element in the info object of the grammar */
		CXBindings& grammar = m_interpreterInfo.grammar;
		CXBindingsInfo& info = grammar.GetInfo();
		CXBindingsArrayString genOrder = info.GetGeneration().GetObjects();

		/* The first thing to do is to estabilsh the generation objects dependecy list
		 * So that object will be generated in the right order...
		 */
		CXBindingsArrayString dependencies;

		for( unsigned int i = 0; i < genOrder.size() ; ++i ){

			CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects;
			CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]];

			for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) {

				std::string name = objectsInfo[j].properties["name" ];

				name = GetRealType( name , options );
				//wxLogMessage( "Checking bases for") + name + "-") + typeExt + wxT("-"  + realType  ;
				if( name == typeExt )  {
					std::pair< std::string , CXBindingsHandlerFileInfo> inf( name , m_objectInfos[name] );
					res.bases.push_back( inf );
					//wxLogMessage( "Adding bases for") + name + "-") + typeExt + wxT("-"  + realType  ;
					return res;
				}

			}
		}

		std::pair< std::string , CXBindingsHandlerFileInfo> inf( typeExt , m_objectInfos[typeExt] );
		res.bases.push_back( inf );
		return res;
	}

	
	if( ruleInfo.make == "property")    {
		std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt );
		res.properties.push_back( mpair );
	}
	else if( ruleInfo.make == "attribute")    {
		std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt );
		res.attributes.push_back( mpair );
	}
	
	if( ruleInfo.make == "property" || ruleInfo.make == "attribute" || ruleInfo.make == "variant_accessor"  || ruleInfo.make == "variant_array_accessor")   {
		std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt );
		res.dependencies.push_back( mpair );
	}

	return res;
	
}
void CXBindingsCppHandlersGenerator::DoGenerateCodeFor( CXBindingsObjectInfo& objectInfo , CXBindings& grammar , CXBindingsGeneratorOptions& options )
{

	// STEP 0 : APPEND OBJECT PROPERTIES IN THE MACRO MAP
	CXBindingsStringStringMap& properties = objectInfo.properties;
	
    if( properties["name"].empty() ) 
		CXB_THROW( "Error object with no name cannot continue...")  ;

	std::string objectName = properties["name" ];
	objectName = GetRealType( objectName , options );
	
	std::string upName; 
	upName += objectName;
	to_upper( upName );
	
	SetMacro( "object" , objectName );
	SetMacro( "OBJECT" , upName );

	// @todo here the file is not preoprely set
	/* First set up some macros for the given file */
	// filename macros
	std::string filename = objectName + "XmlHandler" ;
	SetMacro( "filename" , filename) ;

	// STEP 1 : CHECK CHILD CONTAINERS AND RULES
    CXBindingsArrayGrammarChildContainerInfo& ccInfo = objectInfo.childs;
	CXBindingsHandlerFileInfo objectFileInfo;
	
	for( unsigned int i = 0; i < ccInfo.size() ; ++i ) {
	 	objectFileInfo += DoGenerateChildContainerCodeFor( ccInfo[i] , grammar , options ); 	
	}
		
	// STEP 2 : CHECK CATEGORIES AND RULES
    CXBindingsArrayGrammarCategoryInfo& catInfo = objectInfo.categories;
	for( unsigned int i = 0; i < catInfo.size() ; ++i ) {
		objectFileInfo += DoGenerateCategoryCodeFor( catInfo[i] , grammar , options );
	}
		
	CXBindingsArrayGrammarChildInfo& childs = objectInfo.childInfos;
	for( unsigned int j = 0; j < childs.size() ; ++j ) {

		CXBindingsHandlerFileInfo ruleContent = DoGenerateChildRuleCodeFor( childs[j] , grammar , options );
		objectFileInfo += ruleContent;
	}

	// Finally build the missing macrods for doc comments and other parameters info
	CXBindingsHandlerFileParametersMacros params;
	
	/* once all parameters list have been generated, we need to create the macros of derived
	 * objects. This is very important in order to treat the inherit template from the various
	 * rules/
	 */
	for( unsigned int i = 0; i < objectFileInfo.bases.size() ; ++i ) {
		std::string pName = objectFileInfo.bases[i].first;
		CXBindingsHandlerFileInfo& inf = objectFileInfo.bases[i].second;

		CXBindingsHandlerFileParametersMacros localp;
		DoCreateParametersMacrosFor( inf , localp , options );

		params += localp;
	}
	
	DoCreateParametersMacrosFor( objectFileInfo , params , options );

	SetMacro( "objects_attribute_readers" , params.attribute_readers) ;
	SetMacro( "objects_attribute_writers" , params.attribute_writers) ;
	SetMacro( "objects_property_readers" , params.property_readers) ;
	SetMacro( "objects_property_writers" , params.property_writers) ;
	
	
	/* The next step is very important ! 
	 * First we have to establish all direct dependencies in the given property list
	 * and all dependencies of the given bases.
	 * Once this is done, we can get the dependency list and include list to put in the 
	 * source file*/
	
	std::string local_includes;
	std::string object_imports;
	
	CXBindingsArrayString lc;
	CXBindingsArrayString currObj;
	currObj.push_back(objectName);
	DoGetIncludesListFor(lc,currObj,objectFileInfo,options);
	
	for( unsigned int i = 0; i < lc.size() ; ++i ) {
		local_includes += lc[i];
	}
	
	SetMacro( "local_includes" , local_includes) ;
	//wxLogMessage( "\t\t\t local_includes is :") + local_includes  ;

		
	//wxLogMessage( "\t END STEP 3...")  ;

	// STEP 4 : CHECK EXISTING RULES IN THE GIVEN OBJECT
	//wxLogMessage( "\t STEP 4 : Checking for existing rules in the object ... ")  ;
	CXBindingsArrayGrammarRuleInfo& rules = objectInfo.rules;
	
	//msg = std::string::Format( "\t\t Found %d rules...") , rules.size()  ;
	//wxLogMessage( msg );

	CXBindingsHandlerFileInfo FinalInfo;
	
	if( filename ==options.ns + "_globals")   {
		//wxLogMessage( "Object is a typedef or an enumeration, no handler needs to be generated for.") ;
		return;
	}
	
	CXBindingsGeneratorFileTemplate* rTemplate = m_genfile->FindTemplate( "object")  ;

	if( rTemplate == NULL )
		CXB_THROW( "Error cannot find template object")  ;
	
	std::string objectNodeName = properties["name" ];
	boost::replace_all(objectNodeName,"Type","");

	SetMacro( "object_node_name" , objectNodeName) ;
	
	CXBindingsArrayGrammarGeneratorFileObjectPart& objects = rTemplate->GetObjects();

	for( unsigned int i = 0; i < objects.size() ; ++i ) {
		
		std::string content = objects[i].GetContent();
		DoReplaceMacros( content );

		if( objects[i].GetFile() =="header")   
		{
			FinalInfo.headerInfo += content;
		}
		else
			FinalInfo.srcInfo += content;
		
		//wxLogMessage( "\t\t\t Generated rule content is : ") + content  ;
	}
	
	FinalInfo += objectFileInfo;
	m_objectInfos[objectName] = FinalInfo;

	//wxLogMessage( "\t END STEP 4...")  ;
}