Added use of the nsIJSNativeInitializer interface in constructors. Work in progress for unknown keyword.

This commit is contained in:
vidur%netscape.com 1999-05-04 20:48:50 +00:00
Родитель 18d2335318
Коммит 5a0ff8598d
6 изменённых файлов: 93 добавлений и 45 удалений

Просмотреть файл

@ -595,6 +595,9 @@ IdlAttribute* IdlParser::ParseAttribute(IdlSpecification &aSpecification, int aT
case STRING_TOKEN:
attrObj->SetType(TYPE_STRING);
break;
case UNKNOWN_TOKEN:
attrObj->SetType(TYPE_UNKNOWN);
break;
// scoped name
case IDENTIFIER_TOKEN:
//if (aSpecification.ContainInterface(token->stringID)) {
@ -675,6 +678,9 @@ IdlFunction* IdlParser::ParseFunction(IdlSpecification &aSpecification, Token &a
case VOID_TOKEN:
funcObj->SetReturnValue(TYPE_VOID);
break;
case UNKNOWN_TOKEN:
funcObj->SetReturnValue(TYPE_UNKNOWN);
break;
// scoped name
case IDENTIFIER_TOKEN:
//if (aSpecification.ContainInterface(aToken.stringID)) {
@ -918,6 +924,9 @@ IdlParameter* IdlParser::ParseFunctionParameter(IdlSpecification &aSpecification
case STRING_TOKEN:
argObj->SetType(TYPE_STRING);
break;
case UNKNOWN_TOKEN:
argObj->SetType(TYPE_UNKNOWN);
break;
// scoped name
case IDENTIFIER_TOKEN:
//if (aSpecification.ContainInterface(token->stringID)) {

Просмотреть файл

@ -996,7 +996,7 @@ void IdlScanner::TKeywords(char *aCurrentPos, Token *aToken)
}
//
// It's either 'union' or 'unsigned' if it's a keyword
// It's either 'union', 'unsigned' or 'unknown' if it's a keyword
// otherwise must be an identifier
//
void IdlScanner::UKeywords(char *aCurrentPos, Token *aToken)
@ -1059,6 +1059,30 @@ void IdlScanner::UKeywords(char *aCurrentPos, Token *aToken)
}
}
}
else if (aCurrentPos == startPos + 1 &&
c != EOF && c == 'k' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
c != EOF && c == 'n' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
c != EOF && c == 'o' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
c != EOF && c == 'w' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
c != EOF && c == 'n' && (*aCurrentPos++ = c)) {
// if terminated is a keyword
c = mInputFile->get();
if (c != EOF) {
if (isalpha(c) || isdigit(c) || c == '_') {
// more characters, it must be an identifier
*aCurrentPos++ = c;
Identifier(aCurrentPos, aToken);
}
else {
// it is a keyword
aToken->SetToken(UNKNOWN_TOKEN);
mInputFile->putback(c);
}
}
else {
aToken->SetToken(UNION_TOKEN);
}
}
else {
// it must be an identifier
KeywordMismatch(c, aCurrentPos, aToken);

Просмотреть файл

@ -72,6 +72,7 @@ enum EIDLTokenType {
FUNC_PARAMS_SPEC_BEGIN_TOKEN, // '('
FUNC_PARAMS_SPEC_END_TOKEN, // ')'
VOID_TOKEN,
UNKNOWN_TOKEN,
// constant values
INTEGER_CONSTANT = 1000,
STRING_CONSTANT

Просмотреть файл

@ -40,7 +40,8 @@ enum Type {
TYPE_OBJECT,
TYPE_XPIDL_OBJECT,
TYPE_FUNC,
TYPE_VOID
TYPE_VOID,
TYPE_UNKNOWN
};
class IdlVariable : public IdlObject {

Просмотреть файл

@ -101,6 +101,7 @@ static const char *kXPIDLIncludeStr = "#include \"%s.h\"\n";
static const char *kIncludeConstructorStr =
"#include \"nsIScriptNameSpaceManager.h\"\n"
"#include \"nsIComponentManager.h\"\n"
"#include \"nsIJSNativeInitializer.h\"\n"
"#include \"nsDOMCID.h\"\n";
static PRIntn
@ -1368,8 +1369,10 @@ static const char *kConstructorBeginStr =
" nsIScriptNameSpaceManager* manager;\n"
" nsIDOM%s *nativeThis;\n"
" nsIScriptObjectOwner *owner = nsnull;\n"
" nsIJSNativeInitializer* initializer = nsnull;\n"
"\n"
" static NS_DEFINE_IID(kIDOM%sIID, NS_IDOM%s_IID);\n"
" static NS_DEFINE_IID(kIJSNativeInitializerIID, NS_IJSNATIVEINITIALIZER_IID);\n"
"\n"
" result = context->GetNameSpaceManager(&manager);\n"
" if (NS_OK != result) {\n"
@ -1390,7 +1393,19 @@ static const char *kConstructorBeginStr =
" return JS_FALSE;\n"
" }\n"
"\n"
" // XXX We should be calling Init() on the instance\n"
" result = nativeThis->QueryInterface(kIJSNativeInitializerIID, (void **)&initializer);\n"
" if (NS_OK != result) {\n"
" NS_RELEASE(nativeThis);\n"
" return JS_FALSE;\n"
" }\n"
"\n"
" result = initializer->Initialize(cx, argc, argv);\n"
" NS_RELEASE(initializer);\n"
"\n"
" if (NS_OK != result) {\n"
" NS_RELEASE(nativeThis);\n"
" return JS_FALSE;\n"
" }\n"
"\n"
" result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);\n"
" if (NS_OK != result) {\n"

Просмотреть файл

@ -335,52 +335,50 @@ XPCOMGen::GenerateMethods(IdlInterface &aInterface)
char *cur_param = param_buf;
IdlFunction *func = aInterface.GetFunctionAt(m);
// Don't generate a constructor method
if (strcmp(func->GetName(), aInterface.GetName()) == 0) {
continue;
}
int p, pcount = func->ParameterCount();
for (p = 0; p < pcount; p++) {
IdlParameter *param = func->GetParameterAt(p);
if (p > 0) {
strcpy(cur_param, kDelimiterStr);
cur_param += strlen(kDelimiterStr);
// Don't generate anything for a constructor
if (strcmp(func->GetName(), aInterface.GetName()) != 0) {
int p, pcount = func->ParameterCount();
for (p = 0; p < pcount; p++) {
IdlParameter *param = func->GetParameterAt(p);
if (p > 0) {
strcpy(cur_param, kDelimiterStr);
cur_param += strlen(kDelimiterStr);
}
GetParameterType(type_buf, *param);
GetCapitalizedName(name_buf, *param);
sprintf(cur_param, kParamStr, type_buf, name_buf);
cur_param += strlen(cur_param);
}
GetParameterType(type_buf, *param);
GetCapitalizedName(name_buf, *param);
sprintf(cur_param, kParamStr, type_buf, name_buf);
cur_param += strlen(cur_param);
}
if (func->GetHasEllipsis()) {
if (pcount > 0) {
strcpy(cur_param, kDelimiterStr);
cur_param += strlen(kDelimiterStr);
if (func->GetHasEllipsis()) {
if (pcount > 0) {
strcpy(cur_param, kDelimiterStr);
cur_param += strlen(kDelimiterStr);
}
sprintf(cur_param, kEllipsisParamStr);
cur_param += strlen(cur_param);
}
sprintf(cur_param, kEllipsisParamStr);
cur_param += strlen(cur_param);
}
IdlVariable *rval = func->GetReturnValue();
if (rval->GetType() != TYPE_VOID) {
if ((pcount > 0) || func->GetHasEllipsis()) {
strcpy(cur_param, kDelimiterStr);
cur_param += strlen(kDelimiterStr);
IdlVariable *rval = func->GetReturnValue();
if (rval->GetType() != TYPE_VOID) {
if ((pcount > 0) || func->GetHasEllipsis()) {
strcpy(cur_param, kDelimiterStr);
cur_param += strlen(kDelimiterStr);
}
GetVariableTypeForParameter(type_buf, *rval);
sprintf(cur_param, kReturnStr, type_buf,
rval->GetType() == TYPE_STRING ? "" : "*");
}
GetVariableTypeForParameter(type_buf, *rval);
sprintf(cur_param, kReturnStr, type_buf,
rval->GetType() == TYPE_STRING ? "" : "*");
else {
*cur_param++ = '\0';
}
GetCapitalizedName(name_buf, *func);
sprintf(buf, kMethodDeclStr, name_buf, param_buf);
*file << buf;
}
else {
*cur_param++ = '\0';
}
GetCapitalizedName(name_buf, *func);
sprintf(buf, kMethodDeclStr, name_buf, param_buf);
*file << buf;
}
}