本文整理汇总了C++中clang::QualType类的典型用法代码示例。如果您正苦于以下问题:C++ QualType类的具体用法?C++ QualType怎么用?C++ QualType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QualType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RequireCompleteType
bool ClangASTImporter::RequireCompleteType(clang::QualType type) {
if (type.isNull())
return false;
if (const TagType *tag_type = type->getAs<TagType>()) {
TagDecl *tag_decl = tag_type->getDecl();
if (tag_decl->getDefinition() || tag_decl->isBeingDefined())
return true;
return CompleteTagDecl(tag_decl);
}
if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>()) {
if (ObjCInterfaceDecl *objc_interface_decl =
objc_object_type->getInterface())
return CompleteObjCInterfaceDecl(objc_interface_decl);
else
return false;
}
if (const ArrayType *array_type = type->getAsArrayTypeUnsafe()) {
return RequireCompleteType(array_type->getElementType());
}
if (const AtomicType *atomic_type = type->getAs<AtomicType>()) {
return RequireCompleteType(atomic_type->getPointeeType());
}
return true;
}
示例2: reportTypeMismatch
/**
* Reports mismatch between buffer type and mpi datatype.
* @param callExpr
*/
void MPIBugReporter::reportTypeMismatch(
const CallExpr *callExpr, const std::pair<size_t, size_t> &idxPair,
clang::QualType bufferType, std::string mpiType) const {
auto adc = analysisManager_.getAnalysisDeclContext(currentFunctionDecl_);
PathDiagnosticLocation location = PathDiagnosticLocation::createBegin(
callExpr, bugReporter_.getSourceManager(), adc);
// deref buffer type
while (bufferType->isPointerType()) {
bufferType = bufferType->getPointeeType();
}
// remove qualifiers
bufferType = bufferType.getUnqualifiedType();
SourceRange callRange = callExpr->getCallee()->getSourceRange();
std::string bugType{"type mismatch"};
std::string errorText{"Buffer type '" + bufferType.getAsString() +
+"' and specified MPI type '" + mpiType +
"' do not match. "};
llvm::SmallVector<SourceRange, 3> sourceRanges;
sourceRanges.push_back(callRange);
sourceRanges.push_back(callExpr->getArg(idxPair.first)->getSourceRange());
sourceRanges.push_back(callExpr->getArg(idxPair.second)->getSourceRange());
bugReporter_.EmitBasicReport(adc->getDecl(), &checkerBase_, bugType,
MPIError, errorText, location, sourceRanges);
}
示例3: StreamArr
static void StreamArr(llvm::raw_ostream& o, const void* V, clang::QualType Ty,
cling::Interpreter& interp) {
clang::ASTContext& C = interp.getCI()->getASTContext();
const clang::ArrayType* ArrTy = Ty->getAsArrayTypeUnsafe();
clang::QualType ElementTy = ArrTy->getElementType();
if (ElementTy->isCharType())
StreamCharPtr(o, (const char*)V);
else if (Ty->isConstantArrayType()) {
// Stream a constant array by streaming up to 5 elements.
const clang::ConstantArrayType* CArrTy
= C.getAsConstantArrayType(Ty);
const llvm::APInt& APSize = CArrTy->getSize();
size_t ElBytes = C.getTypeSize(ElementTy) / C.getCharWidth();
size_t Size = (size_t)APSize.getZExtValue();
o << "{ ";
for (size_t i = 0; i < Size; ++i) {
// Handle the case of constant size array of pointers. Eg. const char*[]
if (ElementTy->isPointerType())
StreamValue(o, *(const char* const *)V + i * ElBytes, ElementTy, interp);
else
StreamValue(o, (const char*)V + i * ElBytes, ElementTy, interp);
if (i + 1 < Size) {
if (i == 4) {
o << "...";
break;
}
else o << ", ";
}
}
o << " }";
} else
StreamPtr(o, V);
}
示例4: error
bool WebCLRestrictor::handleParmVarDecl(clang::ParmVarDecl *decl)
{
const clang::TypeSourceInfo *info = decl->getTypeSourceInfo();
if (!info) {
error(decl->getSourceRange().getBegin(), "Invalid parameter type.\n");
return true;
}
clang::SourceLocation typeLocation = info->getTypeLoc().getBeginLoc();
const clang::QualType qualType = info->getType();
const clang::Type *type = qualType.getTypePtrOrNull();
if (!info) {
error(typeLocation, "Invalid parameter type.\n");
return true;
}
const clang::DeclContext *context = decl->getParentFunctionOrMethod();
if (!context) {
error(typeLocation, "Invalid parameter context.\n");
return true;
}
clang::FunctionDecl *function = clang::FunctionDecl::castFromDeclContext(context);
if (!function) {
error(typeLocation, "Invalid parameter context.\n");
return true;
}
checkStructureParameter(function, typeLocation, type);
check3dImageParameter(function, typeLocation, type);
checkUnsupportedBuiltinParameter(function, typeLocation, qualType);
return true;
}
示例5: roughlyEqual
// A loose type equality check that disregards all sugar, qualification, looks
// through pointers, etc.
static bool roughlyEqual(clang::QualType left, clang::QualType right) {
auto leftPointee = left->getPointeeType();
if (leftPointee != clang::QualType())
left = leftPointee;
auto rightPointee = right->getPointeeType();
if (rightPointee != clang::QualType())
right = rightPointee;
return left->getUnqualifiedDesugaredType() ==
right->getUnqualifiedDesugaredType();
}
示例6: slangAssert
// updates S.Ok; and, depending on Kind, possibly S.FnAccumulatorOk or S.FnOutConverterOk
void RSExportReduce::checkVoidReturn(StateOfAnalyzeTranslationUnit &S,
FnIdent Kind, clang::FunctionDecl *Fn) {
slangAssert(Fn);
const clang::QualType ReturnTy = Fn->getReturnType().getCanonicalType();
if (!ReturnTy->isVoidType()) {
S.RSC.ReportError(Fn->getLocation(),
"%0 must return void not '%1'")
<< S.DiagnosticDescription(getKey(Kind), Fn->getName()) << ReturnTy.getAsString();
notOk(S, Kind);
}
}
示例7: IsStructuralType
bool IsStructuralType(const clang::QualType& type, const clang::ASTContext *context) {
// If it is struct, check if all fields are of structural type
if (type.getCanonicalType().getTypePtr()->isStructureType()) {
clang::RecordDecl* struct_decl = type.getCanonicalType().getTypePtr()->getAsStructureType()->getDecl();
for (const auto* field : struct_decl->fields()) {
if (!IsStructuralType(field->getType(),context))
return false;
}
return true;
} else { // Else check if it is of integral type
return type.getCanonicalType().getTypePtr()->isBuiltinType();
}
}
示例8: TraverseType
bool TraverseType(clang::QualType type)
{
if (type.isNull())
{
return PARENT::TraverseType(type);
}
auto node = std::make_unique<GenericAstNode>();
//node->myType = d;
node->name = type->getTypeClassName();
auto nodePtr = node.get();
myStack.back()->attach(std::move(node));
myStack.push_back(nodePtr);
auto res = PARENT::TraverseType(type);
myStack.pop_back();
return res;
}
示例9: ManagedAllocate
Value::Value(clang::QualType clangTy, Interpreter& Interp):
m_StorageType(determineStorageType(clangTy)),
m_Type(clangTy.getAsOpaquePtr()),
m_Interpreter(&Interp) {
if (needsManagedAllocation())
ManagedAllocate();
}
示例10: sizeOfPointer
int TypeUtils::sizeOfPointer(const clang::CompilerInstance &ci, clang::QualType qt)
{
if (!qt.getTypePtrOrNull())
return -1;
// HACK: What's a better way of getting the size of a pointer ?
auto &astContext = ci.getASTContext();
return astContext.getTypeSize(astContext.getPointerType(qt));
}
示例11: assert
CompilerType::CompilerType(clang::ASTContext *ast, clang::QualType qual_type)
: m_type(qual_type.getAsOpaquePtr()),
m_type_system(ClangASTContext::GetASTContext(ast)) {
#ifdef LLDB_CONFIGURATION_DEBUG
if (m_type)
assert(m_type_system != nullptr);
#endif
}
示例12: ShouldRegisterMetaType
bool MocNg::ShouldRegisterMetaType(clang::QualType T)
{
if (T->isVoidType() || (T->isReferenceType() && !T.getNonReferenceType().isConstQualified()))
return false;
if (registered_meta_type.count(T->getCanonicalTypeUnqualified().getTypePtr()))
return true;
T = T.getNonReferenceType();
if (T->isPointerType()) {
// registering pointer to forward declared type fails.
const clang::CXXRecordDecl* Pointee = T->getPointeeCXXRecordDecl();
if (Pointee && !Pointee->hasDefinition())
return false;
return true;
}
const clang::ClassTemplateSpecializationDecl* TD = llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>(T->getAsCXXRecordDecl());
if (TD) {
if (!TD->hasDefinition())
return false;
for (uint I = 0; I < TD->getTemplateArgs().size(); ++I) {
const auto &Arg = TD->getTemplateArgs().get(I);
if (Arg.getKind() == clang::TemplateArgument::Type) {
if (!ShouldRegisterMetaType(Arg.getAsType()))
return false;
}
}
}
return true;
}
示例13: StreamObj
static void StreamObj(llvm::raw_ostream& o, const void* V, clang::QualType Ty) {
if (clang::CXXRecordDecl* CXXRD = Ty->getAsCXXRecordDecl()) {
std::string QualName = CXXRD->getQualifiedNameAsString();
if (QualName == "cling::Value"){
StreamClingValue(o, (const cling::Value*)V);
return;
}
} // if CXXRecordDecl
// TODO: Print the object members.
o << "@" << V;
}
示例14: assert
void ValuePrinterInfo::Init(clang::QualType Ty) {
assert(!Ty.isNull() && "Type must be valid!");
assert(m_Context && "ASTContext cannot be null!");
assert(sizeof(m_Type) >= sizeof(clang::QualType) && "m_Type too small!");
m_Type = *reinterpret_cast<void**>(&Ty);
// 1. Get the flags
if (Ty.isLocalConstQualified() || Ty.isConstant(*m_Context)){
m_Flags |= VPI_Const;
}
if (Ty->isPointerType()) {
// treat arrary-to-pointer decay as array:
QualType PQT = Ty->getPointeeType();
const Type* PTT = PQT.getTypePtr();
if (!PTT || !PTT->isArrayType()) {
m_Flags |= VPI_Ptr;
if (const RecordType* RT = dyn_cast<RecordType>(Ty.getTypePtr()))
if (RecordDecl* RD = RT->getDecl()) {
CXXRecordDecl* CRD = dyn_cast<CXXRecordDecl>(RD);
if (CRD && CRD->isPolymorphic())
m_Flags |= VPI_Polymorphic;
}
}
}
}
示例15: GetTypeAsString
std::string GetTypeAsString(const clang::QualType &type) {
std::stringstream stream;
std::string name = type.getAsString();
// If it is an anonymous structure, print all the fields recursively
if (name.substr(0,11) == "struct (ano") {
stream << "struct { ";
clang::RecordDecl* struct_decl = type.getTypePtr()->getAsStructureType()->getDecl();
// Print the types of all the fields
for (const auto* field : struct_decl->fields()) {
std::string type = GetTypeAsString(field->getType().getCanonicalType());
std::string name = field->getName();
stream << type;
stream << " " << name << "; ";
}
stream << "}";
} else if (type.getTypePtr()->isBooleanType()) {
return "bool";
} else {
stream << type.getAsString(); //just print the type
}
return stream.str();
}