bool RSExportForEach::validateSpecialFuncDecl(int targetAPI, clang::DiagnosticsEngine *DiagEngine, clang::FunctionDecl const *FD) { slangAssert(DiagEngine && FD); bool valid = true; const clang::ASTContext &C = FD->getASTContext(); if (isRootRSFunc(FD)) { unsigned int numParams = FD->getNumParams(); if (numParams == 0) { // Graphics root function, so verify that it returns an int if (FD->getResultType().getCanonicalType() != C.IntTy) { DiagEngine->Report( clang::FullSourceLoc(FD->getLocation(), DiagEngine->getSourceManager()), DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, "root(void) is required to return " "an int for graphics usage")); valid = false; } } else if ((targetAPI < SLANG_ICS_TARGET_API) && (numParams == 1)) { // Legacy graphics root function // This has already been validated in isRSForEachFunc(). } else { slangAssert(false && "Should not call validateSpecialFuncDecl() on compute root()"); } } else if (isInitRSFunc(FD) || isDtorRSFunc(FD)) { if (FD->getNumParams() != 0) { DiagEngine->Report( clang::FullSourceLoc(FD->getLocation(), DiagEngine->getSourceManager()), DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, "%0(void) is required to have no " "parameters")) << FD->getName(); valid = false; } if (FD->getResultType().getCanonicalType() != C.VoidTy) { DiagEngine->Report( clang::FullSourceLoc(FD->getLocation(), DiagEngine->getSourceManager()), DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, "%0(void) is required to have a void " "return type")) << FD->getName(); valid = false; } } else { slangAssert(false && "must be called on root, init or .rs.dtor function!"); } return valid; }
bool RSSpecialFunc::validateSpecialFuncDecl(unsigned int targetAPI, slang::RSContext *Context, clang::FunctionDecl const *FD) { slangAssert(Context && FD); bool valid = true; const clang::ASTContext &C = FD->getASTContext(); const clang::QualType &IntType = FD->getASTContext().IntTy; if (isGraphicsRootRSFunc(targetAPI, FD)) { if ((targetAPI < SLANG_ICS_TARGET_API) && (FD->getNumParams() == 1)) { // Legacy graphics root function const clang::ParmVarDecl *PVD = FD->getParamDecl(0); clang::QualType QT = PVD->getType().getCanonicalType(); if (QT != IntType) { Context->ReportError(PVD->getLocation(), "invalid parameter type for legacy " "graphics root() function: %0") << PVD->getType(); valid = false; } } // Graphics root function, so verify that it returns an int if (FD->getReturnType().getCanonicalType() != IntType) { Context->ReportError(FD->getLocation(), "root() is required to return " "an int for graphics usage"); valid = false; } } else if (isInitRSFunc(FD) || isDtorRSFunc(FD)) { if (FD->getNumParams() != 0) { Context->ReportError(FD->getLocation(), "%0(void) is required to have no " "parameters") << FD->getName(); valid = false; } if (FD->getReturnType().getCanonicalType() != C.VoidTy) { Context->ReportError(FD->getLocation(), "%0(void) is required to have a void " "return type") << FD->getName(); valid = false; } } else { slangAssert(false && "must be called on root, init or .rs.dtor function!"); } return valid; }