diff options
author | Stephen Hines <srhines@google.com> | 2013-12-11 22:15:28 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-12-11 22:15:29 +0000 |
commit | f6557f87687f9414656bc121b1b70df913edc186 (patch) | |
tree | 3e149cc5fe9969254f56353f1e6a5825fb9fb37f | |
parent | 5fdd2f9ce9e0c974eebaf376a154fda81976457c (diff) | |
parent | 48d893dc7794b3cfb74f35955ca763ee4170f9ad (diff) | |
download | slang-f6557f87687f9414656bc121b1b70df913edc186.tar.gz |
Merge "Support reflection of enums."
-rw-r--r-- | slang_rs_backend.cpp | 3 | ||||
-rw-r--r-- | slang_rs_check_ast.cpp | 20 | ||||
-rw-r--r-- | slang_rs_check_ast.h | 7 | ||||
-rw-r--r-- | slang_rs_export_element.cpp | 3 | ||||
-rw-r--r-- | slang_rs_export_type.cpp | 67 | ||||
-rw-r--r-- | slang_rs_export_type.h | 2 | ||||
-rw-r--r-- | tests/P_export_types/export_types.rs | 2 |
7 files changed, 59 insertions, 45 deletions
diff --git a/slang_rs_backend.cpp b/slang_rs_backend.cpp index 541efb5..6c86f71 100644 --- a/slang_rs_backend.cpp +++ b/slang_rs_backend.cpp @@ -68,8 +68,7 @@ RSBackend::RSBackend(RSContext *Context, mExportTypeMetadata(NULL), mRSObjectSlotsMetadata(NULL), mRefCount(mContext->getASTContext()), - mASTChecker(mContext->getASTContext(), mContext->getTargetAPI(), - IsFilterscript) { + mASTChecker(Context, Context->getTargetAPI(), IsFilterscript) { } // 1) Add zero initialization of local RS object types diff --git a/slang_rs_check_ast.cpp b/slang_rs_check_ast.cpp index 14ee822..017e10c 100644 --- a/slang_rs_check_ast.cpp +++ b/slang_rs_check_ast.cpp @@ -38,7 +38,6 @@ void RSCheckAST::VisitStmt(clang::Stmt *S) { void RSCheckAST::WarnOnSetElementAt(clang::CallExpr *E) { clang::FunctionDecl *Decl; - clang::DiagnosticsEngine &DiagEngine = C.getDiagnostics(); Decl = clang::dyn_cast_or_null<clang::FunctionDecl>(E->getCalleeDecl()); if (!Decl || Decl->getNameAsString() != std::string("rsSetElementAt")) { @@ -122,7 +121,7 @@ void RSCheckAST::WarnOnSetElementAt(clang::CallExpr *E) { return; } - clang::DiagnosticBuilder DiagBuilder = DiagEngine.Report( + clang::DiagnosticBuilder DiagBuilder = mDiagEngine.Report( clang::FullSourceLoc(E->getLocStart(), mSM), mDiagEngine.getCustomDiagID( clang::DiagnosticsEngine::Warning, "untyped rsSetElementAt() can reduce performance. " @@ -196,7 +195,7 @@ void RSCheckAST::ValidateVarDecl(clang::VarDecl *VD) { if (VD->getFormalLinkage() == clang::ExternalLinkage) { llvm::StringRef TypeName; const clang::Type *T = QT.getTypePtr(); - if (!RSExportType::NormalizeType(T, TypeName, &mDiagEngine, VD)) { + if (!RSExportType::NormalizeType(T, TypeName, Context, VD)) { mValid = false; } } @@ -245,19 +244,18 @@ void RSCheckAST::VisitCastExpr(clang::CastExpr *CE) { clang::QualType QT = CE->getType(); const clang::Type *T = QT.getTypePtr(); if (T->isVectorType()) { - clang::DiagnosticsEngine &DiagEngine = C.getDiagnostics(); if (llvm::isa<clang::ImplicitCastExpr>(CE)) { - DiagEngine.Report( + mDiagEngine.Report( clang::FullSourceLoc(CE->getExprLoc(), - DiagEngine.getSourceManager()), - DiagEngine.getCustomDiagID(clang::DiagnosticsEngine::Error, + mDiagEngine.getSourceManager()), + mDiagEngine.getCustomDiagID(clang::DiagnosticsEngine::Error, "invalid implicit vector cast")); } else { - DiagEngine.Report( + mDiagEngine.Report( clang::FullSourceLoc(CE->getExprLoc(), - DiagEngine.getSourceManager()), - DiagEngine.getCustomDiagID(clang::DiagnosticsEngine::Error, - "invalid vector cast")); + mDiagEngine.getSourceManager()), + mDiagEngine.getCustomDiagID(clang::DiagnosticsEngine::Error, + "invalid vector cast")); } mValid = false; } diff --git a/slang_rs_check_ast.h b/slang_rs_check_ast.h index 53be3cf..9c86849 100644 --- a/slang_rs_check_ast.h +++ b/slang_rs_check_ast.h @@ -18,6 +18,7 @@ #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CHECK_AST_H_ #include "slang_assert.h" +#include "slang_rs_context.h" #include "clang/AST/ASTContext.h" #include "clang/AST/StmtVisitor.h" @@ -28,6 +29,7 @@ namespace slang { // casts (i.e. no pointers allowed in FS whatsoever). class RSCheckAST : public clang::StmtVisitor<RSCheckAST> { private: + slang::RSContext *Context; clang::ASTContext &C; clang::DiagnosticsEngine &mDiagEngine; clang::SourceManager &mSM; @@ -45,9 +47,10 @@ class RSCheckAST : public clang::StmtVisitor<RSCheckAST> { void WarnOnSetElementAt(clang::CallExpr*); public: - explicit RSCheckAST(clang::ASTContext &Con, unsigned int TargetAPI, + explicit RSCheckAST(RSContext *Con, unsigned int TargetAPI, bool IsFilterscript) - : C(Con), mDiagEngine(Con.getDiagnostics()), mSM(C.getSourceManager()), + : Context(Con), C(Con->getASTContext()), mDiagEngine(C.getDiagnostics()), + mSM(C.getSourceManager()), mValid(true), mTargetAPI(TargetAPI), mIsFilterscript(IsFilterscript), mInKernel(false) { return; diff --git a/slang_rs_export_element.cpp b/slang_rs_export_element.cpp index c1b9c3c..754c322 100644 --- a/slang_rs_export_element.cpp +++ b/slang_rs_export_element.cpp @@ -69,8 +69,7 @@ RSExportType *RSExportElement::Create(RSContext *Context, slangAssert(EI != NULL && "Element info not found"); - if (!RSExportType::NormalizeType(T, TypeName, Context->getDiagnostics(), - NULL)) + if (!RSExportType::NormalizeType(T, TypeName, Context, NULL)) return NULL; switch (T->getTypeClass()) { diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp index 3363594..89f2d92 100644 --- a/slang_rs_export_type.cpp +++ b/slang_rs_export_type.cpp @@ -82,7 +82,7 @@ static RSReflectionType gReflectionTypes[] = { static const clang::Type *TypeExportableHelper( const clang::Type *T, llvm::SmallPtrSet<const clang::Type*, 8>& SPS, - clang::DiagnosticsEngine *DiagEngine, + slang::RSContext *Context, const clang::VarDecl *VD, const clang::RecordDecl *TopLevelRecord); @@ -118,11 +118,15 @@ static void ReportTypeError(clang::DiagnosticsEngine *DiagEngine, static const clang::Type *ConstantArrayTypeExportableHelper( const clang::ConstantArrayType *CAT, llvm::SmallPtrSet<const clang::Type*, 8>& SPS, - clang::DiagnosticsEngine *DiagEngine, + slang::RSContext *Context, const clang::VarDecl *VD, const clang::RecordDecl *TopLevelRecord) { // Check element type const clang::Type *ElementType = GET_CONSTANT_ARRAY_ELEMENT_TYPE(CAT); + clang::DiagnosticsEngine *DiagEngine = NULL; + if (Context) { + DiagEngine = Context->getDiagnostics(); + } if (ElementType->isArrayType()) { ReportTypeError(DiagEngine, VD, TopLevelRecord, "multidimensional arrays cannot be exported: '%0'"); @@ -146,7 +150,7 @@ static const clang::Type *ConstantArrayTypeExportableHelper( } } - if (TypeExportableHelper(ElementType, SPS, DiagEngine, VD, + if (TypeExportableHelper(ElementType, SPS, Context, VD, TopLevelRecord) == NULL) { return NULL; } else { @@ -157,9 +161,13 @@ static const clang::Type *ConstantArrayTypeExportableHelper( static const clang::Type *TypeExportableHelper( clang::Type const *T, llvm::SmallPtrSet<clang::Type const *, 8> &SPS, - clang::DiagnosticsEngine *DiagEngine, + slang::RSContext *Context, clang::VarDecl const *VD, clang::RecordDecl const *TopLevelRecord) { + clang::DiagnosticsEngine *DiagEngine = NULL; + if (Context) { + DiagEngine = Context->getDiagnostics(); + } // Normalize first if ((T = GET_CANONICAL_TYPE(T)) == NULL) return NULL; @@ -233,7 +241,7 @@ static const clang::Type *TypeExportableHelper( const clang::Type *FT = RSExportType::GetTypeOfDecl(FD); FT = GET_CANONICAL_TYPE(FT); - if (!TypeExportableHelper(FT, SPS, DiagEngine, VD, TopLevelRecord)) { + if (!TypeExportableHelper(FT, SPS, Context, VD, TopLevelRecord)) { return NULL; } @@ -276,7 +284,7 @@ static const clang::Type *TypeExportableHelper( // We don't support pointer with array-type pointee or unsupported pointee // type if (PointeeType->isArrayType() || - (TypeExportableHelper(PointeeType, SPS, DiagEngine, VD, + (TypeExportableHelper(PointeeType, SPS, Context, VD, TopLevelRecord) == NULL)) return NULL; else @@ -293,7 +301,7 @@ static const clang::Type *TypeExportableHelper( const clang::Type *ElementType = GET_EXT_VECTOR_ELEMENT_TYPE(EVT); if ((ElementType->getTypeClass() != clang::Type::Builtin) || - (TypeExportableHelper(ElementType, SPS, DiagEngine, VD, + (TypeExportableHelper(ElementType, SPS, Context, VD, TopLevelRecord) == NULL)) return NULL; else @@ -303,10 +311,16 @@ static const clang::Type *TypeExportableHelper( const clang::ConstantArrayType *CAT = UNSAFE_CAST_TYPE(const clang::ConstantArrayType, T); - return ConstantArrayTypeExportableHelper(CAT, SPS, DiagEngine, VD, + return ConstantArrayTypeExportableHelper(CAT, SPS, Context, VD, TopLevelRecord); } + case clang::Type::Enum: { + // FIXME: We currently convert enums to integers, rather than reflecting + // a more complete (and nicer type-safe Java version). + return Context->getASTContext().IntTy.getTypePtr(); + } default: { + slangAssert(false && "Unknown type cannot be validated"); return NULL; } } @@ -320,12 +334,12 @@ static const clang::Type *TypeExportableHelper( // highest struct (in the case of a nested hierarchy) for detecting other // types that cannot be exported (mostly pointers within a struct). static const clang::Type *TypeExportable(const clang::Type *T, - clang::DiagnosticsEngine *DiagEngine, + slang::RSContext *Context, const clang::VarDecl *VD) { llvm::SmallPtrSet<const clang::Type*, 8> SPS = llvm::SmallPtrSet<const clang::Type*, 8>(); - return TypeExportableHelper(T, SPS, DiagEngine, VD, NULL); + return TypeExportableHelper(T, SPS, Context, VD, NULL); } static bool ValidateRSObjectInVarDecl(clang::VarDecl *VD, @@ -544,26 +558,25 @@ static bool ValidateTypeHelper( /****************************** RSExportType ******************************/ bool RSExportType::NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName, - clang::DiagnosticsEngine *DiagEngine, + RSContext *Context, const clang::VarDecl *VD) { - if ((T = TypeExportable(T, DiagEngine, VD)) == NULL) { + if ((T = TypeExportable(T, Context, VD)) == NULL) { return false; } // Get type name TypeName = RSExportType::GetTypeName(T); - if (TypeName.empty()) { - if (DiagEngine) { - if (VD) { - DiagEngine->Report( - clang::FullSourceLoc(VD->getLocation(), - DiagEngine->getSourceManager()), - DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, - "anonymous types cannot be exported")); - } else { - DiagEngine->Report( - DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, - "anonymous types cannot be exported")); - } + if (Context && TypeName.empty()) { + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); + if (VD) { + DiagEngine->Report( + clang::FullSourceLoc(VD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "anonymous types cannot be exported")); + } else { + DiagEngine->Report( + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "anonymous types cannot be exported")); } return false; } @@ -780,7 +793,7 @@ RSExportType *RSExportType::Create(RSContext *Context, RSExportType *RSExportType::Create(RSContext *Context, const clang::Type *T) { llvm::StringRef TypeName; - if (NormalizeType(T, TypeName, Context->getDiagnostics(), NULL)) { + if (NormalizeType(T, TypeName, Context, NULL)) { return Create(Context, T, TypeName); } else { return NULL; @@ -1030,7 +1043,7 @@ RSExportPrimitiveType RSExportPrimitiveType *RSExportPrimitiveType::Create(RSContext *Context, const clang::Type *T) { llvm::StringRef TypeName; - if (RSExportType::NormalizeType(T, TypeName, Context->getDiagnostics(), NULL) + if (RSExportType::NormalizeType(T, TypeName, Context, NULL) && IsPrimitiveType(T)) { return Create(Context, T, TypeName); } else { diff --git a/slang_rs_export_type.h b/slang_rs_export_type.h index e9af953..e13b817 100644 --- a/slang_rs_export_type.h +++ b/slang_rs_export_type.h @@ -154,7 +154,7 @@ class RSExportType : public RSExportable { // If it is not, this function returns false. Otherwise it returns true. static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName, - clang::DiagnosticsEngine *Diags, + RSContext *Context, const clang::VarDecl *VD); // This function checks whether the specified type can be handled by RS/FS. diff --git a/tests/P_export_types/export_types.rs b/tests/P_export_types/export_types.rs index f6c0f3c..01a1205 100644 --- a/tests/P_export_types/export_types.rs +++ b/tests/P_export_types/export_types.rs @@ -27,6 +27,8 @@ rs_program_vertex program_vertex; rs_program_raster program_raster; rs_program_store program_store; rs_font font; +rs_data_kind dk; +rs_data_type dt; float *fp; int *ip; |