//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the Sema class, which performs semantic analysis and
// builds ASTs.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_SEMA_H
#define LLVM_CLANG_AST_SEMA_H
#include "IdentifierResolver.h"
#include "CXXFieldCollector.h"
#include "clang/Parse/Action.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/OwningPtr.h"
#include <vector>
#include <string>
namespace llvm {
class APSInt;
}
namespace clang {
class ASTContext;
class ASTConsumer;
class Preprocessor;
class Decl;
class DeclContext;
class DeclSpec;
class NamedDecl;
class ScopedDecl;
class Expr;
class InitListExpr;
class CallExpr;
class VarDecl;
class ParmVarDecl;
class TypedefDecl;
class FunctionDecl;
class QualType;
struct LangOptions;
class Token;
class IntegerLiteral;
class StringLiteral;
class ArrayType;
class LabelStmt;
class SwitchStmt;
class ExtVectorType;
class TypedefDecl;
class ObjCInterfaceDecl;
class ObjCCompatibleAliasDecl;
class ObjCProtocolDecl;
class ObjCImplementationDecl;
class ObjCCategoryImplDecl;
class ObjCCategoryDecl;
class ObjCIvarDecl;
class ObjCMethodDecl;
class ObjCPropertyDecl;
struct BlockSemaInfo;
/// PragmaPackStack - Simple class to wrap the stack used by #pragma
/// pack.
class PragmaPackStack {
typedef std::vector< std::pair<unsigned, std::string> > stack_ty;
/// Alignment - The current user specified alignment.
unsigned Alignment;
/// Stack - Entries in the #pragma pack stack.
stack_ty Stack;
public:
PragmaPackStack(unsigned A) : Alignment(A) {}
void setAlignment(unsigned A) { Alignment = A; }
unsigned getAlignment() { return Alignment; }
/// push - Push the current alignment onto the stack, optionally
/// using the given \arg Name for the record, if non-zero,
void push(IdentifierInfo *Name) {
Stack.push_back(std::make_pair(Alignment,
std::string(Name ? Name->getName() : "")));
}
/// pop - Pop a record from the stack and restore the current
/// alignment to the previous value. If \arg Name is non-zero then
/// the first such named record is popped, otherwise the top record
/// is popped. Returns true if the pop succeeded.
bool pop(IdentifierInfo *Name);
};
/// Sema - This implements semantic analysis and AST building for C.
class Sema : public Action {
public:
Preprocessor &PP;
ASTContext &Context;
ASTConsumer &Consumer;
/// CurContext - This is the current declaration context of parsing.
DeclContext *CurContext;
/// CurBlock - If inside of a block definition, this contains a pointer to
/// the active block object that represents it.
BlockSemaInfo *CurBlock;
/// PackContext - Manages the stack for #pragma pack. An alignment
/// of 0 indicates default alignment.
PragmaPackStack PackContext;
/// LabelMap - This is a mapping from label identifiers to the LabelStmt for
/// it (which acts like the label decl in some ways). Forward referenced
/// labels have a LabelStmt created for them with a null location & SubStmt.
llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
/// ExtVectorDecls - This is a list all the extended vector types. This allows
/// us to associate a raw vector type with one of the ext_vector type names.
/// This is only necessary for issuing pretty diagnostics.
llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
/// ObjCImplementations - Keep track of all class @implementations
/// so we can emit errors on duplicates.
llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
/// ObjCCategoryImpls - Maintain a list of category implementations so
/// we can check for duplicates and find local method declarations.
llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
/// ObjCProtocols - Keep track of all protocol declarations declared
/// with @protocol keyword, so that we can emit errors on duplicates and
/// find the declarations when needed.
llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;