//gen  public  function
string CodeGen::genOPENATLAS_NS_RESOURCE_CLASS_PUBLIC_FUNCTION(){
    //void get
    string contentFunctions("public :\n");
    contentFunctions.append("static OpenAtlasResource* getInstance()\n{\n");
    contentFunctions.append(" static OpenAtlasResource instance;\n");
     contentFunctions.append(" return &instance;\n}\n");

    
    int arrayIndex=0;
    for(arrayIndex=0;arrayIndex< sizeof(resTypeList)/sizeof(string);arrayIndex++){
        string funName(resTypeList[arrayIndex]);
        
        funName[0] = toupper(funName[0]);
        contentFunctions.append("   // start gen function ").append(resTypeList[arrayIndex]).append("\n\n\n");
        contentFunctions.append("  void set");
        contentFunctions.append(funName);
        contentFunctions.append("(std::string resName,int resId);\n");//gen set
        
        contentFunctions.append("  int get");
        contentFunctions.append(funName);
        contentFunctions.append("(std::string resName);\n");
        
          contentFunctions.append("   // end gen function ").append(resTypeList[arrayIndex]).append("\n\n\n");
   
    }
    
    return contentFunctions;
    

}
bool SaxHandler::startElement( const QString &ns, const QString &ln, const QString &qn,
			       const QXmlAttributes &attrs )
{
    if ( !jshandler.isValid() ) {
	error = ErrorNoHandler;
	return false;
    }

    KJS::Identifier funName("startElement");
    if ( !jshandler.hasProperty(exec, funName) )
	return QXmlDefaultHandler::startElement( ns, ln, qn, attrs );

    KJS::Object fun = jshandler.get(exec, funName).toObject( exec );
    if ( !fun.implementsCall() ) {
	error = ErrorNotCallable;
	return false;
    }

    KJS::List args;
    args.append( KJS::String(ns) );
    args.append( KJS::String(ln) );
    args.append( KJS::String(qn) );
    // TODO: XmlAttributes not yet supported

    KJS::Value ret = fun.call( exec, jshandler, args );
    return ret.toBoolean( exec );
}
Exemple #3
0
 string newFunctionName()
 {
     static int funNum = 0;
     string buf;
     llvm::raw_string_ostream funName(buf);
     funName << replAnonymousFunctionName << funNum;
     ++funNum;
     return funName.str();
 }
