summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/Sema.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-28 21:54:33 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-28 21:54:33 +0000
commit347f7eabb9ae43482f04855cde43f9d164b7b6f0 (patch)
treeb167e4bf7fc08a2d9c09efd46cb7775daed2b521 /clang/lib/Sema/Sema.h
parentc78320960513fe9f193104cbb07b0a5711c81ee0 (diff)
downloadbcm5719-llvm-347f7eabb9ae43482f04855cde43f9d164b7b6f0.tar.gz
bcm5719-llvm-347f7eabb9ae43482f04855cde43f9d164b7b6f0.zip
Code generation support for C99 designated initializers.
The approach I've taken in this patch is relatively straightforward, although the code itself is non-trivial. Essentially, as we process an initializer list we build up a fully-explicit representation of the initializer list, where each of the subobject initializations occurs in order. Designators serve to "fill in" subobject initializations in a non-linear way. The fully-explicit representation makes initializer lists (both with and without designators) easy to grok for codegen and later semantic analyses. We keep the syntactic form of the initializer list linked into the AST for those clients interested in exactly what the user wrote. Known limitations: - Designating a member of a union that isn't the first member may result in bogus initialization (we warn about this) - GNU array-range designators are not supported (we warn about this) llvm-svn: 63242
Diffstat (limited to 'clang/lib/Sema/Sema.h')
-rw-r--r--clang/lib/Sema/Sema.h50
1 files changed, 40 insertions, 10 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index d017e6f9c7b..8cf10ff3e2a 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -28,6 +28,7 @@
#include "llvm/ADT/OwningPtr.h"
#include <string>
#include <vector>
+#include <map>
namespace llvm {
class APSInt;
@@ -1835,38 +1836,67 @@ private:
class InitListChecker {
Sema *SemaRef;
bool hadError;
+ std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
+ InitListExpr *FullyStructuredList;
void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
- unsigned &Index);
+ unsigned &Index, InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
void CheckExplicitInitList(InitListExpr *IList, QualType &T,
- unsigned &Index);
-
+ unsigned &Index, InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
bool SubobjectIsDesignatorContext,
- unsigned &Index);
+ unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
void CheckSubElementType(InitListExpr *IList, QualType ElemType,
- Expr *expr, unsigned &Index);
+ Expr *expr, unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
// FIXME: Does DeclType need to be a reference type?
void CheckScalarType(InitListExpr *IList, QualType &DeclType,
- Expr *expr, unsigned &Index);
- void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index);
+ Expr *expr, 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);
+ bool SubobjectIsDesignatorContext, unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
void CheckArrayType(InitListExpr *IList, QualType &DeclType,
llvm::APSInt elementIndex,
- bool SubobjectIsDesignatorContext, unsigned &Index);
+ 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);
+ unsigned &Index,
+ InitListExpr *StructuredList,
+ unsigned &StructuredIndex);
+ 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
OpenPOWER on IntegriCloud