Chris Lattner [Tue, 18 Nov 2008 07:48:38 +0000 (07:48 +0000)]
Change a couple of the Parser::Diag methods to return DiagnosticInfo
and let the clients push whatever they want into the DiagnosticInfo
instead of hard coding a few forms. Also switch various clients to
use Diag(Tok, ...) instead of Diag(Tok.getLocation(), ...) as the
canonical form to simplify the code a bit.
Chris Lattner [Tue, 18 Nov 2008 07:04:44 +0000 (07:04 +0000)]
This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed. In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a
ton of random stuff. This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.
In addition to introducing DiagnosticInfo, this also substantially changes how
Diagnostic::Report works. Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and
ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator. When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information. This is a somewhat tricky dance, but it means that the
accumulated DiagnosticInfo is allowed to keep pointers to other expression
temporaries without those pointers getting invalidated.
This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema. For example, instead of calling:
Chris Lattner [Tue, 18 Nov 2008 04:56:44 +0000 (04:56 +0000)]
Change the diagnostics interface to take an array of pointers to
strings instead of array of strings. This reduces string copying
in some not-very-important cases, but paves the way for future
improvements.
Ted Kremenek [Tue, 18 Nov 2008 01:33:13 +0000 (01:33 +0000)]
- Add Lexer::isPragma() accessor for clients of Lexer that aren't friends.
- Add static method to test if the current lexer is a non-macro/non-pragma
lexer.
- Refactor some code in PPLexerChange to use this static method.
- No performance change.
Ted Kremenek [Tue, 18 Nov 2008 01:04:47 +0000 (01:04 +0000)]
Add hooks to use PTHLexer::Lex instead of Lexer::Lex when CurLexer is null.
Performance tests on Cocoa.h (using the regular Lexer) shows no performance
difference.
Ted Kremenek [Tue, 18 Nov 2008 00:43:07 +0000 (00:43 +0000)]
Added conditional guard 'if (CurLexer)' when using SetCommentRetentionState().
This is because the PTHLexer will not support this method. Performance testing
on preprocessing Cocoa.h shows that this results in a negligible performance
difference (less than 1%).
I tried making Lexer::SetCommentRetentionState() an out-of-line function (a
precursor to making it a virtual function in PreprocessorLexer) and noticed a 1%
decrease in speed (it is called in a hot part of the Preprocessor).
Ted Kremenek [Tue, 18 Nov 2008 00:34:22 +0000 (00:34 +0000)]
Change a bunch of uses of 'CurLexer->' to 'CurPPLexer->', which should be the
alias for the current PreprocessorLexer. No functionality change. Performance
testing shows this results in no performance degradation when preprocessing
Cocoa.h.
Ted Kremenek [Tue, 18 Nov 2008 00:12:49 +0000 (00:12 +0000)]
- Add 'CurPPLexer' to Preprocessor to keep track of the current
PreprocessorLexer, which will either be a 'Lexer' or 'PTHLexer'.
- Added stub field 'CurPTHLexer' to keep track of the current PTHLexer.
- Modified IncludeStackInfo to track both the current PTHLexer and
current PreprocessorLexer.
Douglas Gregor [Mon, 17 Nov 2008 22:58:34 +0000 (22:58 +0000)]
Eliminate all of the placeholder identifiers used for constructors,
destructors, and conversion functions. The placeholders were used to
work around the fact that the parser and some of Sema really wanted
declarators to have simple identifiers; now, the code that deals with
declarators will use DeclarationNames.
Ted Kremenek [Mon, 17 Nov 2008 22:55:12 +0000 (22:55 +0000)]
Fold assertion into second valid else branch. This removes a compiler warning
where the control reaches the end of a non-void function and also allows the
compiler to generate better code. When this assertion is false we can easily
add more else cases.
Douglas Gregor [Mon, 17 Nov 2008 20:34:05 +0000 (20:34 +0000)]
Updated IdentifierResolver to deal with DeclarationNames. The names of
C++ constructors, destructors, and conversion functions now have a
FETokenInfo field that IdentifierResolver can access, so that these
special names are handled just like ordinary identifiers. A few other
Sema routines now use DeclarationNames instead of IdentifierInfo*'s.
To validate this design, this code also implements parsing and
semantic analysis for id-expressions that name conversion functions,
e.g.,
return operator bool();
The new parser action ActOnConversionFunctionExpr takes the result of
parsing "operator type-id" and turning it into an expression, using
the IdentifierResolver with the DeclarationName of the conversion
function. ActOnDeclarator pushes those conversion function names into
scope so that the IdentifierResolver can find them, of course.
Chris Lattner [Mon, 17 Nov 2008 19:51:54 +0000 (19:51 +0000)]
Implement rdar://6319320: give a good diagnostic for cases where people
are trying to use the old GCC "casts as lvalue" extension. We don't and
will hopefully never support this.
Douglas Gregor [Mon, 17 Nov 2008 14:58:09 +0000 (14:58 +0000)]
Introduction the DeclarationName class, as a single, general method of
representing the names of declarations in the C family of
languages. DeclarationName is used in NamedDecl to store the name of
the declaration (naturally), and ObjCMethodDecl is now a NamedDecl.
Chris Lattner [Sun, 16 Nov 2008 21:48:07 +0000 (21:48 +0000)]
Describe how constant folding and i-c-e diagnosing should work.
Unfortunately, we're not here yet, but eventually Expr::isConstantExpr
and friends should go away.
Chris Lattner [Sun, 16 Nov 2008 18:36:34 +0000 (18:36 +0000)]
Fix PR3077: tokens that come from macro expansions whose macro was
defined in a system header should be treated as system header tokens
even if they are instantiated in a different place.
Zhongxing Xu [Sun, 16 Nov 2008 04:07:26 +0000 (04:07 +0000)]
Enhances SCA to process untyped region to typed region conversion.
- RegionView and RegionViewMap is introduced to assist back-mapping from
super region to subregions.
- GDM is used to carry RegionView information.
- AnonTypedRegion is added to represent a typed region introduced by pointer
casting. Later AnonTypedRegion can be used in other similar cases, e.g.,
malloc()'ed region.
- The specific conversion is delegated to store manager.
Ted Kremenek [Sat, 15 Nov 2008 04:01:56 +0000 (04:01 +0000)]
Reverted part of r59335: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20081110/009243.html
In that patch I added a bogus type promotion for unary '!'.
The real bug was more fallout from edges cases with compound assignments and conjured symbolic values. Now the conjured value has the type of the LHS expression, and we do a promotion to the computation type. We also now correctly do a conversion from the computation type back to the LHS type.
Ted Kremenek [Sat, 15 Nov 2008 00:20:05 +0000 (00:20 +0000)]
Implement FIXME in GRExprEngine::VisitUnaryOperator() to handle implicit conversions caused by the '!' operator. This required adding some logic to GRSimpleVals to reason about nonloc::LocAsInteger SVals. This code appears to work fine, but it should eventually be cleaned up.
Ted Kremenek [Fri, 14 Nov 2008 21:07:14 +0000 (21:07 +0000)]
Minor tweaks to liveness analysis:
- Block-expression for 'ObjCForCollectionStmt' is not alive before it occurs
- Recursively visit 'element' expression for ObjCForCollectionStmt to get liveness for referenced block-level expressions and variables.
Douglas Gregor [Fri, 14 Nov 2008 16:09:21 +0000 (16:09 +0000)]
Add a new expression node, CXXOperatorCallExpr, which expresses a
function call created in response to the use of operator syntax that
resolves to an overloaded operator in C++, e.g., "str1 +
str2" that resolves to std::operator+(str1, str2)". We now build a
CXXOperatorCallExpr in C++ when we pick an overloaded operator. (But
only for binary operators, where we actually implement overloading)
I decided *not* to refactor the current CallExpr to make it abstract
(with FunctionCallExpr and CXXOperatorCallExpr as derived
classes). Doing so would allow us to make CXXOperatorCallExpr a little
bit smaller, at the cost of making the argument and callee accessors
virtual. We won't know if this is going to be a win until we can parse
lots of C++ code to determine how much memory we'll save by making
this change vs. the performance penalty due to the extra virtual
calls.
Douglas Gregor [Fri, 14 Nov 2008 12:46:07 +0000 (12:46 +0000)]
Don't require us to manually number the statements and expressions in StmtNodes.def. We don't need stable numbers yet, renumbering is a pain, and LAST_STMT had the wrong value anyway.