[cfe-dev] [PATCH]: Parsing for C++ classes
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Jun 21 02:07:48 PDT 2008
Chris Lattner wrote:
>
> +/// TryParseFunctionOrCXXMethodDef - Check the parsed declarator and
> continue
> +/// parsing if it is a function definition.
> +/// If it is a function definition it will return true and 'Res' will
> hold the
> +/// declaration.
> +/// If it is not a function definition it will return false.
> +/// If a parsing error occured, it will return true and 'Res' will
> hold 0.
>
> Please mention that on a parse error, no tokens will be consumed.
>
> +bool Parser::TryParseFunctionOrCXXMethodDef(Declarator &DeclaratorInfo,
> + DeclTy *&Res) {
>
>
> This returns a Decl plus a "success" bool. Should this return a
> "DeclResult" like the existing ExprResult/StmtResult etc stuff used by
> actions?
Actually, I don't think a "DeclResult" is appropriate. The semantic of
DeclResult is that on "success" it holds a valid value, otherwise the
value is invalid. The return semantics of this method are slightly
different, "success" means "I took care of the parsing and here's the
result (the result could be valid or invalid)"; "failure" means "not a
function definition, continue parsing it as a declaration".
So "success" can result to an invalid value as well, unlike DeclResult.
How about I split this method into "isDeclaration" and
"ParseFunctionOrCXXMethodDecl" so that instead of
> DeclTy *Res;
> bool wasParsed = TryParseFunctionOrCXXMethodDef(DeclaratorInfo, Res);
> if (wasParsed) return Res;
we have
> if (!isDeclaration(DeclaratorInfo))
> return ParseFunctionOrCXXMethodDef(DeclaratorInfo, Res);
?
-Argiris
More information about the cfe-dev
mailing list