Process objc methods

This commit is contained in:
Roberto Raggi
2010-08-13 15:06:29 +02:00
parent f23c2286c9
commit f2372257ce
2 changed files with 64 additions and 25 deletions

View File

@@ -847,15 +847,14 @@ bool Bind::visit(ObjCTypeNameAST *ast)
return false; return false;
} }
void Bind::objCTypeName(ObjCTypeNameAST *ast) FullySpecifiedType Bind::objCTypeName(ObjCTypeNameAST *ast)
{ {
if (! ast) if (! ast)
return; return FullySpecifiedType();
// unsigned lparen_token = ast->lparen_token;
// unsigned type_qualifier_token = ast->type_qualifier_token; // unsigned type_qualifier_token = ast->type_qualifier_token;
ExpressionTy type_id = this->expression(ast->type_id); ExpressionTy type_id = this->expression(ast->type_id);
// unsigned rparen_token = ast->rparen_token; return type_id;
} }
bool Bind::visit(ObjCInstanceVariablesDeclarationAST *ast) bool Bind::visit(ObjCInstanceVariablesDeclarationAST *ast)
@@ -903,18 +902,23 @@ bool Bind::visit(ObjCMessageArgumentDeclarationAST *ast)
return false; return false;
} }
void Bind::objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast) void Bind::objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast, ObjCMethod *method)
{ {
if (! ast) if (! ast)
return; return;
this->objCTypeName(ast->type_name); FullySpecifiedType type = this->objCTypeName(ast->type_name);
FullySpecifiedType type;
for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) { for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
type = this->specifier(it->value, type); type = this->specifier(it->value, type);
} }
/*const Name *param_name =*/ this->name(ast->param_name);
// Argument *argument = ast->argument; const Name *param_name = this->name(ast->param_name);
const unsigned sourceLocation = ast->param_name ? ast->param_name->firstToken() : ast->firstToken();
Argument *arg = control()->newArgument(sourceLocation, param_name);
arg->setType(type);
ast->argument = arg;
method->addMember(arg);
} }
bool Bind::visit(ObjCMethodPrototypeAST *ast) bool Bind::visit(ObjCMethodPrototypeAST *ast)
@@ -924,23 +928,41 @@ bool Bind::visit(ObjCMethodPrototypeAST *ast)
return false; return false;
} }
void Bind::objCMethodPrototype(ObjCMethodPrototypeAST *ast) ObjCMethod *Bind::objCMethodPrototype(ObjCMethodPrototypeAST *ast)
{ {
if (! ast) if (! ast)
return; return 0;
// unsigned method_type_token = ast->method_type_token; // unsigned method_type_token = ast->method_type_token;
this->objCTypeName(ast->type_name); FullySpecifiedType returnType = this->objCTypeName(ast->type_name);
/*const Name *selector =*/ this->name(ast->selector); const Name *selector = this->name(ast->selector);
const unsigned sourceLocation = ast->selector ? ast->selector->firstToken() : ast->firstToken();
ObjCMethod *method = control()->newObjCMethod(sourceLocation, selector);
// ### set the offsets
method->setReturnType(returnType);
if (isObjCClassMethod(tokenKind(ast->method_type_token)))
method->setStorage(Symbol::Static);
method->setVisibility(_objcVisibility);
_scope->addMember(method);
ast->symbol = method;
Scope *previousScope = switchScope(method);
for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) { for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
this->objCMessageArgumentDeclaration(it->value); this->objCMessageArgumentDeclaration(it->value, method);
} }
// unsigned dot_dot_dot_token = ast->dot_dot_dot_token; (void) switchScope(previousScope);
FullySpecifiedType type;
if (ast->dot_dot_dot_token)
method->setVariadic(true);
FullySpecifiedType specifiers;
for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) { for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
type = this->specifier(it->value, type); specifiers = this->specifier(it->value, specifiers);
} }
// ObjCMethod *symbol = ast->symbol; setDeclSpecifiers(method, specifiers);
return method;
} }
bool Bind::visit(ObjCSynthesizedPropertyAST *ast) bool Bind::visit(ObjCSynthesizedPropertyAST *ast)
@@ -1579,7 +1601,7 @@ bool Bind::visit(ObjCProtocolExpressionAST *ast)
bool Bind::visit(ObjCEncodeExpressionAST *ast) bool Bind::visit(ObjCEncodeExpressionAST *ast)
{ {
// unsigned encode_token = ast->encode_token; // unsigned encode_token = ast->encode_token;
this->objCTypeName(ast->type_name); FullySpecifiedType type = this->objCTypeName(ast->type_name);
return false; return false;
} }
@@ -2227,9 +2249,14 @@ bool Bind::visit(ObjCPropertyDeclarationAST *ast)
bool Bind::visit(ObjCMethodDeclarationAST *ast) bool Bind::visit(ObjCMethodDeclarationAST *ast)
{ {
this->objCMethodPrototype(ast->method_prototype); ObjCMethod *method = this->objCMethodPrototype(ast->method_prototype);
if (! _skipFunctionBodies && ast->function_body) {
Scope *previousScope = switchScope(method);
this->statement(ast->function_body); this->statement(ast->function_body);
// unsigned semicolon_token = ast->semicolon_token; (void) switchScope(previousScope);
}
return false; return false;
} }
@@ -2831,3 +2858,14 @@ int Bind::visibilityForObjCAccessSpecifier(int tokenKind)
return Symbol::Protected; return Symbol::Protected;
} }
} }
bool Bind::isObjCClassMethod(int tokenKind)
{
switch (tokenKind) {
case T_PLUS:
return true;
case T_MINUS:
default:
return false;
}
}