//生成实现类
string CodeGen::genOPENATLAS_NS_RESOURCE_CLASS_PUBLIC_FUNCTION_IMPL()
{
    string contentFunImpl("//auto gen by aaptExt");
    contentFunImpl.append("#include \"OpenAtlasResource.h\"\n\n");
    
    
    int arrayIndex=0;
    for(arrayIndex=0;arrayIndex< sizeof(resTypeList)/sizeof(string);arrayIndex++){
        string funName(resTypeList[arrayIndex]);
         funName[0] = toupper(funName[0]);
        //gen  getter
        contentFunImpl.append("int ").append(OPENATLAS_NS_RESOURCE_CLASS);
        contentFunImpl.append("::get").append(funName);
        contentFunImpl.append("(std::string resName){\n");
        contentFunImpl.append("map<string, int>::iterator itr =");
                              
        contentFunImpl.append(getFunctionMapName(resTypeList[arrayIndex]));
        contentFunImpl.append(".find(resName);\n");
        contentFunImpl.append("if (itr == ").append(getFunctionMapName(resTypeList[arrayIndex])).append(".end()){\n");
        contentFunImpl.append("return 0x0000;\n}\n");
        contentFunImpl.append("return itr->second;");
        contentFunImpl.append(" \n}\n\n\n\n");
        
        //gen  getter end
        
        
        //get setter
        
        
       
        
        cout<<"//function auto gen bye AaptExt\n";
        
        contentFunImpl.append("void ").append(OPENATLAS_NS_RESOURCE_CLASS);
        contentFunImpl.append("::set").append(funName).append("(std::string resName,int resVal){\n");
        contentFunImpl.append(getFunctionMapName(resTypeList[arrayIndex]));
      
        contentFunImpl.append(".insert(std::pair<std::string, int>");
        contentFunImpl.append("(resName,resVal));\n");
 
          contentFunImpl.append(" \n}\n\n");
     
    
    }
    
    
    return contentFunImpl;
}
//procese  shared resource
string CodeGenResouceBirdge::genFunctionBridge_AnalyticsSharedResource(){
    string  content("//auto gen function  OpenAtlasResourceBridge::AnalyticsSharedResource\n");
    content.append("void  cacheSharedResource(){\n");
    CodeGen mCodeGen;
    content.append("std::string dumpline;\n");
    content.append("std::string type;\n");
//    std::istringstream streamStr(ret);
//    std::string line;
//    string  type="";
//    while (std::getline(streamStr, line)) {
//        
//        //gen class
//        if (line.find("final class") != string::npos) {
//            
//            type=getInfoType(line);
//            
//        }
//        
//        if (line.find("public static final int") != string::npos) {
    content.append(" while (std::getline(streamStr, dumpline)) {\n");
    content.append(" if (line.find(\"final class\") != string::npos) {\n\n");
    content.append("type=getIDType(line);");
    content.append("\n}\n");
    content.append(" if (line.find(\"public static final int\") != string::npos) {\n");
    int arrayIndex=0;
    for(arrayIndex=0;arrayIndex< sizeof( mCodeGen.resTypeList)/sizeof(string);arrayIndex++){
        string funName( mCodeGen.resTypeList[arrayIndex]);
        // f
        content.append(" if (!type.compare(\"").append(funName);
        content.append("\")){\n");
        funName[0] = toupper(funName[0]);
        content.append("   OpenAtlasResource::getInstance()->set").append(funName);
        content.append("(getSharedId(dumpline),getSharedValue(dumpline)");
        content.append( ");\n");
        content.append("}else\n");
        
        
    }
    content.append("{}\n" );
    content.append("}\n}\n");
    content.append("};\n\n");
    
    return content;
};
bool SaxHandler::endDocument()
{
    if ( !jshandler.isValid() ) {
	error = ErrorNoHandler;
	return false;
    }

    KJS::Identifier funName("endDocument");
    if ( !jshandler.hasProperty(exec, funName) )
	return QXmlDefaultHandler::endDocument();

    KJS::Object fun = jshandler.get(exec, funName).toObject( exec );
    if ( !fun.implementsCall() ) {
	error = ErrorNotCallable;
	return false;
    }

    KJS::Value ret = fun.call( exec, jshandler, KJS::List() );
    return ret.toBoolean( exec );
}
bool SaxHandler::characters( const QString &chars )
{
    if ( !jshandler.isValid() ) {
	error = ErrorNoHandler;
	return false;
    }

    KJS::Identifier funName("characters");
    if ( !jshandler.hasProperty(exec, funName) )
	return QXmlDefaultHandler::characters( chars );

    KJS::Object fun = jshandler.get(exec, funName).toObject( exec );
    if ( !fun.implementsCall() ) {
	error = ErrorNotCallable;
	return false;
    }

    KJS::List args;
    args.append( KJS::String(chars) );

    KJS::Value ret = fun.call( exec, jshandler, args );
    return ret.toBoolean( exec );
}
string CodeGenResouceBirdge::genFunctionBridge_getResource(){
    string  content("//auto gen function  OpenAtlasResourceBridge::getResourceId\n");
    content.append("int  getResourceId(string type,string resName){\n");
    CodeGen mCodeGen;
   
    
    
    int arrayIndex=0;
    for(arrayIndex=0;arrayIndex< sizeof( mCodeGen.resTypeList)/sizeof(string);arrayIndex++){
        string funName( mCodeGen.resTypeList[arrayIndex]);
       // f
        content.append(" if (!type.compare(\"").append(funName);
        content.append("\")){\n");
        funName[0] = toupper(funName[0]);
        content.append("return   OpenAtlasResource::getInstance()->get").append(funName);
        content.append("(resName);\n");
        content.append("};\n");
        
        
    }
    content.append("};\n\n");
    
    return content;
};