Changeset View
Changeset View
Standalone View
Standalone View
libc/utils/HdrGen/PublicAPICommand.cpp
//===-- Implementation of PublicAPICommand --------------------------------===// | //===-- Implementation of PublicAPICommand --------------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "PublicAPICommand.h" | #include "PublicAPICommand.h" | ||||
#include "llvm/ADT/StringExtras.h" | #include "llvm/ADT/StringExtras.h" | ||||
#include "llvm/ADT/StringRef.h" | #include "llvm/ADT/StringRef.h" | ||||
#include "llvm/Support/SourceMgr.h" | #include "llvm/Support/SourceMgr.h" | ||||
#include "llvm/TableGen/Error.h" | #include "llvm/TableGen/Error.h" | ||||
#include "llvm/TableGen/Record.h" | |||||
static const char NamedTypeClassName[] = "NamedType"; | static const char NamedTypeClassName[] = "NamedType"; | ||||
static const char PtrTypeClassName[] = "PtrType"; | static const char PtrTypeClassName[] = "PtrType"; | ||||
static const char RestrictedPtrTypeClassName[] = "RestrictedPtrType"; | static const char RestrictedPtrTypeClassName[] = "RestrictedPtrType"; | ||||
static const char ConstTypeClassName[] = "ConstType"; | static const char ConstTypeClassName[] = "ConstType"; | ||||
static const char StructTypeClassName[] = "Struct"; | static const char StructTypeClassName[] = "Struct"; | ||||
static const char StandardSpecClassName[] = "StandardSpec"; | static const char StandardSpecClassName[] = "StandardSpec"; | ||||
static const char PublicAPIClassName[] = "PublicAPI"; | static const char PublicAPIClassName[] = "PublicAPI"; | ||||
static bool isa(llvm::Record *Def, llvm::Record *TypeClass) { | |||||
llvm::RecordRecTy *RecordType = Def->getType(); | |||||
llvm::ArrayRef<llvm::Record *> Classes = RecordType->getClasses(); | |||||
// We want exact types. That is, we don't want the classes listed in | |||||
// spec.td to be subclassed. Hence, we do not want the record |Def| | |||||
// to be of more than one class type.. | |||||
if (Classes.size() != 1) | |||||
return false; | |||||
return Classes[0] == TypeClass; | |||||
} | |||||
// Text blocks for macro definitions and type decls can be indented to | // Text blocks for macro definitions and type decls can be indented to | ||||
// suit the surrounding tablegen listing. We need to dedent such blocks | // suit the surrounding tablegen listing. We need to dedent such blocks | ||||
// before writing them out. | // before writing them out. | ||||
static void dedentAndWrite(llvm::StringRef Text, llvm::raw_ostream &OS) { | static void dedentAndWrite(llvm::StringRef Text, llvm::raw_ostream &OS) { | ||||
llvm::SmallVector<llvm::StringRef, 10> Lines; | llvm::SmallVector<llvm::StringRef, 10> Lines; | ||||
llvm::SplitString(Text, Lines, "\n"); | llvm::SplitString(Text, Lines, "\n"); | ||||
size_t shortest_indent = 1024; | size_t shortest_indent = 1024; | ||||
for (llvm::StringRef L : Lines) { | for (llvm::StringRef L : Lines) { | ||||
▲ Show 20 Lines • Show All 245 Lines • Show Last 20 Lines |