From b6e23e71e17c705ce9f3a2b57e3cb683d7afd6b1 Mon Sep 17 00:00:00 2001 From: "rth%cygnus.com" Date: Sat, 12 Dec 1998 08:21:25 +0000 Subject: [PATCH] Detect and handle overloaded methods. git-svn-id: svn://10.0.0.236/trunk@16312 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/ef/Tools/JavaH/JNIHeaderGenerator.cpp | 32 ++++++++++++++++--- .../Tools/JavaH/NetscapeHeaderGenerator.cpp | 32 ++++++++++++++++--- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/mozilla/ef/Tools/JavaH/JNIHeaderGenerator.cpp b/mozilla/ef/Tools/JavaH/JNIHeaderGenerator.cpp index b2cc76c9b13..3f22f4e8157 100644 --- a/mozilla/ef/Tools/JavaH/JNIHeaderGenerator.cpp +++ b/mozilla/ef/Tools/JavaH/JNIHeaderGenerator.cpp @@ -42,11 +42,26 @@ bool JNIHeaderGenerator::genHeaderFile(ClassFileSummary &summ, PR_fprintf(fp, "#include \n\n"); - /* Go through each native method and generate a declaration for it */ const Method **methods = summ.getMethods(); Uint32 methodCount = summ.getMethodCount(); - JNIShortMangler mangler; + /* Now go through each method and see if it is overloaded. */ + TemporaryBuffer overbuf(methodCount*sizeof(bool)); + bool *overloadedMethods = (bool *) (char *) overbuf; + + for (Uint32 i = 0; i < methodCount; i++) { + const char *methodName = methods[i]->getName(); + + overloadedMethods[i] = false; + for (Uint32 j = 0; j < methodCount; ++j) + if (i != j && strcmp(methodName, methods[j]->getName()) == 0) + overloadedMethods[i] = true; + } + + /* Go through each native method and generate a declaration for it */ + + JNILongMangler lmangler; + JNIShortMangler smangler; /* extern "C" the generated method headers */ PR_fprintf(fp, "#ifdef __cplusplus\n"); @@ -72,9 +87,16 @@ bool JNIHeaderGenerator::genHeaderFile(ClassFileSummary &summ, TemporaryBuffer copy(len); char *mangledMethodName = copy; - if (!mangler.mangle(className, methodName, signature, - mangledMethodName, len)) - continue; + if (overloadedMethods[i]) { + if (!lmangler.mangle(className, methodName, signature, + mangledMethodName, len)) + continue; + } + else { + if (!smangler.mangle(className, methodName, signature, + mangledMethodName, len)) + continue; + } PR_fprintf(fp, "\n/*\n"); PR_fprintf(fp, " * Class : %s\n", className); diff --git a/mozilla/ef/Tools/JavaH/NetscapeHeaderGenerator.cpp b/mozilla/ef/Tools/JavaH/NetscapeHeaderGenerator.cpp index 918cb9e57be..0026b9c141f 100644 --- a/mozilla/ef/Tools/JavaH/NetscapeHeaderGenerator.cpp +++ b/mozilla/ef/Tools/JavaH/NetscapeHeaderGenerator.cpp @@ -125,11 +125,26 @@ bool NetscapeHeaderGenerator::genHeaderFile(ClassFileSummary &summ, /* Generate a declaration for the array type corresponding to this class */ PR_fprintf(fp, "ARRAY_OF(Java_%s);\n", mangledClassName); - /* Now go through each native method and generate a declaration for it */ const Method **methods = summ.getMethods(); uint32 methodCount = summ.getMethodCount(); + + /* Now go through each method and see if it is overloaded. */ + TemporaryBuffer overbuf(methodCount*sizeof(bool)); + bool *overloadedMethods = (bool *) (char *) overbuf; + + for (i = 0; i < methodCount; i++) { + const char *methodName = methods[i]->getName(); + + overloadedMethods[i] = false; + for (int j = 0; j < methodCount; ++j) + if (i != j && strcmp(methodName, methods[j]->getName()) == 0) + overloadedMethods[i] = true; + } - NetscapeShortMangler mangler; + /* Now go through each native method and generate a declaration for it */ + + NetscapeShortMangler smangler; + NetscapeLongMangler lmangler; /* extern "C" the generated method headers */ PR_fprintf(fp, "extern \"C\" {\n"); @@ -153,9 +168,16 @@ bool NetscapeHeaderGenerator::genHeaderFile(ClassFileSummary &summ, TemporaryBuffer copy(len); char *mangledMethodName = copy; - if (!mangler.mangle(className, methodName, signature, - mangledMethodName, len)) - continue; + if (overloadedMethods[i]) { + if (!lmangler.mangle(className, methodName, signature, + mangledMethodName, len)) + continue; + } + else { + if (!smangler.mangle(className, methodName, signature, + mangledMethodName, len)) + continue; + } PR_fprintf(fp, "\n/*\n"); PR_fprintf(fp, " * Class : %s\n", className);