summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Updated IdentifierResolver to deal with DeclarationNames. The names ofDouglas Gregor2008-11-171-11/+15
| | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 59462
* Introduction the DeclarationName class, as a single, general method ofDouglas Gregor2008-11-171-3/+17
| | | | | | | | 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. llvm-svn: 59441
* rename Expr::tryEvaluate to Expr::Evaluate.Chris Lattner2008-11-161-4/+4
| | | | llvm-svn: 59426
* Implement parsing and semantic checking of the 'mutable' keyword.Sebastian Redl2008-11-141-6/+12
| | | | | | Thanks to Doug for the review. Actual effects of mutable to follow. llvm-svn: 59331
* Add a new expression node, CXXOperatorCallExpr, which expresses aDouglas Gregor2008-11-141-1/+3
| | | | | | | | | | | | | | | | | | | 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. llvm-svn: 59306
* don't highlight field name, just put a caret on it.Chris Lattner2008-11-131-2/+2
| | | | llvm-svn: 59255
* Don't build identifiers for C++ constructors, destructors, orDouglas Gregor2008-11-121-5/+0
| | | | | | | | | | | | | | conversion functions. Instead, we just use a placeholder identifier for these (e.g., "<constructor>") and override NamedDecl::getName() to provide a human-readable name. This is one potential solution to the problem; another solution would be to replace the use of IdentifierInfo* in NamedDecl with a different class that deals with identifiers better. I'm also prototyping that to see how it compares, but this commit is better than what we had previously. llvm-svn: 59193
* Fix a FIXME by improving a diagnostic, add a testcase for PR3048Chris Lattner2008-11-121-2/+1
| | | | llvm-svn: 59167
* make TryFixInvalidVariablyModifiedType a static function.Chris Lattner2008-11-121-2/+6
| | | | llvm-svn: 59163
* Restructure code to encourage fallthrough, no functionality change.Chris Lattner2008-11-121-10/+13
| | | | llvm-svn: 59157
* fix PR3048. I'm going to do some more work before closing it off andChris Lattner2008-11-121-0/+1
| | | | | | adding a testcase. llvm-svn: 59156
* Implement support for operator overloading using candidate operatorDouglas Gregor2008-11-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | functions for built-in operators, e.g., the builtin bool operator==(int const*, int const*) can be used for the expression "x1 == x2" given: struct X { operator int const*(); } x1, x2; The scheme for handling these built-in operators is relatively simple: for each candidate required by the standard, create a special kind of candidate function for the built-in. If overload resolution picks the built-in operator, we perform the appropriate conversions on the arguments and then let the normal built-in operator take care of it. There may be some optimization opportunity left: if we can reduce the number of built-in operator overloads we generate, overload resolution for these cases will go faster. However, one must be careful when doing this: GCC generates too few operator overloads in our little test program, and fails to compile it because none of the overloads it generates match. Note that we only support operator overload for non-member binary operators at the moment. The other operators will follow. As part of this change, ImplicitCastExpr can now be an lvalue. llvm-svn: 59148
* Introduce a single AST node SizeOfAlignOfExpr for all sizeof and alignof ↵Sebastian Redl2008-11-111-8/+4
| | | | | | expressions, both of values and types. llvm-svn: 59057
* Implement C++ 'typeid' parsing and sema.Sebastian Redl2008-11-111-1/+14
| | | | llvm-svn: 59042
* Fix PR3031 by silencing follow-on errors in invalid declarations.Chris Lattner2008-11-111-3/+4
| | | | llvm-svn: 59027
* Introduce ScopedDecl::getLexicalDeclContext() which is different from ↵Argyrios Kyrtzidis2008-11-091-13/+21
| | | | | | | | | | | | | ScopedDecl::getDeclContext() when there are nested-names. e.g.: namespace A { void f(); // SemanticDC (getDeclContext) == LexicalDC (getLexicalDeclContext) == 'namespace A' } void A::f(); // SemanticDC == namespace 'A' // LexicalDC == global namespace llvm-svn: 58948
* When a tag has nested-name ('struct foo::bar'), use not 'CurContext' but the ↵Argyrios Kyrtzidis2008-11-091-15/+19
| | | | | | context of the nested-name ('foo::'). llvm-svn: 58945
* Simplify handling of nested-names in tags ('struct foo::bar').Argyrios Kyrtzidis2008-11-091-57/+52
| | | | | | | -Use more of the non nested-name code path. -Also use the ActOnTagStruct code path. llvm-svn: 58944
* Implement Sema support for C++ nested-name-specifiers.Argyrios Kyrtzidis2008-11-081-36/+144
| | | | llvm-svn: 58916
* Implement support for C++ nested-name-specifiers ('foo::bar::x') in the ↵Argyrios Kyrtzidis2008-11-081-3/+5
| | | | | | | | Parser side. No Sema functionality change, just the signatures of the Action/Sema methods. llvm-svn: 58913
* Changes in preparation for nested-name-specifiers.Argyrios Kyrtzidis2008-11-071-14/+22
| | | | | | | -When parsing declarators, don't depend on "CurScope->isCXXClassScope() == true" for constructors/destructors -For C++ member declarations, don't depend on "Declarator.getContext() == Declarator::MemberContext" llvm-svn: 58866
* Parsing, ASTs, and semantic analysis for the declaration of conversionDouglas Gregor2008-11-071-0/+23
| | | | | | | | | | | | | functions in C++, e.g., struct X { operator bool() const; }; Note that these conversions don't actually do anything, since we don't yet have the ability to use them for implicit or explicit conversions. llvm-svn: 58860
* Fix crash caused by this:Argyrios Kyrtzidis2008-11-071-0/+4
| | | | | | | | void f() { int +; // crash here } llvm-svn: 58846
* Parsing, ASTs, and semantic analysis for the declaration of overloadedDouglas Gregor2008-11-061-0/+5
| | | | | | | | | operators in C++. Overloaded operators can be called directly via their operator-function-ids, e.g., "operator+(foo, bar)", but we don't yet implement the semantics of operator overloading to handle, e.g., "foo + bar". llvm-svn: 58817
* Parsing, representation, and preliminary semantic analysis of destructors.Douglas Gregor2008-11-051-72/+28
| | | | | | | | | | | Implicit declaration of destructors (when necessary). Extended Declarator to store information about parsed constructors and destructors; this will be extended to deal with declarators that name overloaded operators (e.g., "operator +") and user-defined conversion operators (e.g., "operator int"). llvm-svn: 58767
* Keep track of whether a C++ class is an aggregate. Don't allow ↵Douglas Gregor2008-11-051-0/+17
| | | | | | initialization of non-aggregates with initializer lists. llvm-svn: 58757
* Implement C++ copy-initialization for declarations. There is now someDouglas Gregor2008-11-051-10/+59
| | | | | | | | duplication in the handling of copy-initialization by constructor, which occurs both for initialization of a declaration and for overloading. The initialization code is due for some refactoring. llvm-svn: 58756
* Implicit support for direct initialization of objects of class type, e.g.,Douglas Gregor2008-11-031-1/+27
| | | | | | X x(5, 7); llvm-svn: 58641
* Add support for parsing and representing C++ constructor declarations.Douglas Gregor2008-10-311-1/+88
| | | | | | | | | | | | | | | Notes: - Constructors are never found by name lookup, so they'll never get pushed into any scope. Instead, they are stored as an OverloadedFunctionDecl in CXXRecordDecl for easy overloading. - There's a new action isCurrentClassName that determines whether an identifier is the name of the innermost class currently being defined; we use this to identify the declarator-id grammar rule that refers to a type-name. - MinimalAction does *not* support parsing constructors. - We now handle virtual and explicit function specifiers. llvm-svn: 58499
* Simplify and correct the check for function redefinitions. This does two things:Douglas Gregor2008-10-291-14/+9
| | | | | | | | | | - Allows definitions of overloaded functions :) - Eliminates extraneous error messages when we have a definition of a function that isn't an overload but doesn't have exactly the same type as the original. llvm-svn: 58382
* Temporary disable the const-object-declaration-without-initializer check, ↵Douglas Gregor2008-10-291-1/+9
| | | | | | because it depends on linkage-specifier semantics we don't yet have llvm-svn: 58377
* Implement initialization of a reference (C++ [dcl.init.ref]) as partDouglas Gregor2008-10-291-0/+50
| | | | | | | | | | | | | | | | | | | of copy initialization. Other pieces of the puzzle: - Try/Perform-ImplicitConversion now handles implicit conversions that don't involve references. - Try/Perform-CopyInitialization uses CheckSingleAssignmentConstraints for C. PerformCopyInitialization is now used for all argument passing and returning values from a function. - Diagnose errors with declaring references and const values without an initializer. (Uses a new Action callback, ActOnUninitializedDecl). We do not yet have implicit conversion sequences for reference binding, which means that we don't have any overloading support for reference parameters yet. llvm-svn: 58353
* Rename ExplicitCCastExpr to CStyleCastExprDouglas Gregor2008-10-281-3/+3
| | | | llvm-svn: 58331
* Improve our handling of (C++) references within Clang. Specifically:Douglas Gregor2008-10-281-5/+0
| | | | | | | | | | | - Do not allow expressions to ever have reference type - Extend Expr::isLvalue to handle more cases where having written a reference into the source implies that the expression is an lvalue (e.g., function calls, C++ casts). - Make GRExprEngine::VisitCall treat the call arguments as lvalues when they are being bound to a reference parameter. llvm-svn: 58306
* Refactor the expression class hierarchy for casts. Most importantly:Douglas Gregor2008-10-271-3/+3
| | | | | | | | | | | | | | | | | | | | | | - CastExpr is the root of all casts - ImplicitCastExpr is (still) used for all explicit casts - ExplicitCastExpr is now the root of all *explicit* casts - ExplicitCCastExpr (new name needed!?) is a C-style cast in C or C++ - CXXFunctionalCastExpr inherits from ExplicitCastExpr - CXXNamedCastExpr inherits from ExplicitCastExpr and is the root of all of the C++ named cast expression types (static_cast, dynamic_cast, etc.) - Added classes CXXStaticCastExpr, CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr to Also, fixed returned-stack-addr.cpp, which broke once when we fixed reinterpret_cast to diagnose double->int* conversions and again when we eliminated implicit conversions to reference types. The fix is in both testcase and SemaChecking.cpp. Most of this patch is simply support for the renaming. There's very little actual change in semantics. llvm-svn: 58264
* Replace common diagnostic with a convenience function.Steve Naroff2008-10-271-38/+24
| | | | | | This simplifies debug of this particular diagnostic (and removes some code clutter). llvm-svn: 58242
* -Add support for cv-qualifiers after function declarators.Argyrios Kyrtzidis2008-10-241-1/+1
| | | | | | -Add withConst/withVolatile/withRestrict methods to QualType class, that return the QualType plus the respective qualifier. llvm-svn: 58120
* PR2942: FunctionDecls by typedef crash the C++ front-endDouglas Gregor2008-10-241-1/+30
| | | | llvm-svn: 58100
* Restrict creation of OverloadedFunctionDecl only to C++ (it was getting used ↵Argyrios Kyrtzidis2008-10-221-1/+2
| | | | | | for invalid redeclarations on C). llvm-svn: 58008
* Preliminary support for function overloadingDouglas Gregor2008-10-211-19/+135
| | | | llvm-svn: 57909
* Implement #pragma pack use in structure packing. The general approachDaniel Dunbar2008-10-161-0/+14
| | | | | | | | | | | | | | | | | | | | | | is to encode the state of the #pragma pack stack as an attribute when the structure is declared. - Extend PackedAttr to take an alignment (in bits), and reuse for both __attribute__((packed)) (which takes no argument, instead packing tightly (to "minimize the memory required") and for #pragma pack (which allows specification of the maximum alignment in bytes). __attribute__((packed)) is just encoded as Alignment=1. This conflates two related but different mechanisms, but it didn't seem worth another attribute. - I have attempted to follow the MSVC semantics as opposed to the gcc ones, since if I understand correctly #pragma pack originated with MSVC. The semantics are generally equivalent except when the stack is altered during the definition of a structure; its not clear if anyone does this in practice. See testcase if curious. llvm-svn: 57623
* Add Sema implementation of #pragma pack stack. Daniel Dunbar2008-10-141-0/+95
| | | | | | | | | | | - Follows the MSVC (original) implementation, including support of pack(show) (useful for testing). - Implements support for named pack records which gcc seems to ignore (or implements incorrectly). - Not currently wired to anything, only functionality change is the type checking of the pragma. llvm-svn: 57476
* silence some release-assert warnings.Chris Lattner2008-10-121-7/+7
| | | | llvm-svn: 57391
* Make sema and codegen allow __builtin___CFStringMakeConstantString as a validChris Lattner2008-10-061-4/+12
| | | | | | | constant lvalue. Implement this in codegen by moving the code out of CGBuiltin into EmitConstantExpr. llvm-svn: 57163
* Add a Expr::isEvaluatable method, eliminate isBuiltinConstantExprChris Lattner2008-10-061-10/+5
| | | | | | | which is checking for something that can be inconsistent with what we can constant fold. llvm-svn: 57159
* "Enhance" CheckArithmeticConstantExpression to accept ?: with a constant Chris Lattner2008-10-061-18/+41
| | | | | | | | | | | | | | | condition as a constant even if the unevaluated side is a not a constant. We don't do this when extensions are off, and we emit a warning when this happens: t.c:22:11: warning: expression is not a constant, but is accepted as one by GNU extensions short t = __builtin_constant_p(5353) ? 42 : somefunc(); ^ ~~~~~~~~~~ suggestions for improvement are welcome. This is obviously horrible, but is required for real-world code. llvm-svn: 57153
* Merge postfix attributes on record decls.Daniel Dunbar2008-10-031-1/+4
| | | | llvm-svn: 57019
* Pass postfix attributes to ActOnFields.Daniel Dunbar2008-10-031-1/+2
| | | | llvm-svn: 56992
* Add getTypeSpecStartLoc() to VarDecls and FunctionDecls.Steve Naroff2008-10-031-3/+6
| | | | | | | This is a temporary solution to help with the block rewriter (though it certainly has general utility). Once DeclGroup's are implemented, this SourceLocation should be stored with it (since it applies to all the decls). llvm-svn: 56985
* Add Builtins.def attribute for "can be a constant expression".Daniel Dunbar2008-10-021-2/+2
| | | | | | | | | | | | | | - Enabled for builtins which are always constant expressions (__builtin_huge_val*, __builtin_inf*, __builtin_constant_p, __builtin_classify_type, __builtin___CFStringMakeConstantString). Added Builtin::Context::isConstantExpr. - Currently overly simply interface which only works for builtins whose constantexprness does not depend on their arguments. CallExpr::isBuiltinConstantExpr now takes an ASTContext argument. llvm-svn: 56983
OpenPOWER on IntegriCloud