View File

@@ -72,6 +72,7 @@ protected:
static int visibilityForAccessSpecifier(int tokenKind); static int visibilityForAccessSpecifier(int tokenKind);
static int visibilityForClassKey(int tokenKind); static int visibilityForClassKey(int tokenKind);
static int visibilityForObjCAccessSpecifier(int tokenKind); static int visibilityForObjCAccessSpecifier(int tokenKind);
static bool isObjCClassMethod(int tokenKind);
void setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpecifiers); void setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpecifiers);
@@ -116,11 +117,11 @@ protected:
void translationUnit(TranslationUnitAST *ast); void translationUnit(TranslationUnitAST *ast);
void objCProtocolRefs(ObjCProtocolRefsAST *ast, Symbol *objcClassOrProtocol); void objCProtocolRefs(ObjCProtocolRefsAST *ast, Symbol *objcClassOrProtocol);
void objCMessageArgument(ObjCMessageArgumentAST *ast); void objCMessageArgument(ObjCMessageArgumentAST *ast);
void objCTypeName(ObjCTypeNameAST *ast); FullySpecifiedType objCTypeName(ObjCTypeNameAST *ast);
void objCInstanceVariablesDeclaration(ObjCInstanceVariablesDeclarationAST *ast, ObjCClass *klass); void objCInstanceVariablesDeclaration(ObjCInstanceVariablesDeclarationAST *ast, ObjCClass *klass);
void objCPropertyAttribute(ObjCPropertyAttributeAST *ast); void objCPropertyAttribute(ObjCPropertyAttributeAST *ast);
void objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast); void objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast, ObjCMethod *method);
void objCMethodPrototype(ObjCMethodPrototypeAST *ast); ObjCMethod *objCMethodPrototype(ObjCMethodPrototypeAST *ast);
void objCSynthesizedProperty(ObjCSynthesizedPropertyAST *ast); void objCSynthesizedProperty(ObjCSynthesizedPropertyAST *ast);
void lambdaIntroducer(LambdaIntroducerAST *ast); void lambdaIntroducer(LambdaIntroducerAST *ast);
void lambdaCapture(LambdaCaptureAST *ast); void lambdaCapture(LambdaCaptureAST *ast);