@@ -178,10 +178,11 @@ traverse(UsingDirectiveDecl const* D)
178178 Info* NDI = findOrTraverse (ND);
179179 MRDOCS_CHECK_OR (NDI, nullptr );
180180
181- auto res = toNameInfo (ND);
182- MRDOCS_ASSERT (!res.valueless_after_move ());
183- MRDOCS_ASSERT (res->isIdentifier ());
184- if (NameInfo NI = *res;
181+ Optional<Polymorphic<NameInfo>> res = toNameInfo (ND);
182+ MRDOCS_CHECK_OR (res, nullptr );
183+ MRDOCS_ASSERT (!res->valueless_after_move ());
184+ MRDOCS_ASSERT ((*res)->isIdentifier ());
185+ if (NameInfo NI = **res;
185186 !contains (PNI.UsingDirectives , NI))
186187 {
187188 PNI.UsingDirectives .push_back (std::move (NI));
@@ -1249,9 +1250,10 @@ populate(
12491250{
12501251 NamedDecl const * Aliased = D->getAliasedNamespace ();
12511252 NestedNameSpecifier NNS = D->getQualifier ();
1252- Polymorphic<NameInfo> NI = toNameInfo (Aliased, {}, NNS);
1253- MRDOCS_ASSERT (NI->isIdentifier ());
1254- I.AliasedSymbol = std::move (dynamic_cast <IdentifierNameInfo&>(*NI));
1253+ Optional<Polymorphic<NameInfo>> NI = toNameInfo (Aliased, {}, NNS);
1254+ MRDOCS_CHECK_OR (NI);
1255+ MRDOCS_ASSERT ((*NI)->isIdentifier ());
1256+ I.AliasedSymbol = std::move (dynamic_cast <IdentifierNameInfo&>(**NI));
12551257}
12561258
12571259void
@@ -1263,7 +1265,9 @@ populate(
12631265 I.Class = UsingClass::Normal;
12641266 DeclarationName const & Name = D->getNameInfo ().getName ();
12651267 NestedNameSpecifier const & NNS = D->getQualifier ();
1266- I.IntroducedName = toNameInfo (Name, {}, NNS);
1268+ auto INI = toNameInfo (Name, {}, NNS);
1269+ MRDOCS_CHECK_OR (INI);
1270+ I.IntroducedName = *INI;
12671271 for (UsingShadowDecl const * UDS: D->shadows ())
12681272 {
12691273 ScopeExitRestore s (mode_, Dependency);
@@ -2054,14 +2058,15 @@ toTypeInfo(QualType const qt, TraversalMode const mode)
20542058 return Builder.result ();
20552059}
20562060
2057- Polymorphic<NameInfo>
2058- ASTVisitor::toNameInfo (NestedNameSpecifier NNS)
2061+ Optional<Polymorphic<NameInfo>>
2062+ ASTVisitor::
2063+ toNameInfo (NestedNameSpecifier NNS)
20592064{
20602065 MRDOCS_SYMBOL_TRACE (NNS, context_);
20612066 ScopeExitRestore scope (mode_, Dependency);
20622067 switch (NNS.getKind ()) {
20632068 case NestedNameSpecifier::Kind::Null:
2064- return nullable_traits<Polymorphic<NameInfo>>:: null () ;
2069+ return std:: nullopt ;
20652070 case NestedNameSpecifier::Kind::Type: {
20662071 const Type *T = NNS.getAsType ();
20672072 NameInfoBuilder Builder (*this );
@@ -2082,40 +2087,42 @@ ASTVisitor::toNameInfo(NestedNameSpecifier NNS)
20822087 }
20832088 case NestedNameSpecifier::Kind::Global:
20842089 case NestedNameSpecifier::Kind::MicrosoftSuper:
2085- // FIXME: Unimplemented.
2086- return nullable_traits<Polymorphic<NameInfo>>::null ();
2090+ default :
2091+ // Unimplemented
2092+ return std::nullopt ;
20872093 }
20882094 MRDOCS_UNREACHABLE ();
20892095}
20902096
20912097template <class TArgRange >
2092- Polymorphic<NameInfo>
2098+ Optional< Polymorphic<NameInfo> >
20932099ASTVisitor::
2094- toNameInfo (DeclarationName const Name,
2100+ toNameInfo (
2101+ DeclarationName const Name,
20952102 Optional<TArgRange> TArgs,
20962103 NestedNameSpecifier NNS)
20972104{
20982105 if (Name.isEmpty ())
20992106 {
2100- return nullable_traits<Polymorphic<NameInfo>>:: null () ;
2107+ return std:: nullopt ;
21012108 }
2102- Polymorphic<NameInfo> I = nullable_traits<Polymorphic<NameInfo>>:: null () ;
2103- if (TArgs)
2109+ Optional< Polymorphic<NameInfo>> I = std:: nullopt ;
2110+ if (TArgs)
21042111 {
21052112 I = Polymorphic<NameInfo>(std::in_place_type<SpecializationNameInfo>);
2106- populate (static_cast <SpecializationNameInfo &>(*I).TemplateArgs , *TArgs);
2113+ populate (dynamic_cast <SpecializationNameInfo &>(* *I).TemplateArgs , *TArgs);
21072114 }
21082115 else
21092116 {
21102117 I = Polymorphic<NameInfo>(std::in_place_type<IdentifierNameInfo>);
21112118 }
2112- I ->Name = extractName (Name);
2113- I ->Prefix = toNameInfo (NNS);
2119+ (*I) ->Name = extractName (Name);
2120+ (*I) ->Prefix = toNameInfo (NNS);
21142121 return I;
21152122}
21162123
21172124template <class TArgRange >
2118- Polymorphic<NameInfo>
2125+ Optional< Polymorphic<NameInfo> >
21192126ASTVisitor::
21202127toNameInfo (
21212128 Decl const * D,
@@ -2125,25 +2132,25 @@ toNameInfo(
21252132 auto const * ND = dyn_cast_if_present<NamedDecl>(D);
21262133 if (!ND)
21272134 {
2128- return nullable_traits<Polymorphic<NameInfo>>:: null () ;
2135+ return std:: nullopt ;
21292136 }
2130- auto I = toNameInfo (
2131- ND->getDeclName (), std::move (TArgs), NNS);
2132- if (I.valueless_after_move ())
2137+ Optional<Polymorphic<NameInfo>> I = toNameInfo (ND->getDeclName (), std::move (TArgs), NNS);
2138+ if (!I)
21332139 {
2134- return nullable_traits<Polymorphic<NameInfo>>:: null () ;
2140+ return std:: nullopt ;
21352141 }
2142+ MRDOCS_ASSERT (!I->valueless_after_move ());
21362143 ScopeExitRestore scope (mode_, Dependency);
21372144 auto * ID = getInstantiatedFrom (D);
21382145 if (Info const * info = findOrTraverse (const_cast <Decl*>(ID)))
21392146 {
2140- I ->id = info->id ;
2147+ (*I) ->id = info->id ;
21412148 }
21422149 return I;
21432150}
21442151
21452152template
2146- Polymorphic<NameInfo>
2153+ Optional< Polymorphic<NameInfo> >
21472154ASTVisitor::
21482155toNameInfo<llvm::ArrayRef<clang::TemplateArgument>>(
21492156 Decl const * D,
@@ -2233,7 +2240,7 @@ toTArg(TemplateArgument const& A)
22332240 // expression
22342241 case TemplateArgument::Expression:
22352242 {
2236- auto R = Polymorphic<TArg>(std::in_place_type<NonTypeTArg >);
2243+ auto R = Polymorphic<TArg>(std::in_place_type<ConstantTArg >);
22372244 R->IsPackExpansion = A.isPackExpansion ();
22382245 // if this is a pack expansion, use the template argument
22392246 // expansion pattern in place of the template argument pack
@@ -2242,15 +2249,15 @@ toTArg(TemplateArgument const& A)
22422249 A.getPackExpansionPattern () : A;
22432250
22442251 llvm::raw_string_ostream stream (
2245- static_cast <NonTypeTArg &>(*R).Value .Written );
2252+ static_cast <ConstantTArg &>(*R).Value .Written );
22462253 adjusted.print (context_.getPrintingPolicy (), stream, false );
22472254
22482255 return Polymorphic<TArg>(R);
22492256 }
22502257 default :
22512258 MRDOCS_UNREACHABLE ();
22522259 }
2253- return nullable_traits< Polymorphic<TArg>>:: null ( );
2260+ return Polymorphic<TArg>(std::in_place_type<ConstantTArg> );
22542261}
22552262
22562263
0 commit comments