mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-03 22:06:06 +00:00
Move InitListChecker out of Sema.h
llvm-svn: 63258
This commit is contained in:
parent
f6d2752f12
commit
85df8d82c7
@ -19,7 +19,6 @@
|
|||||||
#include "CXXFieldCollector.h"
|
#include "CXXFieldCollector.h"
|
||||||
#include "SemaOverload.h"
|
#include "SemaOverload.h"
|
||||||
#include "clang/AST/DeclBase.h"
|
#include "clang/AST/DeclBase.h"
|
||||||
#include "clang/AST/Expr.h"
|
|
||||||
#include "clang/Parse/Action.h"
|
#include "clang/Parse/Action.h"
|
||||||
#include "clang/Basic/DiagnosticSema.h"
|
#include "clang/Basic/DiagnosticSema.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
@ -28,7 +27,6 @@
|
|||||||
#include "llvm/ADT/OwningPtr.h"
|
#include "llvm/ADT/OwningPtr.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class APSInt;
|
class APSInt;
|
||||||
@ -1720,6 +1718,7 @@ public:
|
|||||||
bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
|
bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
|
||||||
SourceLocation InitLoc,DeclarationName InitEntity,
|
SourceLocation InitLoc,DeclarationName InitEntity,
|
||||||
bool DirectInit);
|
bool DirectInit);
|
||||||
|
bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
|
||||||
bool CheckSingleInitializer(Expr *&simpleInit, QualType declType,
|
bool CheckSingleInitializer(Expr *&simpleInit, QualType declType,
|
||||||
bool DirectInit);
|
bool DirectInit);
|
||||||
bool CheckForConstantInitializer(Expr *e, QualType t);
|
bool CheckForConstantInitializer(Expr *e, QualType t);
|
||||||
@ -1835,73 +1834,6 @@ private:
|
|||||||
void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
|
void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
|
||||||
};
|
};
|
||||||
|
|
||||||
class InitListChecker {
|
|
||||||
Sema *SemaRef;
|
|
||||||
bool hadError;
|
|
||||||
std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
|
|
||||||
InitListExpr *FullyStructuredList;
|
|
||||||
|
|
||||||
void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
|
|
||||||
unsigned &Index, InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
void CheckExplicitInitList(InitListExpr *IList, QualType &T,
|
|
||||||
unsigned &Index, InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
|
|
||||||
bool SubobjectIsDesignatorContext,
|
|
||||||
unsigned &Index,
|
|
||||||
InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
void CheckSubElementType(InitListExpr *IList, QualType ElemType,
|
|
||||||
unsigned &Index,
|
|
||||||
InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
// FIXME: Does DeclType need to be a reference type?
|
|
||||||
void CheckScalarType(InitListExpr *IList, QualType &DeclType,
|
|
||||||
unsigned &Index,
|
|
||||||
InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index,
|
|
||||||
InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
|
|
||||||
RecordDecl::field_iterator Field,
|
|
||||||
bool SubobjectIsDesignatorContext, unsigned &Index,
|
|
||||||
InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
void CheckArrayType(InitListExpr *IList, QualType &DeclType,
|
|
||||||
llvm::APSInt elementIndex,
|
|
||||||
bool SubobjectIsDesignatorContext, unsigned &Index,
|
|
||||||
InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex);
|
|
||||||
bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE,
|
|
||||||
DesignatedInitExpr::designators_iterator D,
|
|
||||||
QualType &CurrentObjectType,
|
|
||||||
RecordDecl::field_iterator *NextField,
|
|
||||||
llvm::APSInt *NextElementIndex,
|
|
||||||
unsigned &Index,
|
|
||||||
InitListExpr *StructuredList,
|
|
||||||
unsigned &StructuredIndex,
|
|
||||||
bool FinishSubobjectInit = true);
|
|
||||||
InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
|
|
||||||
QualType CurrentObjectType,
|
|
||||||
InitListExpr *StructuredList,
|
|
||||||
unsigned StructuredIndex,
|
|
||||||
SourceRange InitRange);
|
|
||||||
void UpdateStructuredListElement(InitListExpr *StructuredInitList,
|
|
||||||
unsigned &StructuredInitIndex,
|
|
||||||
Expr *expr);
|
|
||||||
int numArrayElements(QualType DeclType);
|
|
||||||
int numStructUnionElements(QualType DeclType);
|
|
||||||
public:
|
|
||||||
InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
|
|
||||||
bool HadError() { return hadError; }
|
|
||||||
|
|
||||||
// @brief Retrieves the fully-structured initializer list used for
|
|
||||||
// semantic analysis and code generation.
|
|
||||||
InitListExpr *getFullyStructuredList() const { return FullyStructuredList; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/// BlockSemaInfo - When a block is being parsed, this contains information
|
/// BlockSemaInfo - When a block is being parsed, this contains information
|
||||||
/// about the block. It is pointed to from Sema::CurBlock.
|
/// about the block. It is pointed to from Sema::CurBlock.
|
||||||
struct BlockSemaInfo {
|
struct BlockSemaInfo {
|
||||||
|
@ -1150,11 +1150,9 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InitListChecker CheckInitList(this, InitList, DeclType);
|
bool hadError = CheckInitList(InitList, DeclType);
|
||||||
if (!CheckInitList.HadError())
|
Init = InitList;
|
||||||
Init = CheckInitList.getFullyStructuredList();
|
return hadError;
|
||||||
|
|
||||||
return CheckInitList.HadError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetNameForDeclarator - Determine the full declaration name for the
|
/// GetNameForDeclarator - Determine the full declaration name for the
|
||||||
|
@ -17,8 +17,76 @@
|
|||||||
#include "clang/AST/Expr.h"
|
#include "clang/AST/Expr.h"
|
||||||
#include "clang/AST/ExprCXX.h"
|
#include "clang/AST/ExprCXX.h"
|
||||||
#include "clang/Basic/DiagnosticSema.h"
|
#include "clang/Basic/DiagnosticSema.h"
|
||||||
|
#include <map>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
|
class InitListChecker {
|
||||||
|
Sema *SemaRef;
|
||||||
|
bool hadError;
|
||||||
|
std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
|
||||||
|
InitListExpr *FullyStructuredList;
|
||||||
|
|
||||||
|
void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
|
||||||
|
unsigned &Index, InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
void CheckExplicitInitList(InitListExpr *IList, QualType &T,
|
||||||
|
unsigned &Index, InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
|
||||||
|
bool SubobjectIsDesignatorContext,
|
||||||
|
unsigned &Index,
|
||||||
|
InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
void CheckSubElementType(InitListExpr *IList, QualType ElemType,
|
||||||
|
unsigned &Index,
|
||||||
|
InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
// FIXME: Does DeclType need to be a reference type?
|
||||||
|
void CheckScalarType(InitListExpr *IList, QualType &DeclType,
|
||||||
|
unsigned &Index,
|
||||||
|
InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index,
|
||||||
|
InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
|
||||||
|
RecordDecl::field_iterator Field,
|
||||||
|
bool SubobjectIsDesignatorContext, unsigned &Index,
|
||||||
|
InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
void CheckArrayType(InitListExpr *IList, QualType &DeclType,
|
||||||
|
llvm::APSInt elementIndex,
|
||||||
|
bool SubobjectIsDesignatorContext, unsigned &Index,
|
||||||
|
InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex);
|
||||||
|
bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE,
|
||||||
|
DesignatedInitExpr::designators_iterator D,
|
||||||
|
QualType &CurrentObjectType,
|
||||||
|
RecordDecl::field_iterator *NextField,
|
||||||
|
llvm::APSInt *NextElementIndex,
|
||||||
|
unsigned &Index,
|
||||||
|
InitListExpr *StructuredList,
|
||||||
|
unsigned &StructuredIndex,
|
||||||
|
bool FinishSubobjectInit = true);
|
||||||
|
InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
|
||||||
|
QualType CurrentObjectType,
|
||||||
|
InitListExpr *StructuredList,
|
||||||
|
unsigned StructuredIndex,
|
||||||
|
SourceRange InitRange);
|
||||||
|
void UpdateStructuredListElement(InitListExpr *StructuredInitList,
|
||||||
|
unsigned &StructuredInitIndex,
|
||||||
|
Expr *expr);
|
||||||
|
int numArrayElements(QualType DeclType);
|
||||||
|
int numStructUnionElements(QualType DeclType);
|
||||||
|
public:
|
||||||
|
InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
|
||||||
|
bool HadError() { return hadError; }
|
||||||
|
|
||||||
|
// @brief Retrieves the fully-structured initializer list used for
|
||||||
|
// semantic analysis and code generation.
|
||||||
|
InitListExpr *getFullyStructuredList() const { return FullyStructuredList; }
|
||||||
|
};
|
||||||
|
|
||||||
/// Recursively replaces NULL values within the given initializer list
|
/// Recursively replaces NULL values within the given initializer list
|
||||||
/// with expressions that perform value-initialization of the
|
/// with expressions that perform value-initialization of the
|
||||||
/// appropriate type.
|
/// appropriate type.
|
||||||
@ -1003,3 +1071,11 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
|
|||||||
static_cast<Expr *>(Init.release()));
|
static_cast<Expr *>(Init.release()));
|
||||||
return Owned(DIE);
|
return Owned(DIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Sema::CheckInitList(InitListExpr *&InitList, QualType &DeclType) {
|
||||||
|
InitListChecker CheckInitList(this, InitList, DeclType);
|
||||||
|
if (!CheckInitList.HadError())
|
||||||
|
InitList = CheckInitList.getFullyStructuredList();
|
||||||
|
|
||||||
|
return CheckInitList.HadError();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user