|
20 | 20 | #include "swift/AST/ASTContext.h"
|
21 | 21 | #include "swift/AST/DiagnosticsClangImporter.h"
|
22 | 22 | #include "swift/AST/Expr.h"
|
23 |
| -#include "swift/AST/ParameterList.h" |
24 | 23 | #include "swift/AST/Stmt.h"
|
25 | 24 | #include "swift/AST/Types.h"
|
26 | 25 | #include "swift/Basic/Assertions.h"
|
|
32 | 31 | #include "clang/Lex/MacroInfo.h"
|
33 | 32 | #include "clang/Lex/Preprocessor.h"
|
34 | 33 | #include "clang/Sema/DelayedDiagnostic.h"
|
35 |
| -#include "clang/Sema/Lookup.h" |
36 | 34 | #include "clang/Sema/Sema.h"
|
37 | 35 | #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
|
38 | 36 | #include "llvm/ADT/SmallString.h"
|
@@ -373,104 +371,6 @@ getIntegerConstantForMacroToken(ClangImporter::Implementation &impl,
|
373 | 371 | return std::nullopt;
|
374 | 372 | }
|
375 | 373 |
|
376 |
| -namespace { |
377 |
| -ValueDecl *importDeclAlias(ClangImporter::Implementation &clang, |
378 |
| - swift::DeclContext *DC, const clang::ValueDecl *D, |
379 |
| - Identifier alias) { |
380 |
| - // Variadic functions cannot be imported into Swift. |
381 |
| - // FIXME(compnerd) emit a diagnostic for the missing diagnostic. |
382 |
| - if (const auto *FD = dyn_cast<clang::FunctionDecl>(D)) |
383 |
| - if (FD->isVariadic()) |
384 |
| - return nullptr; |
385 |
| - |
386 |
| - // Ignore self-referential macros. |
387 |
| - if (D->getName() == alias.str()) |
388 |
| - return nullptr; |
389 |
| - |
390 |
| - swift::ValueDecl *VD = |
391 |
| - dyn_cast_or_null<ValueDecl>(clang.importDecl(D, clang.CurrentVersion)); |
392 |
| - if (VD == nullptr) |
393 |
| - return nullptr; |
394 |
| - |
395 |
| - // If the imported decl is named identically, avoid the aliasing. |
396 |
| - if (VD->getBaseIdentifier().str() == alias.str()) |
397 |
| - return nullptr; |
398 |
| - |
399 |
| - swift::ASTContext &Ctx = DC->getASTContext(); |
400 |
| - ImportedType Ty = |
401 |
| - clang.importType(D->getType(), ImportTypeKind::Abstract, |
402 |
| - [&clang, &D](Diagnostic &&Diag) { |
403 |
| - clang.addImportDiagnostic(D, std::move(Diag), |
404 |
| - D->getLocation()); |
405 |
| - }, /*AllowsNSUIntegerAsInt*/true, |
406 |
| - Bridgeability::None, { }); |
407 |
| - swift::Type GetterTy = FunctionType::get({}, Ty.getType(), ASTExtInfo{}); |
408 |
| - swift::Type SetterTy = |
409 |
| - FunctionType::get({AnyFunctionType::Param(Ty.getType())}, |
410 |
| - Ctx.TheEmptyTupleType, ASTExtInfo{}); |
411 |
| - |
412 |
| - /* Storage */ |
413 |
| - swift::VarDecl *V = |
414 |
| - new (Ctx) VarDecl(/*IsStatic*/false, VarDecl::Introducer::Var, |
415 |
| - SourceLoc(), alias, DC); |
416 |
| - V->setAccess(swift::AccessLevel::Public); |
417 |
| - V->setInterfaceType(Ty.getType()); |
418 |
| - V->getAttrs().add(new (Ctx) TransparentAttr(/*Implicit*/true)); |
419 |
| - V->getAttrs().add(new (Ctx) InlineAttr(InlineKind::Always)); |
420 |
| - |
421 |
| - /* Accessor */ |
422 |
| - swift::AccessorDecl *G = nullptr; |
423 |
| - { |
424 |
| - G = AccessorDecl::createImplicit(Ctx, AccessorKind::Get, V, false, false, |
425 |
| - TypeLoc(), GetterTy, DC); |
426 |
| - G->setAccess(swift::AccessLevel::Public); |
427 |
| - G->setInterfaceType(GetterTy); |
428 |
| - G->setIsTransparent(true); |
429 |
| - G->setParameters(ParameterList::createEmpty(Ctx)); |
430 |
| - |
431 |
| - DeclRefExpr *DRE = |
432 |
| - new (Ctx) DeclRefExpr(ConcreteDeclRef(VD), {}, /*Implicit*/true, |
433 |
| - AccessSemantics::Ordinary, Ty.getType()); |
434 |
| - ReturnStmt *RS = ReturnStmt::createImplicit(Ctx, DRE); |
435 |
| - |
436 |
| - G->setBody(BraceStmt::createImplicit(Ctx, {RS}), |
437 |
| - AbstractFunctionDecl::BodyKind::TypeChecked); |
438 |
| - } |
439 |
| - |
440 |
| - swift::AccessorDecl *S = nullptr; |
441 |
| - if (isa<clang::VarDecl>(D) && |
442 |
| - !cast<clang::VarDecl>(D)->getType().isConstQualified()) { |
443 |
| - S = AccessorDecl::createImplicit(Ctx, AccessorKind::Set, V, false, false, |
444 |
| - TypeLoc(), Ctx.TheEmptyTupleType, DC); |
445 |
| - S->setAccess(swift::AccessLevel::Public); |
446 |
| - S->setInterfaceType(SetterTy); |
447 |
| - S->setIsTransparent(true); |
448 |
| - S->setParameters(ParameterList::create(Ctx, { |
449 |
| - ParamDecl::createImplicit(Ctx, Identifier(), Ctx.getIdentifier("newValue"), |
450 |
| - Ty.getType(), DC) |
451 |
| - })); |
452 |
| - |
453 |
| - DeclRefExpr *LHS = |
454 |
| - new (Ctx) DeclRefExpr(ConcreteDeclRef(VD), {}, /*Implicit*/true, |
455 |
| - AccessSemantics::Ordinary, Ty.getType()); |
456 |
| - DeclRefExpr *RHS = |
457 |
| - new (Ctx) DeclRefExpr(S->getParameters()->get(0), {}, /*Implicit*/true, |
458 |
| - AccessSemantics::Ordinary, Ty.getType()); |
459 |
| - AssignExpr *AE = new (Ctx) AssignExpr(LHS, SourceLoc(), RHS, true); |
460 |
| - AE->setType(Ctx.TheEmptyTupleType); |
461 |
| - S->setBody(BraceStmt::createImplicit(Ctx, {AE}), |
462 |
| - AbstractFunctionDecl::BodyKind::TypeChecked); |
463 |
| - } |
464 |
| - |
465 |
| - /* Bind */ |
466 |
| - V->setImplInfo(S ? StorageImplInfo::getMutableComputed() |
467 |
| - : StorageImplInfo::getImmutableComputed()); |
468 |
| - V->setAccessors(SourceLoc(), S ? ArrayRef{G,S} : ArrayRef{G}, SourceLoc()); |
469 |
| - |
470 |
| - return V; |
471 |
| -} |
472 |
| -} |
473 |
| - |
474 | 374 | static ValueDecl *importMacro(ClangImporter::Implementation &impl,
|
475 | 375 | llvm::SmallSet<StringRef, 4> &visitedMacros,
|
476 | 376 | DeclContext *DC, Identifier name,
|
@@ -609,14 +509,7 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl,
|
609 | 509 | }
|
610 | 510 | }
|
611 | 511 |
|
612 |
| - /* Create an alias for any Decl */ |
613 |
| - clang::Sema &S = impl.getClangSema(); |
614 |
| - clang::LookupResult R(S, {{tok.getIdentifierInfo()}, {}}, |
615 |
| - clang::Sema::LookupAnyName); |
616 |
| - if (S.LookupName(R, S.TUScope)) |
617 |
| - if (R.getResultKind() == clang::LookupResult::LookupResultKind::Found) |
618 |
| - if (const auto *VD = dyn_cast<clang::ValueDecl>(R.getFoundDecl())) |
619 |
| - return importDeclAlias(impl, DC, VD, name); |
| 512 | + // FIXME: If the identifier refers to a declaration, alias it? |
620 | 513 | }
|
621 | 514 |
|
622 | 515 | // TODO(https://github.com/apple/swift/issues/57735): Seems rare to have a single token that is neither a literal nor an identifier, but add diagnosis.
|
|
0 commit comments