llvm-project/clang/lib/AST
Faisal Vali 2b391ab708 Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
  - any sort of capturing within generic lambdas 
  - generic lambdas within template functions and nested 
    within other generic lambdas
  - conversion operator for captureless lambdas
  - ensuring all visitors are generic lambda aware
  (Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)

As an example of what compiles through this commit:

template <class F1, class F2>
struct overload : F1, F2 {
    using F1::operator();
    using F2::operator();
    overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
  };

  auto Recursive = [](auto Self, auto h, auto ... rest) {
    return 1 + Self(Self, rest...);
  };
  auto Base = [](auto Self, auto h) {
      return 1;
  };
  overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
  int num_params =  O(O, 5, 3, "abc", 3.14, 'a');

Please see attached tests for more examples.

This patch has been reviewed by Doug and Richard.  Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics). 



Some implementation notes:

  - Add a new Declarator context => LambdaExprParameterContext to 
    clang::Declarator to allow the use of 'auto' in declaring generic
    lambda parameters
      
  - Add various helpers to CXXRecordDecl to facilitate identifying
    and querying a closure class
  
  - LambdaScopeInfo (which maintains the current lambda's Sema state)
    was augmented to house the current depth of the template being
    parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
    so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately 
    generate a template-parameter-type when 'auto' is parsed in a generic
    lambda parameter context.  (i.e we do NOT use AutoType deduced to 
    a template parameter type - Richard seemed ok with this approach).  
    We encode that this template type was generated from an auto by simply
    adding $auto to the name which can be used for better diagnostics if needed.

  - SemaLambda.h was added to hold some common lambda utility
    functions (this file is likely to grow ...)
    
  - Teach Sema::ActOnStartOfFunctionDef to check whether it
    is being called to instantiate a generic lambda's call
    operator, and if so, push an appropriately prepared
    LambdaScopeInfo object on the stack.
    
  - various tests were added - but much more will be needed.

There is obviously more work to be done, and both Richard (weakly) and Doug (strongly) 
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.

A greatful thanks to all reviewers including Eli Friedman, James Dennett, 
and especially the two gracious wizards (Richard Smith and Doug Gregor) 
who spent hours providing feedback (in person in Chicago and on the mailing lists).  
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!

Thanks!

llvm-svn: 191453
2013-09-26 19:54:12 +00:00
..
APValue.cpp Pacify compilers that think you can drop off a fully covered switch. 2013-06-03 21:26:13 +00:00
ASTConsumer.cpp Sort all of Clang's files under 'lib', and fix up the broken headers 2012-12-04 09:13:33 +00:00
ASTContext.cpp Fix ObjC @encode for C++ classes w/virtual bases. 2013-09-18 01:59:16 +00:00
ASTDiagnostic.cpp If a default argument is a dependent type, get the real type from the desugared 2013-07-20 03:49:02 +00:00
ASTDumper.cpp Implement a rudimentary form of generic lambdas. 2013-09-26 19:54:12 +00:00
ASTImporter.cpp Implement a rudimentary form of generic lambdas. 2013-09-26 19:54:12 +00:00
ASTTypeTraits.cpp Add more types to ASTNodeKind. Refactor common instantiation code. 2013-07-16 15:47:24 +00:00
AttrImpl.cpp Tablegen now generates a StringSwitch for attributes containing enumeration arguments to map strings to the proper enumeration value. This makes error checking more consistent and reduces the amount of hand-written code required. 2013-09-11 19:47:58 +00:00
CMakeLists.txt Fix CMakeLists.txt. 2013-07-01 20:34:51 +00:00
CXXABI.h [ms-cxxabi] Implement guard variables for static initialization 2013-09-10 20:14:30 +00:00
CXXInheritance.cpp Use pop_back_val() instead of both back() and pop_back(). 2013-08-23 16:11:15 +00:00
Comment.cpp Add unused markings to suppress warnings. 2013-09-10 22:57:15 +00:00
CommentBriefParser.cpp Some refactoring in my patch on document 2013-03-02 02:39:57 +00:00
CommentCommandTraits.cpp Use llvm::array_lengthof to replace sizeof(array)/sizeof(array[0]). 2013-07-15 03:38:40 +00:00
CommentLexer.cpp Fix indentation 2013-08-23 17:48:41 +00:00
CommentParser.cpp Comment parsing: fix a bug where a line with whitespace between two paragraphs 2013-08-23 18:03:40 +00:00
CommentSema.cpp Use pop_back_val() instead of both back() and pop_back(). 2013-08-23 16:11:15 +00:00
Decl.cpp Revert "Revert "[-cxx-abi microsoft] Mangle local TagDecls appropriately"" 2013-09-17 23:57:10 +00:00
DeclBase.cpp C++ modules: fix a bug where loading a declaration with some name would prevent 2013-09-09 07:34:56 +00:00
DeclCXX.cpp Implement a rudimentary form of generic lambdas. 2013-09-26 19:54:12 +00:00
DeclFriend.cpp Lazily deserialize the "first' friend declaration when deserializing a class 2013-06-26 02:41:25 +00:00
DeclGroup.cpp Sort all of Clang's files under 'lib', and fix up the broken headers 2012-12-04 09:13:33 +00:00
DeclObjC.cpp ObjC migrator: Improve on hueristics. 2013-07-10 21:30:22 +00:00
DeclOpenMP.cpp OpenMP: basic support for #pragma omp parallel 2013-07-19 03:13:43 +00:00
DeclPrinter.cpp [OPENMP] Improved variable lookup procedure for threadprivate variables. 2013-09-26 03:24:06 +00:00
DeclTemplate.cpp A clean-up pass, exploring the unification of traversals of class, variable and function templates. 2013-08-23 22:21:36 +00:00
DeclarationName.cpp Provide operator<< for stream output of DeclarationNames 2013-05-14 21:04:00 +00:00
DumpXML.cpp Add ms_abi and sysv_abi attribute handling. 2013-08-30 04:39:01 +00:00
Expr.cpp Add the intrinsic __builtin_convertvector 2013-09-18 03:29:45 +00:00
ExprCXX.cpp Implement a rudimentary form of generic lambdas. 2013-09-26 19:54:12 +00:00
ExprClassification.cpp Add the intrinsic __builtin_convertvector 2013-09-18 03:29:45 +00:00
ExprConstant.cpp Fix comment to match name of variable. 2013-09-22 10:07:22 +00:00
ExternalASTSource.cpp Simplify FindExternalVisibleDeclsByName by making it return a bool indicating 2013-02-07 03:30:24 +00:00
InheritViz.cpp Use llvm::sys::fs::createTemporaryFile. 2013-07-05 20:00:06 +00:00
ItaniumCXXABI.cpp [ms-cxxabi] Implement guard variables for static initialization 2013-09-10 20:14:30 +00:00
ItaniumMangle.cpp Add the intrinsic __builtin_convertvector 2013-09-18 03:29:45 +00:00
Makefile
Mangle.cpp Get rid of dead/useless code for block mangling. 2013-07-10 01:13:27 +00:00
MangleNumberingContext.cpp [ms-cxxabi] Implement guard variables for static initialization 2013-09-10 20:14:30 +00:00
MicrosoftCXXABI.cpp [ms-cxxabi] Implement guard variables for static initialization 2013-09-10 20:14:30 +00:00
MicrosoftMangle.cpp Remove unused param from MicrosoftMangle::mangleCallingConvention() 2013-09-25 22:28:52 +00:00
NSAPI.cpp Use None rather than Optional<T>() where possible. 2013-02-21 01:47:18 +00:00
NestedNameSpecifier.cpp Use pop_back_val() instead of both back() and pop_back(). 2013-08-23 16:11:15 +00:00
ParentMap.cpp [analyzer; new edges] Simplify edges in a C++11 for-range loop. 2013-06-06 21:53:45 +00:00
RawCommentList.cpp [Doc parsing] Provide diagnostics for unknown documentation 2013-05-03 23:15:20 +00:00
RecordLayout.cpp First pass at abstracting out a class for the target C++ ABI. 2013-01-25 22:30:49 +00:00
RecordLayoutBuilder.cpp Be lazier when loading KeyFunctions from PCH/modules. We don't need to load 2013-08-29 23:59:27 +00:00
SelectorLocationsKind.cpp Fix crash when using archaic protocol, rdar://10238337 2011-10-05 21:28:06 +00:00
Stmt.cpp Add unused markings to suppress warnings. 2013-09-10 22:57:15 +00:00
StmtIterator.cpp Simplify StmtIterator. 2013-06-27 20:39:04 +00:00
StmtPrinter.cpp [OPENMP] Bug fixes and improvements. 2013-09-24 03:17:45 +00:00
StmtProfile.cpp [OPENMP] Bug fixes and improvements. 2013-09-24 03:17:45 +00:00
StmtViz.cpp
TemplateBase.cpp Reduce sizeof(TemplateArgument) from 32 to 24. 2013-08-21 23:05:56 +00:00
TemplateName.cpp Add quotation marks to template names in diagnostics. 2013-03-05 06:21:38 +00:00
Type.cpp volatile types are not trivially copyable. 2013-09-11 03:49:34 +00:00
TypeLoc.cpp AST: Don't treat a TemplateExpansion as a Template 2013-08-28 00:00:27 +00:00
TypePrinter.cpp Mark that qualifiers can prefix the auto type. This seems to just have 2013-09-02 19:20:06 +00:00
VTTBuilder.cpp Remove get(V)BaseClassOffsetInBits, the CharUnit functions should be used instead. 2012-07-04 18:45:14 +00:00
VTableBuilder.cpp Abstract out virtual calls and virtual function prologue code generation; implement them for -cxx-abi microsoft 2013-08-21 06:25:03 +00:00