mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Added iid generation, dealing with the void keyword and fixed bugs in generation code
This commit is contained in:
parent
05045ca24d
commit
41487ffa6c
@ -656,6 +656,9 @@ IdlFunction* IdlParser::ParseFunction(IdlSpecification &aSpecification, Token &a
|
||||
case STRING_TOKEN:
|
||||
funcObj->SetReturnValue(TYPE_STRING);
|
||||
break;
|
||||
case VOID_TOKEN:
|
||||
funcObj->SetReturnValue(TYPE_VOID);
|
||||
break;
|
||||
// scoped name
|
||||
case IDENTIFIER_TOKEN:
|
||||
//if (aSpecification.ContainInterface(aToken.stringID)) {
|
||||
|
@ -186,6 +186,9 @@ Token* IdlScanner::NextToken()
|
||||
case 'u':
|
||||
UKeywords(mTokenName + 1, mCurrentToken);
|
||||
break;
|
||||
case 'v':
|
||||
VKeywords(mTokenName + 1, mCurrentToken);
|
||||
break;
|
||||
case 'w':
|
||||
WKeywords(mTokenName + 1, mCurrentToken);
|
||||
break;
|
||||
@ -1000,6 +1003,40 @@ void IdlScanner::UKeywords(char *aCurrentPos, Token *aToken)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 'void' is the only keyword starting with 'v'.
|
||||
// If that is not it, it must be an identifier
|
||||
//
|
||||
void IdlScanner::VKeywords(char *aCurrentPos, Token *aToken)
|
||||
{
|
||||
int c = mInputFile->get();
|
||||
if (c != EOF && c == 'o' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'i' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'd' && (*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(VOID_TOKEN);
|
||||
mInputFile->putback(c);
|
||||
}
|
||||
}
|
||||
else {
|
||||
aToken->SetToken(VOID_TOKEN);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// it must be an identifier
|
||||
KeywordMismatch(c, aCurrentPos, aToken);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 'wstring' is the only keyword starting with 'w'.
|
||||
// If that is not it, it must be an identifier
|
||||
|
@ -62,6 +62,7 @@ enum TokenType {
|
||||
ASSIGNEMENT_TOKEN, // '='
|
||||
FUNC_PARAMS_SPEC_BEGIN_TOKEN, // '('
|
||||
FUNC_PARAMS_SPEC_END_TOKEN, // ')'
|
||||
VOID_TOKEN,
|
||||
// constant values
|
||||
INTEGER_CONSTANT = 1000,
|
||||
STRING_CONSTANT
|
||||
@ -186,6 +187,7 @@ protected:
|
||||
void SKeywords(char *aCurrentPos, Token *aToken);
|
||||
void TKeywords(char *aCurrentPos, Token *aToken);
|
||||
void UKeywords(char *aCurrentPos, Token *aToken);
|
||||
void VKeywords(char *aCurrentPos, Token *aToken);
|
||||
void WKeywords(char *aCurrentPos, Token *aToken);
|
||||
void Identifier(char *aCurrentPos, Token *aToken);
|
||||
void Number(int aStartChar, Token *aToken);
|
||||
|
@ -33,7 +33,8 @@ enum Type {
|
||||
TYPE_INT,
|
||||
TYPE_UINT,
|
||||
TYPE_STRING,
|
||||
TYPE_OBJECT
|
||||
TYPE_OBJECT,
|
||||
TYPE_VOID
|
||||
};
|
||||
|
||||
class IdlVariable : public IdlObject {
|
||||
|
@ -657,7 +657,9 @@ static const char *kMethodBeginStr = "\n\n"
|
||||
"{\n"
|
||||
" nsIDOM%s *nativeThis = (nsIDOM%s*)JS_GetPrivate(cx, obj);\n"
|
||||
" NS_ASSERTION(nsnull != nativeThis, \"null pointer\");\n"
|
||||
" JSBool rBool = JS_FALSE;\n"
|
||||
" JSBool rBool = JS_FALSE;\n";
|
||||
|
||||
static const char *kMethodReturnStr =
|
||||
" %s nativeRet;\n";
|
||||
|
||||
static const char *kMethodParamStr = " %s b%d;\n";
|
||||
@ -718,7 +720,8 @@ static const char *kMethodIntParamStr = "\n"
|
||||
#define JSGEN_GENERATE_INTPARAM(buffer, paramNum) \
|
||||
sprintf(buffer, kMethodIntParamStr, paramNum, paramNum)
|
||||
|
||||
static const char *kMethodParamListStr = "b%d, ";
|
||||
static const char *kMethodParamListStr = "b%d";
|
||||
static const char *kMethodParamListDelimiterStr = ", ";
|
||||
|
||||
static const char *kMethodBodyMiddleStr =
|
||||
"\n"
|
||||
@ -727,6 +730,13 @@ static const char *kMethodBodyMiddleStr =
|
||||
" }\n"
|
||||
"\n";
|
||||
|
||||
static const char *kMethodBodyMiddleNoReturnStr =
|
||||
"\n"
|
||||
" if (NS_OK != nativeThis->%s(%s)) {\n"
|
||||
" return JS_FALSE;\n"
|
||||
" }\n"
|
||||
"\n";
|
||||
|
||||
static const char *kMethodObjectRetStr =
|
||||
" if (nativeRet != nsnull) {\n"
|
||||
" nsIScriptObjectOwner *owner = nsnull;\n"
|
||||
@ -755,6 +765,9 @@ static const char *kMethodIntRetStr =
|
||||
static const char *kMethodBoolRetStr =
|
||||
" *rval = BOOLEAN_TO_JSVAL(nativeRet);\n";
|
||||
|
||||
static const char *kMethodVoidRetStr =
|
||||
" *rval = JSVAL_VOID;\n";
|
||||
|
||||
static const char *kMethodEndStr =
|
||||
" }\n"
|
||||
" else {\n"
|
||||
@ -785,9 +798,12 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec)
|
||||
GetCapitalizedName(method_name, *func);
|
||||
GetVariableTypeForLocal(return_type, *rval);
|
||||
sprintf(buf, kMethodBeginStr, method_name, iface->GetName(),
|
||||
method_name, iface->GetName(), iface->GetName(),
|
||||
return_type);
|
||||
method_name, iface->GetName(), iface->GetName());
|
||||
*file << buf;
|
||||
if (rval->GetType() != TYPE_VOID) {
|
||||
sprintf(buf, kMethodReturnStr, return_type);
|
||||
*file << buf;
|
||||
}
|
||||
|
||||
for (p = 0; p < pcount; p++) {
|
||||
IdlParameter *param = func->GetParameterAt(p);
|
||||
@ -834,13 +850,22 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec)
|
||||
char *param_ptr = param_buf;
|
||||
param_buf[0] = '\0';
|
||||
for (p = 0; p < pcount; p++) {
|
||||
if (p > 0) {
|
||||
strcpy(param_ptr, kMethodParamListDelimiterStr);
|
||||
param_ptr += strlen(param_ptr);
|
||||
}
|
||||
sprintf(param_ptr, kMethodParamListStr, p);
|
||||
param_ptr += strlen(param_ptr);
|
||||
}
|
||||
|
||||
sprintf(buf, kMethodBodyMiddleStr, method_name, param_buf,
|
||||
rval->GetType() == TYPE_STRING ? "" : "&",
|
||||
method_name);
|
||||
if (rval->GetType() != TYPE_VOID) {
|
||||
strcpy(param_ptr, kMethodParamListDelimiterStr);
|
||||
sprintf(buf, kMethodBodyMiddleStr, method_name, param_buf,
|
||||
rval->GetType() == TYPE_STRING ? "" : "&");
|
||||
}
|
||||
else {
|
||||
sprintf(buf, kMethodBodyMiddleNoReturnStr, method_name, param_buf);
|
||||
}
|
||||
*file << buf;
|
||||
|
||||
switch(rval->GetType()) {
|
||||
@ -862,6 +887,9 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec)
|
||||
case TYPE_OBJECT:
|
||||
*file << kMethodObjectRetStr;
|
||||
break;
|
||||
case TYPE_VOID:
|
||||
*file << kMethodVoidRetStr;
|
||||
break;
|
||||
default:
|
||||
// XXX Fail for other cases
|
||||
break;
|
||||
|
@ -41,8 +41,7 @@ static const char *kIncludeStr = "#include \"nsIDOM%s.h\"\n";
|
||||
static const char *kForwardClassStr = "class nsIDOM%s;\n";
|
||||
static const char *kUuidStr =
|
||||
"#define %s \\\n"
|
||||
" { 0x6f7652e0, 0xee43, 0x11d1,\\\n"
|
||||
" { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }\n\n";
|
||||
"--- IID GOES HERE ---\n\n";
|
||||
static const char *kClassDeclStr = "class nsIDOM%s : ";
|
||||
static const char *kBaseClassStr = "public nsIDOM%s";
|
||||
static const char *kNoBaseClassStr = "public nsISupports";
|
||||
@ -51,7 +50,8 @@ static const char *kConstDeclStr = " const %s %s = %l;\n";
|
||||
static const char *kGetterMethodDeclStr = "\n NS_IMETHOD Get%s(%s%s a%s)=0;\n";
|
||||
static const char *kSetterMethodDeclStr = " NS_IMETHOD Set%s(%s a%s)=0;\n";
|
||||
static const char *kMethodDeclStr = "\n NS_IMETHOD %s(%s)=0;\n";
|
||||
static const char *kParamStr = "%s a%s, ";
|
||||
static const char *kParamStr = "%s a%s";
|
||||
static const char *kDelimiterStr = ", ";
|
||||
static const char *kReturnStr = "%s%s aReturn";
|
||||
static const char *kClassEpilogStr = "};\n\n";
|
||||
static const char *kInitClassStr = "extern nsresult NS_Init%sClass(JSContext *aContext, JSObject **aPrototype);\n\n";
|
||||
@ -181,7 +181,7 @@ XPCOMGen::GenerateClassDecl(IdlInterface &aInterface)
|
||||
int b, bcount = aInterface.BaseClassCount();
|
||||
for (b = 0; b < bcount; b++) {
|
||||
if (b > 0) {
|
||||
*file << ", ";
|
||||
*file << kDelimiterStr;
|
||||
}
|
||||
sprintf(buf, kBaseClassStr, aInterface.GetBaseClassAt(b));
|
||||
*file << buf;
|
||||
@ -229,6 +229,11 @@ XPCOMGen::GenerateMethods(IdlInterface &aInterface)
|
||||
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);
|
||||
@ -236,10 +241,16 @@ XPCOMGen::GenerateMethods(IdlInterface &aInterface)
|
||||
}
|
||||
|
||||
IdlVariable *rval = func->GetReturnValue();
|
||||
GetVariableTypeForParameter(type_buf, *rval);
|
||||
sprintf(cur_param, kReturnStr, type_buf,
|
||||
rval->GetType() == TYPE_STRING ? "" : "*");
|
||||
|
||||
if (rval->GetType() != TYPE_VOID) {
|
||||
if (p > 0) {
|
||||
strcpy(cur_param, kDelimiterStr);
|
||||
cur_param += strlen(kDelimiterStr);
|
||||
}
|
||||
GetVariableTypeForParameter(type_buf, *rval);
|
||||
sprintf(cur_param, kReturnStr, type_buf,
|
||||
rval->GetType() == TYPE_STRING ? "" : "*");
|
||||
}
|
||||
|
||||
GetCapitalizedName(name_buf, *func);
|
||||
sprintf(buf, kMethodDeclStr, name_buf, param_buf);
|
||||
*file << buf;
|
||||
|
85
dom/tools/geniid.pl
Normal file
85
dom/tools/geniid.pl
Normal file
@ -0,0 +1,85 @@
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
require "find.pl";
|
||||
|
||||
$uuid = 0x6f7652e0;
|
||||
$format = "{ 0x%x, 0xee43, 0x11d1, \\ \
|
||||
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }";
|
||||
$pattern = "--- IID GOES HERE ---";
|
||||
|
||||
sub replaceText {
|
||||
local ($oldname) = $_;
|
||||
local ($newname) = $_;
|
||||
local ($found) = 0;
|
||||
local ($tempname) = $oldname.'.orig';
|
||||
local ($replacement);
|
||||
|
||||
if (-T $oldname && -s $oldname) {
|
||||
open(FILE, "<$oldname")
|
||||
|| die "Unable to open $oldname\n";
|
||||
while (<FILE>) {
|
||||
if (/$pattern/) {
|
||||
$found = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
close(FILE);
|
||||
|
||||
if ($found) {
|
||||
rename($oldname, $tempname)
|
||||
|| die "Unable to rename $oldname as $tempname";
|
||||
open(REPLACEFILE, ">$newname")
|
||||
|| die "Unable to open $newname for writing\n";
|
||||
|
||||
open(SEARCHFILE, "<$tempname")
|
||||
|| die "Unable to open $tempname\n";
|
||||
|
||||
while (<SEARCHFILE>) {
|
||||
if (/$pattern/) {
|
||||
$replacement = sprintf($format, $uuid++);
|
||||
warn "$name: Changing '$pattern' to '$replacement'\n";
|
||||
s/$pattern/$replacement /g;
|
||||
}
|
||||
print REPLACEFILE;
|
||||
}
|
||||
close(SEARCHFILE);
|
||||
close(REPLACEFILE);
|
||||
if (-z $newname) {
|
||||
die "$newname has zero size\n."
|
||||
."Restore manually from $tempname\n";
|
||||
} else {
|
||||
unlink($tempname);
|
||||
}
|
||||
|
||||
warn "$name: Renaming as $newname\n" if $newname ne $oldname;
|
||||
|
||||
$_ = $oldname;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ($newname ne $oldname) {
|
||||
warn "$name: Renaming as $newname\n";
|
||||
rename($oldname, $newname) || warn "Unable to rename $oldname\n";
|
||||
}
|
||||
$_ = $oldname;
|
||||
}
|
||||
|
||||
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
|
||||
if $running_under_some_shell;
|
||||
|
||||
# Traverse desired filesystems
|
||||
$dont_use_nlink = 1;
|
||||
|
||||
if (!$ARGV[0]) {
|
||||
&find('.');
|
||||
}
|
||||
else {
|
||||
&find($ARGV[0]);
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
sub wanted {
|
||||
/^nsIDOM.*\.h$/ &&
|
||||
&replaceText($name);
|
||||
}
|
@ -80,7 +80,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// initialize and run the parser
|
||||
IdlParser *parser = new IdlParser();
|
||||
try {
|
||||
try {
|
||||
parser->Parse(argv[i], *specification);
|
||||
} catch(AbortParser &exc) {
|
||||
cout << exc;
|
||||
@ -101,7 +101,8 @@ int main(int argc, char *argv[])
|
||||
if (gen_xpcom) {
|
||||
XPCOMGen *xpcomgen = new XPCOMGen();
|
||||
|
||||
try {
|
||||
cout << "Generating XPCOM headers for " << argv[i] << ".\n";
|
||||
try {
|
||||
xpcomgen->Generate(argv[i], op_dir ? argv[op_dir_arg] : NULL,
|
||||
*specification);
|
||||
}
|
||||
@ -117,6 +118,7 @@ int main(int argc, char *argv[])
|
||||
if (gen_js) {
|
||||
JSStubGen *jsgen = new JSStubGen();
|
||||
|
||||
cout << "Generating JavaScript stubs for " << argv[i] << ".\n";
|
||||
try {
|
||||
jsgen->Generate(argv[i], op_dir ? argv[op_dir_arg] : NULL,
|
||||
*specification);
|
||||
|
Loading…
Reference in New Issue
Block a user