clang API Documentation

SelectorExtras.h
Go to the documentation of this file.
00001 //=== SelectorExtras.h - Helpers for checkers using selectors -----*- C++ -*-=//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H
00011 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H
00012 
00013 #include "clang/AST/ASTContext.h"
00014 #include <cstdarg>
00015 
00016 namespace clang {
00017 namespace ento {
00018 
00019 static inline Selector getKeywordSelectorImpl(ASTContext &Ctx,
00020                                               const char *First,
00021                                               va_list argp) {
00022   SmallVector<IdentifierInfo*, 10> II;
00023   II.push_back(&Ctx.Idents.get(First));
00024 
00025   while (const char *s = va_arg(argp, const char *))
00026     II.push_back(&Ctx.Idents.get(s));
00027 
00028   return Ctx.Selectors.getSelector(II.size(), &II[0]);
00029 }
00030 
00031 static inline Selector getKeywordSelector(ASTContext &Ctx, va_list argp) {
00032   const char *First = va_arg(argp, const char *);
00033   assert(First && "keyword selectors must have at least one argument");
00034   return getKeywordSelectorImpl(Ctx, First, argp);
00035 }
00036 
00037 LLVM_END_WITH_NULL
00038 static inline Selector getKeywordSelector(ASTContext &Ctx,
00039                                           const char *First, ...) {
00040   va_list argp;
00041   va_start(argp, First);
00042   Selector result = getKeywordSelectorImpl(Ctx, First, argp);
00043   va_end(argp);
00044   return result;
00045 }
00046 
00047 LLVM_END_WITH_NULL
00048 static inline void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx,
00049                                            const char *First, ...) {
00050   if (!Sel.isNull())
00051     return;
00052   va_list argp;
00053   va_start(argp, First);
00054   Sel = getKeywordSelectorImpl(Ctx, First, argp);
00055   va_end(argp);
00056 }
00057 
00058 static inline void lazyInitNullarySelector(Selector &Sel, ASTContext &Ctx,
00059                                            const char *Name) {
00060   if (!Sel.isNull())
00061     return;
00062   Sel = GetNullarySelector(Name, Ctx);
00063 }
00064 
00065 } // end namespace ento
00066 } // end namespace clang
00067 
00068 #endif