Commit b713f177 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added semantic checks for method declarations.

parent b54517ad
......@@ -2970,7 +2970,7 @@ protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public AST
class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public NameAST
{
public:
ObjCTypeNameAST* type_name;
......@@ -2978,7 +2978,7 @@ public:
unsigned param_name_token;
public: // annotations
Name *param_name;
Argument *argument;
public:
virtual ObjCMessageArgumentDeclarationAST *asObjCMessageArgumentDeclaration()
......
......@@ -248,6 +248,8 @@ bool CheckDeclarator::visit(ReferenceAST *ast)
bool CheckDeclarator::visit(ObjCMethodPrototypeAST *ast)
{
FullySpecifiedType returnType = semantic()->check(ast->type_name, _scope);
unsigned location = ast->firstToken();
Name *name = semantic()->check(ast->selector, _scope);
......@@ -259,15 +261,20 @@ bool CheckDeclarator::visit(ObjCMethodPrototypeAST *ast)
fun->setMethodKey(Function::NormalMethod);
fun->setVisibility(semantic()->currentVisibility());
fun->setPureVirtual(false);
fun->setReturnType(returnType);
if (ast->selector->asObjCSelectorWithArguments()) {
// TODO: check the parameters (EV)
// fun->setVariadic(...);
// TODO: add arguments (EV)
for (ObjCMessageArgumentDeclarationListAST *it = ast->arguments; it; it = it->next) {
ObjCMessageArgumentDeclarationAST *argDecl = it->argument_declaration;
// TODO: check return type (EV)
// fun->setReturnType(semantic()->check(ast->type_name, _scope));
// TODO: check the parameters (EV)
// fun->setVariadic(...);
// TODO: add arguments (EV)
semantic()->check(argDecl, fun->arguments());
}
}
FullySpecifiedType mTy(fun);
_fullySpecifiedType = mTy;
_fullySpecifiedType = FullySpecifiedType(fun);
// TODO: check which specifiers are allowed here (EV)
......
......@@ -96,6 +96,7 @@ protected:
// ObjC
virtual bool visit(ObjCMethodPrototypeAST *ast);
void checkMessageArgument(ObjCMessageArgumentDeclarationAST *arg);
void applyCvQualifiers(SpecifierAST *cv);
private:
......
......@@ -55,6 +55,7 @@
#include "Names.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include "Scope.h"
#include <cassert>
CPLUSPLUS_BEGIN_NAMESPACE
......@@ -108,6 +109,17 @@ Name *CheckName::check(ObjCSelectorAST *args, Scope *scope)
return switchName(previousName);
}
void CheckName::check(ObjCMessageArgumentDeclarationAST *arg, Scope *scope)
{
Name *previousName = switchName(0);
Scope *previousScope = switchScope(scope);
accept(arg);
(void) switchScope(previousScope);
(void) switchName(previousName);
}
Name *CheckName::switchName(Name *name)
{
Name *previousName = _name;
......@@ -386,4 +398,26 @@ bool CheckName::visit(ObjCSelectorWithArgumentsAST *ast)
return false;
}
bool CheckName::visit(ObjCMessageArgumentDeclarationAST *ast)
{
FullySpecifiedType type;
if (ast->type_name)
type = semantic()->check(ast->type_name, _scope);
if (ast->param_name_token) {
Identifier *id = identifier(ast->param_name_token);
_name = control()->nameId(id);
ast->name = _name;
Argument *arg = control()->newArgument(ast->firstToken(), _name);
ast->argument = arg;
arg->setType(type);
arg->setInitializer(false);
_scope->enterSymbol(arg);
}
return false;
}
CPLUSPLUS_END_NAMESPACE
......@@ -64,6 +64,7 @@ public:
Name *check(NameAST *name, Scope *scope);
Name *check(NestedNameSpecifierAST *name, Scope *scope);
Name *check(ObjCSelectorAST *args, Scope *scope);
void check(ObjCMessageArgumentDeclarationAST *arg, Scope *scope);
protected:
Name *switchName(Name *name);
......@@ -81,6 +82,7 @@ protected:
// ObjC
virtual bool visit(ObjCSelectorWithoutArgumentsAST *ast);
virtual bool visit(ObjCSelectorWithArgumentsAST *ast);
virtual bool visit(ObjCMessageArgumentDeclarationAST *ast);
private:
Name *_name;
......
......@@ -80,6 +80,17 @@ FullySpecifiedType CheckSpecifier::check(SpecifierAST *specifier, Scope *scope)
return switchFullySpecifiedType(previousType);
}
FullySpecifiedType CheckSpecifier::check(ObjCTypeNameAST *typeName, Scope *scope)
{
FullySpecifiedType previousType = switchFullySpecifiedType(FullySpecifiedType());
Scope *previousScope = switchScope(scope);
accept(typeName);
(void) switchScope(previousScope);
return switchFullySpecifiedType(previousType);
}
SpecifierAST *CheckSpecifier::switchSpecifier(SpecifierAST *specifier)
{
SpecifierAST *previousSpecifier = _specifier;
......@@ -402,4 +413,11 @@ bool CheckSpecifier::visit(AttributeSpecifierAST *ast)
return false;
}
bool CheckSpecifier::visit(ObjCTypeNameAST * /*ast*/)
{
// TODO: implement this (EV)
_fullySpecifiedType = FullySpecifiedType();
return false;
}
CPLUSPLUS_END_NAMESPACE
......@@ -63,6 +63,7 @@ public:
virtual ~CheckSpecifier();
FullySpecifiedType check(SpecifierAST *specifier, Scope *scope);
FullySpecifiedType check(ObjCTypeNameAST *typeName, Scope *scope);
protected:
SpecifierAST *switchSpecifier(SpecifierAST *specifier);
......@@ -79,6 +80,8 @@ protected:
virtual bool visit(TypeofSpecifierAST *ast);
virtual bool visit(AttributeSpecifierAST *ast);
virtual bool visit(ObjCTypeNameAST *ast);
private:
SpecifierAST *_specifier;
FullySpecifiedType _fullySpecifiedType;
......
......@@ -137,6 +137,12 @@ FullySpecifiedType Semantic::check(PtrOperatorAST *ptrOperators, FullySpecifiedT
FullySpecifiedType Semantic::check(ObjCMethodPrototypeAST *methodPrototype, Scope *scope)
{ return d->checkDeclarator->check(methodPrototype, scope); }
FullySpecifiedType Semantic::check(ObjCTypeNameAST *typeName, Scope *scope)
{ return d->checkSpecifier->check(typeName, scope); }
void Semantic::check(ObjCMessageArgumentDeclarationAST *arg, Scope *scope)
{ return d->checkName->check(arg, scope); }
FullySpecifiedType Semantic::check(ExpressionAST *expression, Scope *scope)
{ return d->checkExpression->check(expression, scope); }
......
......@@ -87,6 +87,9 @@ public:
Name *check(NestedNameSpecifierAST *name, Scope *scope);
Name *check(ObjCSelectorAST *args, Scope *scope);
FullySpecifiedType check(ObjCTypeNameAST *typeName, Scope *scope);
void check(ObjCMessageArgumentDeclarationAST *arg, Scope *scope);
bool skipFunctionBodies() const;
void setSkipFunctionBodies(bool skipFunctionBodies);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment