[cfe-commits] r58817 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ include/clang/Parse/ lib/AST/ lib/Basic/ lib/Parse/ lib/Sema/ test/SemaCXX/ www/
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Nov 7 14:53:38 PST 2008
Douglas Gregor wrote:
> Author: dgregor
> Date: Thu Nov 6 16:13:31 2008
> New Revision: 58817
>
> URL: http://llvm.org/viewvc/llvm-project?rev=58817&view=rev
> Log:
> Parsing, ASTs, and semantic analysis for the declaration of overloaded
> operators in C++.
Yay!
> +DIAG(err_operator_overload_must_be_unary, ERROR,
> + "overloaded operator '%0' must be a unary operator (has %1 parameter%2)")
> +DIAG(err_operator_overload_must_be_binary, ERROR,
> + "overloaded operator '%0' must be a binary operator (has %1 parameter%2)")
> +DIAG(err_operator_overload_must_be_unary_or_binary, ERROR,
> + "overloaded operator '%0' must be a unary or binary operator (has %1 parameter%2)")
> +DIAG(err_operator_overload_must_be_member, ERROR,
> + "overloaded operator '%0' must be a non-static member function")
> +DIAG(err_operator_overload_post_incdec_must_be_int, ERROR,
> + "%0parameter of overloaded post-%1 operator must have type 'int' (not '%2')")
> +
>
To echo a concern Chris recently raised about my code, these are not
localizable. I'm not quite sure how to make them localizable, though.
> +
> +#ifndef OVERLOADED_OPERATOR
> +# define OVERLOADED_OPERATOR(Name,Spelling,Token)
> +#endif
>
Wouldn't it make more sense to put an #error directive here? Surely
including a .def file without defining those macros cannot be intentional.
> +IdentifierInfo *Parser::MaybeParseOperatorFunctionId() {
> + if (Tok.isNot(tok::kw_operator))
> + return 0;
> +
> + OverloadedOperatorKind Op = OO_None;
> + switch (NextToken().getKind()) {
>
Hmm ... I know very little about how Clang's parser works, but wouldn't
it be easier to just consume the operator keyword no matter what? What's
the use case of leaving it in there? (Obviously, the part that parses a
conversion operator would have to be adapted.)
> +
> + bool CanBeUnaryOperator = false;
> + bool CanBeBinaryOperator = false;
> + bool MustBeMemberOperator = false;
> +
>
Wouldn't it be cleaner to extend the operator def file with this
information and use it to generate the switch? Or would the resulting
generated code duplication be worse than the gain? (But you could also
generate a lookup table.)
Sebastian
More information about the cfe-commits
mailing list