Lines Matching +full:parameter +full:- +full:less

1 //===--- ParseTemplate.cpp - Template Parsing -----------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
27 /// Re-enter a possible template scope, creating as many template parameter
29 /// \return The number of template parameter scopes entered.
45 if (Tok.is(tok::kw_template) && NextToken().isNot(tok::less)) {
56 /// Template declarations include one or more template parameter lists
64 /// template-declaration: [C++ temp]
65 /// 'export'[opt] 'template' '<' template-parameter-list '>' declaration
67 /// template-declaration: [C++2a]
68 /// template-head declaration
69 /// template-head concept-definition
71 /// TODO: requires-clause
72 /// template-head: [C++2a]
73 /// 'template' '<' template-parameter-list '>'
74 /// requires-clause[opt]
76 /// explicit-specialization: [ C++ temp.expl.spec]
92 // parameter scope, e.g.,
98 // We parse multiple levels non-recursively so that we can build a
99 // single data structure containing all of the template parameter
108 // both template parameter lists. In the second case, the action for
109 // defining A<T>::B receives just the inner template parameter list
110 // (and retrieves the outer template parameter list from its
129 // Parse the '<' template-parameter-list '>'
135 // Skip until the semi-colon or a '}'.
151 // Skip until the semi-colon or a '}'.
189 /// declaration. Will be AS_none for namespace-scope declarations.
347 /// ParseTemplateParameters - Parses a template-parameter-list enclosed in
348 /// angle brackets. Depth is the depth of this template-parameter-list, which
351 /// The template parameter we parse will be added to this list. LAngleLoc and
353 /// that enclose this template parameter list.
360 // Get the template parameter list.
361 if (!TryConsumeToken(tok::less, LAngleLoc)) {
366 // Try to parse the template parameter list.
375 // No diagnostic required here: a template-parameter-list can only be
376 // followed by a declaration or, for a template template parameter, the
390 /// ParseTemplateParameterList - Parse a template parameter list. If
395 /// template-parameter-list: [C++ temp]
396 /// template-parameter
397 /// template-parameter-list ',' template-parameter
407 // If we failed to parse a template parameter, skip until we find
413 // Did we find a comma or the end of the template parameter list?
433 /// type parameter.
436 // "class" may be the start of an elaborated-type-specifier or a
437 // type-parameter. Per C++ [temp.param]p3, we prefer the type-parameter.
447 // This may be either a type-parameter or an elaborated-type-specifier.
472 // type-constraint is in fact part of a placeholder-type-specifier of a
473 // non-type template parameter.
478 // 'typedef' is a reasonably-common typo/thinko for 'typename', and is
479 // ill-formed otherwise.
485 // template-parameter. typename followed by an unqualified-id
486 // names a template type parameter. typename followed by a
487 // qualified-id denotes the type in a non-type
488 // parameter-declaration.
506 // These indicate that a comma was missed after a type parameter, not that
507 // we have found a non-type parameter.
515 /// ParseTemplateParameter - Parse a template-parameter (C++ [temp.param]).
517 /// template-parameter: [C++ temp.param]
518 /// type-parameter
519 /// parameter-declaration
521 /// type-parameter: (See below)
522 /// type-parameter-key ...[opt] identifier[opt]
523 /// type-parameter-key identifier[opt] = type-id
524 /// (C++2a) type-constraint ...[opt] identifier[opt]
525 /// (C++2a) type-constraint identifier[opt] = type-id
526 /// 'template' '<' template-parameter-list '>' type-parameter-key
528 /// 'template' '<' template-parameter-list '>' type-parameter-key
529 /// identifier[opt] '=' id-expression
531 /// type-parameter-key:
558 // We return an invalid parameter as opposed to null to avoid having bogus
559 // diagnostics about an empty template parameter list.
573 ErrorParam->setInvalidDecl(true);
586 // If it's none of the above, then it must be a parameter declaration.
587 // NOTE: This will pick up errors in the closure of the template parameter
592 /// Check whether the current token is a template-id annotation denoting a
593 /// type-constraint.
600 return ExistingAnnot->Kind == TNK_Concept_template;
603 /// Try parsing a type-constraint at the current location.
605 /// type-constraint:
606 /// nested-name-specifier[opt] concept-name
607 /// nested-name-specifier[opt] concept-name
608 /// '<' template-argument-list[opt] '>'[opt]
620 // If this is not a type-constraint, then
621 // this scope-spec is part of the typename
622 // of a non-type template parameter
625 // non-namespaces anyway, so might as well
653 // At this point we're sure we're dealing with a constrained parameter. It
654 // may or may not have a template parameter list following the concept
669 /// ParseTypeParameter - Parse a template type parameter (C++ [temp.param]).
673 /// type-parameter: [C++ temp.param]
675 /// 'class' identifier[opt] '=' type-id
677 /// 'typename' identifier[opt] '=' type-id
681 "A type-parameter starts with 'class', 'typename' or a "
682 "type-constraint");
692 // Consume the 'type-constraint'.
695 assert(TypeConstraint->Kind == TNK_Concept_template &&
696 "stray non-concept template-id annotation");
716 // Grab the template parameter name (if given)
724 // Unnamed template parameter. Don't have to do anything here, just
738 // we introduce the type parameter into the local scope.
774 /// ParseTemplateTemplateParameter - Handle the parsing of template
777 /// type-parameter: [C++ temp.param]
778 /// template-head type-parameter-key ...[opt] identifier[opt]
779 /// template-head type-parameter-key identifier[opt] = id-expression
780 /// type-parameter-key:
783 /// template-head: [C++2a]
784 /// 'template' '<' template-parameter-list '>'
785 /// requires-clause[opt]
862 // Unnamed template parameter. Don't have to do anything here, just
880 // we introduce the template parameter into the local scope.
898 /// ParseNonTypeTemplateParameter - Handle the parsing of non-type
901 /// template-parameter:
903 /// parameter-declaration
906 // Parse the declaration-specifiers (i.e., the type).
930 // we introduce the template parameter into the local scope.
939 // When parsing a default template-argument for a non-type
940 // template-parameter, the first non-nested > is taken as the
941 // end of the template-parameter-list rather than a greater-than
960 // Create the parameter.
998 /// \param ObjCGenericList if true, this is the '>' closing an Objective-C
999 /// type parameter or type argument list, rather than a C++ template parameter
1015 Diag(LAngleLoc, diag::note_matching) << tok::less;
1053 // This template-id is terminated by a token that starts with a '>'.
1054 // Outside C++11 and Objective-C, this is now error recovery.
1059 // Objective-C allows this in its type parameter / argument lists.
1129 Tok.setLength(OldLength - GreaterLength);
1132 // (eg, the fifth token in 'A<B>>>' should re-lex as '>', not '>>').
1161 /// Parses a template-id that after the template name has
1165 /// list ('<' template-parameter-list [opt] '>') and placing the
1169 /// token that forms the template-id. Otherwise, we will leave the
1177 assert(Tok.is(tok::less) && "Must have already parsed the template-name");
1182 // Parse the optional template-argument-list.
1206 /// Replace the tokens that form a simple-template-id with an
1207 /// annotation token containing the complete template-id.
1211 /// simple-template-id and replace the tokens with a single annotation
1212 /// token with one of two different kinds: if the template-id names a
1214 /// a type annotation that includes the optional nested-name-specifier
1215 /// (\p SS). Otherwise, the annotation token is a template-id
1217 /// nested-name-specifier.
1225 /// \param SS if non-NULL, the nested-name-specifier that precedes
1228 /// \param TemplateKWLoc if valid, specifies that this template-id
1231 /// template-id was not preceded by a 'template' keyword.
1234 /// simple-template-id that refers to a class template, template
1235 /// template parameter, or other template that produces a type will be
1237 /// simple-template-id is always replaced with a template-id
1240 /// \param TypeConstraint if true, then this is actually a type-constraint,
1253 assert(getLangOpts().CPlusPlus && "Can only annotate template-ids in C++");
1254 assert((Tok.is(tok::less) || TypeConstraint) &&
1255 "Parser isn't at the beginning of a template-id");
1256 assert(!(TypeConstraint && AllowTypeAnnotation) && "type-constraint can't be "
1258 assert((!TypeConstraint || TNK == TNK_Concept_template) && "type-constraint "
1262 // Consume the template-name.
1269 if (!TypeConstraint || Tok.is(tok::less)) {
1273 // token -- we don't know how much to annotate.
1275 // template-id in another context. Try to annotate anyway?
1300 // Build a template-id annotation token that can be processed
1334 /// Replaces a template-id annotation token with a type
1337 /// If there was a failure when forming the type from the template-id,
1341 /// \param SS The scope specifier appearing before the template-id, if any.
1345 /// \param IsClassName Is this template-id appearing in a context where we
1346 /// know it names a class, such as in an elaborated-type-specifier or
1347 /// base-specifier? ('typename' and 'template' are unneeded and disallowed
1352 assert(Tok.is(tok::annot_template_id) && "Requires template-id tokens");
1355 assert(TemplateId->mightBeType() &&
1358 ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
1359 TemplateId->NumArgs);
1362 TemplateId->isInvalid()
1365 getCurScope(), SS, TemplateId->TemplateKWLoc,
1366 TemplateId->Template, TemplateId->Name,
1367 TemplateId->TemplateNameLoc, TemplateId->LAngleLoc,
1368 TemplateArgsPtr, TemplateId->RAngleLoc,
1377 // Replace the template-id annotation token, and possible the scope-specifier
1396 // A template-argument for a template template-parameter shall be the name
1397 // of a class template or an alias template, expressed as id-expression.
1399 // We parse an id-expression that refers to a class template or alias
1402 // nested-name-specifier[opt] template[opt] identifier ...[opt]
1406 CXXScopeSpec SS; // nested-name-specifier, if present
1415 // nested-name-specifier.
1427 // a (possibly-dependent) template name that could be a template template
1437 // We may have a (non-dependent) template name.
1453 // We have an id-expression that refers to a class template or
1467 /// ParseTemplateArgument - Parse a C++ template argument (C++ [temp.names]).
1469 /// template-argument: [C++ 14.2]
1470 /// constant-expression
1471 /// type-id
1472 /// id-expression
1473 /// braced-init-list [C++26, DR]
1477 // In a template-argument, an ambiguity between a type-id and an
1478 // expression is resolved to a type-id, regardless of the form of
1479 // the corresponding template-parameter.
1481 // Therefore, we initially try to parse a type-id - and isCXXTypeId might look
1482 // up and annotate an identifier as an id-expression during disambiguation,
1507 // Revert this tentative parse to parse a non-type template argument.
1511 // Parse a non-type template argument.
1526 /// ParseTemplateArgumentList - Parse a C++ template-argument-list
1529 /// template-argument-list: [C++ 14.2]
1530 /// template-argument
1531 /// template-argument-list ',' template-argument
1574 /// explicit-instantiation:
1592 return getTemplateParamsRange(TemplateParams->data(),
1593 TemplateParams->size());
1602 ((Parser *)P)->ParseLateTemplatedFuncDef(LPT);
1614 FunctionDecl *FunD = LPT.D->getAsFunction();
1615 // Track template parameter depth.
1626 for (DeclContext *DC = FunD; DC && !DC->isTranslationUnit();
1627 DC = DC->getLexicalParent())
1658 // to be re-used for method bodies as well.
1663 Sema::ContextRAII FunctionSavedContext(Actions, FunD->getLexicalParent());
1678 ->getTemplateParameters()
1679 ->getDepth() == TemplateParameterDepth - 1) &&
1697 // If we're in a function-try-block, we need to store all the catch blocks.
1708 /// be an expression. Determine if this is likely to be a template-id and if so,
1710 bool Parser::diagnoseUnknownTemplateId(ExprResult LHS, SourceLocation Less) {
1718 ParseGreaterThanInTemplateList(Less, Greater, true, false);
1720 Less, Greater);
1725 // interpreted as a template-id. Parse it as an (ill-formed) comparison.
1731 assert(Tok.is(tok::less) && "not at a potential angle bracket");
1739 // template-name, followed by a '<' token. Check for some easy cases.
1741 // If we have potential_template<>, then it's supposed to be a template-name.
1745 SourceLocation Less = ConsumeToken();
1747 ParseGreaterThanInTemplateList(Less, Greater, true, false);
1749 getCurScope(), PotentialTemplateName, Less, Greater);
1755 // If we have 'potential_template<type-id', assume it's supposed to be a
1756 // template-name if there's a matching '>' later on.
1760 SourceLocation Less = ConsumeToken();
1762 diagnoseUnknownTemplateId(PotentialTemplateName, Less)) {
1771 // Otherwise, remember that we saw this in case we see a potentially-matching
1785 // template argument and cannot be an expression, then this is ill-formed,
1786 // but might be intended to be part of a template-id.
1793 // If a context that looks like a template-id is followed by '()', then
1794 // this is ill-formed, but might be intended to be a template-id
1806 // intended to be treated as a template-id.