2020-03-01 23:05:12 +08:00
|
|
|
//===--- CollectMacros.cpp ---------------------------------------*- C++-*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CollectMacros.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
2021-01-14 16:35:38 +08:00
|
|
|
void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
|
|
|
|
bool IsDefinition) {
|
2020-03-01 23:05:12 +08:00
|
|
|
if (!InMainFile)
|
|
|
|
return;
|
|
|
|
auto Loc = MacroNameTok.getLocation();
|
|
|
|
if (Loc.isInvalid() || Loc.isMacroID())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto Name = MacroNameTok.getIdentifierInfo()->getName();
|
|
|
|
Out.Names.insert(Name);
|
|
|
|
auto Range = halfOpenToRange(
|
|
|
|
SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
|
|
|
|
if (auto SID = getSymbolID(Name, MI, SM))
|
2021-01-14 16:35:38 +08:00
|
|
|
Out.MacroRefs[SID].push_back({Range, IsDefinition});
|
2020-03-01 23:05:12 +08:00
|
|
|
else
|
2021-01-14 16:35:38 +08:00
|
|
|
Out.UnknownMacros.push_back({Range, IsDefinition});
|
2020-03-01 23:05:12 +08:00
|
|
|
}
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|