bool FileProcess::LoadLogicClass(std::string strFile) { //////////////////////////////////////////////////// tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument(); if (NULL == doc) { return false; } doc->LoadFile(strFile.c_str()); tinyxml2::XMLElement* root = doc->RootElement(); auto classElement = root->FirstChildElement("Class"); std::string strIObjectPath = classElement->Attribute("Path"); auto nodeElement = classElement->FirstChildElement(); if (nodeElement) { while (true) { std::string strID = nodeElement->Attribute("Id"); std::string sqlToWrite = "CREATE TABLE `" + strID + "` (\n"; sqlToWrite += "\t`ID` varchar(128) NOT NULL,\n"; sqlToWrite += "\tPRIMARY KEY (`ID`)\n"; sqlToWrite += ") ENGINE=InnoDB DEFAULT CHARSET=utf8;\n"; fwrite(sqlToWrite.c_str(), sqlToWrite.length(), 1, mysqlClassWriter); // 读取父节点内容 if (!LoadClass(strRelativePath + strIObjectPath, strID)) { return false; } // 读取自己节点内容 std::string strPath = nodeElement->Attribute("Path"); if (!LoadClass(strRelativePath + strPath, strID)) { return false; } fwrite("\n", 1, 1, mysqlClassWriter); if (nodeElement == classElement->LastChildElement()) { break; } nodeElement++; } } delete doc; return true; }
/* *1. Load class from dex file 1. *2. Link class: a. Load and link the super b. link methods: 1. direct methods a. MethodArrays? or use hash set 2. virtual methods a. use MethodArrays b. copy the father's virtual methods to this array TODO 3. interface c. link fiedls * */ Class* ClassLoader::DefineClass(std::string& className) { const DexFile::ClassDefItem* cls_def_ = NULL; DexFile* cls_dex_file_ = NULL; Class* ret = NULL; // iterator over all the dex files to find the className for (std::vector<DexFile*>::iterator it = dex_files_.begin(); it != dex_files_.end(); ++it) { DexFile* dex_file = *it; cls_def_ = dex_file->LoadClassFromDex(className.c_str()); if (cls_def_ != NULL) { cls_dex_file_ = dex_file; break; } } /*Find the class, if not find , throw no class find exception*/ if (cls_def_ == NULL) { printf("ERROR: class not found for %s", className.c_str()); } ret = LoadClass(cls_dex_file_, cls_def_); return ret; }
void CScriptEnvTest::LoadExtension() { HMODULE hDll = ::LoadLibrary(_T("HTML5i.dll")); ASSERT_TRUE(NULL != hDll); DllGetClassObjectFunc fnDllGetClassObject = (DllGetClassObjectFunc) ::GetProcAddress(hDll, "DllGetClassObject"); CComPtr<ITypeLib> spTypeLib; ASSERT_HRESULT_SUCCEEDED(::LoadTypeLib(_T("HTML5i.dll"), &spTypeLib)); ASSERT_TRUE(NULL != fnDllGetClassObject); LoadClass(fnDllGetClassObject, _T("Context2D"), CLSID_Context2D); LoadClass(fnDllGetClassObject, _T("ContextWebGL"), CLSID_ContextWebGL); }
/* * Entry point. */ int main(int argc, char ** argv) { JavaVM *vm = 0; JNIEnv *env = 0; char *jarfile = 0; char *classname = 0; char *s = 0; char *main_class = NULL; jstring mainClassName; jclass mainClass; jmethodID mainID; jobjectArray mainArgs; int ret; InvocationFunctions ifn; jlong start, end; char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN]; char ** original_argv = argv; /* * Error message to print or display; by default the message will * only be displayed in a window. */ char * message = "Fatal exception occurred. Program will exit."; jboolean messageDest = JNI_FALSE; if (getenv("_JAVA_LAUNCHER_DEBUG") != 0) { _launcher_debug = JNI_TRUE; printf("----_JAVA_LAUNCHER_DEBUG----\n"); } /* * Make sure the specified version of the JRE is running. * * There are three things to note about the SelectVersion() routine: * 1) If the version running isn't correct, this routine doesn't * return (either the correct version has been exec'd or an error * was issued). * 2) Argc and Argv in this scope are *not* altered by this routine. * It is the responsibility of subsequent code to ignore the * arguments handled by this routine. * 3) As a side-effect, the variable "main_class" is guaranteed to * be set (if it should ever be set). This isn't exactly the * poster child for structured programming, but it is a small * price to pay for not processing a jar file operand twice. */ SelectVersion(argc, argv, &main_class); /* copy original argv */ { int i; original_argv = (char**)MemAlloc(sizeof(char*)*(argc+1)); for(i = 0; i < argc+1; i++) original_argv[i] = argv[i]; } CreateExecutionEnvironment(&argc, &argv, jrepath, sizeof(jrepath), jvmpath, sizeof(jvmpath), original_argv); ifn.CreateJavaVM = 0; ifn.GetDefaultJavaVMInitArgs = 0; if (_launcher_debug) start = CounterGet(); if (!LoadJavaVM(jvmpath, &ifn)) { exit(6); } if (_launcher_debug) { end = CounterGet(); printf("%ld micro seconds to LoadJavaVM\n", (long)(jint)Counter2Micros(end-start)); } #ifdef JAVA_ARGS /* javac, jar and friends. */ progname = "java"; #else /* java, oldjava, javaw and friends */ #ifdef PROGNAME progname = PROGNAME; #else progname = *argv; if ((s = strrchr(progname, FILE_SEPARATOR)) != 0) { progname = s + 1; } #endif /* PROGNAME */ #endif /* JAVA_ARGS */ ++argv; --argc; #ifdef JAVA_ARGS /* Preprocess wrapper arguments */ TranslateDashJArgs(&argc, &argv); if (!AddApplicationOptions()) { exit(1); } #endif /* Set default CLASSPATH */ if ((s = getenv("CLASSPATH")) == 0) { s = "."; } #ifndef JAVA_ARGS SetClassPath(s); #endif /* * Parse command line options; if the return value of * ParseArguments is false, the program should exit. */ if (!ParseArguments(&argc, &argv, &jarfile, &classname, &ret)) { exit(ret); } /* Override class path if -jar flag was specified */ if (jarfile != 0) { SetClassPath(jarfile); } /* set the -Dsun.java.command pseudo property */ SetJavaCommandLineProp(classname, jarfile, argc, argv); /* Set the -Dsun.java.launcher pseudo property */ SetJavaLauncherProp(); /* * Done with all command line processing and potential re-execs so * clean up the environment. */ (void)UnsetEnv(ENV_ENTRY); /* Initialize the virtual machine */ if (_launcher_debug) start = CounterGet(); if (!InitializeJVM(&vm, &env, &ifn)) { ReportErrorMessage("Could not create the Java virtual machine.", JNI_TRUE); exit(1); } if (printVersion || showVersion) { PrintJavaVersion(env); if ((*env)->ExceptionOccurred(env)) { ReportExceptionDescription(env); goto leave; } if (printVersion) { ret = 0; message = NULL; goto leave; } if (showVersion) { fprintf(stderr, "\n"); } } /* If the user specified neither a class name nor a JAR file */ if (jarfile == 0 && classname == 0) { PrintUsage(); message = NULL; goto leave; } FreeKnownVMs(); /* after last possible PrintUsage() */ if (_launcher_debug) { end = CounterGet(); printf("%ld micro seconds to InitializeJVM\n", (long)(jint)Counter2Micros(end-start)); } /* At this stage, argc/argv have the applications' arguments */ if (_launcher_debug) { int i = 0; printf("Main-Class is '%s'\n", classname ? classname : ""); printf("Apps' argc is %d\n", argc); for (; i < argc; i++) { printf(" argv[%2d] = '%s'\n", i, argv[i]); } } ret = 1; /* Get the application's main class */ if (jarfile != 0) { mainClassName = GetMainClassName(env, jarfile); if ((*env)->ExceptionOccurred(env)) { ReportExceptionDescription(env); goto leave; } if (mainClassName == NULL) { const char * format = "Failed to load Main-Class manifest " "attribute from\n%s"; message = (char*)MemAlloc((strlen(format) + strlen(jarfile)) * sizeof(char)); sprintf(message, format, jarfile); messageDest = JNI_TRUE; goto leave; } classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0); if (classname == NULL) { ReportExceptionDescription(env); goto leave; } mainClass = LoadClass(env, classname); if(mainClass == NULL) { /* exception occured */ ReportExceptionDescription(env); message = "Could not find the main class. Program will exit."; goto leave; } (*env)->ReleaseStringUTFChars(env, mainClassName, classname); } else { mainClassName = NewPlatformString(env, classname); if (mainClassName == NULL) { const char * format = "Failed to load Main Class: %s"; message = (char *)MemAlloc((strlen(format) + strlen(classname)) * sizeof(char) ); sprintf(message, format, classname); messageDest = JNI_TRUE; goto leave; } classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0); if (classname == NULL) { ReportExceptionDescription(env); goto leave; } mainClass = LoadClass(env, classname); if(mainClass == NULL) { /* exception occured */ ReportExceptionDescription(env); message = "Could not find the main class. Program will exit."; goto leave; } (*env)->ReleaseStringUTFChars(env, mainClassName, classname); } /* Get the application's main method */ mainID = (*env)->GetStaticMethodID(env, mainClass, "main", "([Ljava/lang/String;)V"); if (mainID == NULL) { if ((*env)->ExceptionOccurred(env)) { ReportExceptionDescription(env); } else { message = "No main method found in specified class."; messageDest = JNI_TRUE; } goto leave; } { /* Make sure the main method is public */ jint mods; jmethodID mid; jobject obj = (*env)->ToReflectedMethod(env, mainClass, mainID, JNI_TRUE); if( obj == NULL) { /* exception occurred */ ReportExceptionDescription(env); goto leave; } mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, obj), "getModifiers", "()I"); if ((*env)->ExceptionOccurred(env)) { ReportExceptionDescription(env); goto leave; } mods = (*env)->CallIntMethod(env, obj, mid); if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */ message = "Main method not public."; messageDest = JNI_TRUE; goto leave; } } /* Build argument array */ mainArgs = NewPlatformStringArray(env, argv, argc); if (mainArgs == NULL) { ReportExceptionDescription(env); goto leave; } /* Invoke main method. */ (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs); if ((*env)->ExceptionOccurred(env)) { /* * Formerly, we used to call the "uncaughtException" method of * the main thread group, but this was later shown to be * unnecessary since the default definition merely printed out * the same exception stack trace as ExceptionDescribe and * could never actually be overridden by application programs. */ ReportExceptionDescription(env); goto leave; } /* * Detach the current thread so that it appears to have exited when * the application's main method exits. */ if ((*vm)->DetachCurrentThread(vm) != 0) { message = "Could not detach main thread."; messageDest = JNI_TRUE; goto leave; } ret = 0; message = NULL; leave: (*vm)->DestroyJavaVM(vm); if(message != NULL && !noExitErrorMessage) ReportErrorMessage(message, messageDest); return ret; }
ClassReferenceHolder::ClassReferenceHolder(JNIEnv* jni) { LoadClass(jni, "org/cio/CIODelegate"); }
void Universe::InitializeGlobals() { set_vt_to_null(); # warning is _store_ptr sufficient? // //allocate nil object // VMObject* nil = new (GetHeap<HEAP_CLS>()) VMObject; nilObject = _store_ptr(nil); nil->SetClass((VMClass*) nil); metaClassClass = _store_ptr(NewMetaclassClass()); objectClass = _store_ptr(NewSystemClass()); nilClass = _store_ptr(NewSystemClass()); classClass = _store_ptr(NewSystemClass()); arrayClass = _store_ptr(NewSystemClass()); symbolClass = _store_ptr(NewSystemClass()); methodClass = _store_ptr(NewSystemClass()); integerClass = _store_ptr(NewSystemClass()); primitiveClass = _store_ptr(NewSystemClass()); stringClass = _store_ptr(NewSystemClass()); doubleClass = _store_ptr(NewSystemClass()); nil->SetClass(load_ptr(nilClass)); InitializeSystemClass(load_ptr(objectClass), nullptr, "Object"); InitializeSystemClass(load_ptr(classClass), load_ptr(objectClass), "Class"); InitializeSystemClass(load_ptr(metaClassClass), load_ptr(classClass), "Metaclass"); InitializeSystemClass(load_ptr(nilClass), load_ptr(objectClass), "Nil"); InitializeSystemClass(load_ptr(arrayClass), load_ptr(objectClass), "Array"); InitializeSystemClass(load_ptr(methodClass), load_ptr(arrayClass), "Method"); InitializeSystemClass(load_ptr(stringClass), load_ptr(objectClass), "String"); InitializeSystemClass(load_ptr(symbolClass), load_ptr(stringClass), "Symbol"); InitializeSystemClass(load_ptr(integerClass), load_ptr(objectClass), "Integer"); InitializeSystemClass(load_ptr(primitiveClass), load_ptr(objectClass), "Primitive"); InitializeSystemClass(load_ptr(doubleClass), load_ptr(objectClass), "Double"); // Fix up objectClass load_ptr(objectClass)->SetSuperClass((VMClass*) nil); obtain_vtables_of_known_classes(nil->GetClass()->GetName()); #if USE_TAGGING GlobalBox::updateIntegerBox(NewInteger(1)); #endif LoadSystemClass(load_ptr(objectClass)); LoadSystemClass(load_ptr(classClass)); LoadSystemClass(load_ptr(metaClassClass)); LoadSystemClass(load_ptr(nilClass)); LoadSystemClass(load_ptr(arrayClass)); LoadSystemClass(load_ptr(methodClass)); LoadSystemClass(load_ptr(symbolClass)); LoadSystemClass(load_ptr(integerClass)); LoadSystemClass(load_ptr(primitiveClass)); LoadSystemClass(load_ptr(stringClass)); LoadSystemClass(load_ptr(doubleClass)); blockClass = _store_ptr(LoadClass(SymbolForChars("Block"))); VMSymbol* trueClassName = SymbolForChars("True"); trueClass = _store_ptr(LoadClass(trueClassName)); trueObject = _store_ptr(NewInstance(load_ptr(trueClass))); VMSymbol* falseClassName = SymbolForChars("False"); falseClass = _store_ptr(LoadClass(falseClassName)); falseObject = _store_ptr(NewInstance(load_ptr(falseClass))); systemClass = _store_ptr(LoadClass(SymbolForChars("System"))); }
main(int argc, char **argv) { int i = 1, not_emit = 0, mem_debug = 0; char *vid, filename[256], *name, *oz_root, class_sc, *cpath = NULL; #if 0 int shared = 0; #endif Mode = NORMAL; while (i < argc && *argv[i] == '-') { if (!strcmp(argv[i], "-d")) { Debug = 1; } else if (!strcmp(argv[i], "-d2")) { Debug = 2; } else if (!strcmp (argv[i], "-n")) { not_emit = 1; } else if (!strcmp (argv[i], "-g")) { int j, num = atoi(argv[++i]); for (j = 0; j < num; j++) SetTypeParameter (argv[++i]); Generic = 1; } #if 0 else if (!strcmp (argv[i], "-s")) { shared = 1; } #endif else if (!strcmp (argv[i], "-c")) { ClassPath = argv[++i]; } else if (!strcmp (argv[i], "-p0")) { Mode = THIS_CLASS; } else if (!strcmp (argv[i], "-p1")) { Mode = USED_CLASSES; } else if (!strcmp (argv[i], "-p2")) { Mode = INHERITED_CLASSES; } else if (!strcmp (argv[i], "-p3")) { Mode = ALL_CLASSES; } else if (!strcmp (argv[i], "-pg")) { Generic = 1; Mode = GENERIC_PARAMS; } else if (!strcmp (argv[i], "-object")) { Object = 1; } #ifdef NONISHIOKA else if (!strcmp (argv[i], "-md")) { mem_debug = atoi (argv[++i]); } #else #ifdef MALLOC_DEBUG else if (!strcmp (argv[i], "-md")) { mem_debug = atoi (argv[++i]); } #endif #endif i++; } #ifdef NONISHIOKA malloc_debug (mem_debug); #else #ifdef MALLOC_DEBUG malloc_debug (mem_debug); #endif #endif if (!(oz_root = getenv ("OZROOT"))) { fprintf (stderr, "You must set OZROOT\n"); exit (1); } if (!ClassPath) { cpath = "lib/boot-class"; ClassPath = (char *) malloc (strlen (oz_root) + strlen (cpath) + 1); sprintf (ClassPath, "%s/%s", oz_root, cpath); } Pass = 0; Part = NOT_PART; if (Mode != NORMAL) { #if 0 if (shared) { if (Mode == INHERITED_CLASSES) { print_usage (); exit (1); } yyfile = argv[i]; Part = PUBLIC_PART; } else if (Mode == GENERIC_PARAMS) #endif if (Mode == GENERIC_PARAMS) { yyfile = argv[i]; } else if (Mode == USED_CLASSES || Mode == ALL_CLASSES) { if (i + 1 == argc) { print_usage (); exit (1); } if (!strchr (argv[i], '.')) { Part = atoi (argv[i++]); yyfile = argv[i]; } else { yyfile = argv[i++]; LoadSchool (argv[i++]); Part = PRIVATE_PART; } } else yyfile = argv[i]; if (!(yyin = fopen (yyfile, "r"))) { fprintf(stderr, "cannot open file: %s\n", argv[i]); exit(1); } /* octal escaping */ yyin = EucToOctalEscape (yyin, oz_root); yyparse (); if (Part == PRIVATE_PART) { Pass = 1; yylineno = 1; rewind (yyin); yyparse (); } fclose (yyin); return Error; } #if 0 if ((shared && i + 2 >= argc) || (!shared && i + 3 >= argc)) #endif if (i + 3 >= argc) { print_usage (); exit(1); } #if 0 if (shared) { Part = PUBLIC_PART; name = argv[i++]; } else { #endif Part = atoi (argv [i++]); name = argv[i++]; if (Object && strcmp (name, "Object")) { fprintf (stderr, "this class not `Object'\n"); exit (1); } #if 0 } #endif yyfile = argv[i++]; LoadSchool (argv[i]); vid = GetVID (name, Part); if (Debug) PrintSchool (-1, 0); if (!not_emit) switch (Part) { case PUBLIC_PART: sprintf (filename, "%s/%s/public.z", ClassPath, vid); PublicOutputFileZ = file_open (filename); sprintf (filename, "%s/%s/public.h", ClassPath, vid); PublicOutputFileH = file_open (filename); class_sc = GetClassSC (name); if (class_sc == SC_RECORD || class_sc == SC_STATIC) { if (class_sc == SC_STATIC) { sprintf (filename, "%s/%s/private.i", ClassPath, vid); PrivateOutputFileI = file_open (filename); } sprintf (filename, "%s/%s/private.l", ClassPath, vid); PrivateOutputFileL = file_open (filename); #if 0 vid = GetVID (name, 2); #endif sprintf (filename, "%s/%s/private.c", ClassPath, vid); PrivateOutputFileC = file_open (filename); } if (class_sc && class_sc != SC_ABSTRACT) { sprintf (filename, "%s/%s/private.d", ClassPath, vid); PrivateOutputFileD = file_open (filename); } break; case PROTECTED_PART: sprintf (filename, "%s/%s/protected.z", ClassPath, vid); ProtectedOutputFileZ = file_open (filename); sprintf (filename, "%s/%s/protected.h", ClassPath, vid); ProtectedOutputFileH = file_open (filename); break; case PRIVATE_PART: sprintf (filename, "%s/%s/private.l", ClassPath, vid); PrivateOutputFileL = file_open (filename); sprintf (filename, "%s/%s/private.i", ClassPath, vid); PrivateOutputFileI = file_open (filename); sprintf (filename, "%s/%s/private.d", ClassPath, vid); PrivateOutputFileD = file_open (filename); sprintf (filename, "%s/%s/private.h", ClassPath, vid); PrivateOutputFileH = file_open (filename); sprintf (filename, "%s/%s/private.c", ClassPath, vid); PrivateOutputFileC = file_open (filename); break; } CreateObjectClass (); LoadClass (yyfile, name, oz_root); if (!not_emit) switch (Part) { case PUBLIC_PART: if (!Error) { EmitClassFileZ (ThisClass, Part); EmitHeader (ThisClass); if (ThisClass->cl == TC_StaticObject) { EmitClassFileI (ThisClass); fclose (PrivateOutputFileI); } } if (ThisClass->cl == TC_Record || ThisClass->cl == TC_StaticObject) { fclose (PrivateOutputFileL); fclose (PrivateOutputFileC); } if (ThisClass->cl != TC_Object) fclose (PrivateOutputFileD); fclose (PublicOutputFileZ); fclose (PublicOutputFileH); break; case PROTECTED_PART: if (!Error) { EmitClassFileZ (ThisClass, Part); EmitHeader (ThisClass); } fclose (ProtectedOutputFileZ); fclose (ProtectedOutputFileH); break; case PRIVATE_PART: if (!Error) { EmitClassFileI (ThisClass); EmitHeader (ThisClass); } fclose (PrivateOutputFileL); fclose (PrivateOutputFileI); fclose (PrivateOutputFileD); fclose (PrivateOutputFileH); fclose (PrivateOutputFileC); break; } return Error; }