slang_rs_export_func.cpp revision 462aefd62cc646d2ff753c1d003ef3cd7bbea262
1#include "slang_rs_context.hpp" 2#include "slang_rs_export_func.hpp" 3#include "slang_rs_export_type.hpp" 4 5#include "clang/AST/Decl.h" /* for clang::*Decl */ 6 7namespace slang { 8 9RSExportFunc* RSExportFunc::Create(RSContext* Context, const FunctionDecl* FD) { 10 llvm::StringRef Name = FD->getName(); 11 RSExportFunc* F; 12 13 assert(!Name.empty() && "Function must have a name"); 14 15 F = new RSExportFunc(Context, Name); 16 17 /* Check whether the parameters passed to the function is exportable */ 18 for(int i=0;i<FD->getNumParams();i++) { 19 const ParmVarDecl* PVD = FD->getParamDecl(i); 20 const llvm::StringRef ParamName = PVD->getName(); 21 22 assert(!ParamName.empty() && "Parameter must have a name"); 23 24 if(PVD->hasDefaultArg()) 25 printf("Note: parameter '%s' in function '%s' has default value will not support\n", ParamName.str().c_str(), Name.str().c_str()); 26 27 /* Check type */ 28 RSExportType* PET = RSExportType::CreateFromDecl(Context, PVD); 29 if(PET != NULL) { 30 F->mParams.push_back(new Parameter(PET, ParamName)); 31 } else { 32 printf("Note: parameter '%s' in function '%s' uses unsupported type", ParamName.str().c_str(), Name.str().c_str()); 33 delete F; 34 return NULL; 35 } 36 } 37 38 return F; 39} 40 41const RSExportRecordType* RSExportFunc::getParamPacketType() const { 42 /* Pack parameters */ 43 if((mParamPacketType == NULL) && hasParam()) { 44 int Index = 0; 45 RSExportRecordType* ParamPacketType = new RSExportRecordType(mContext, "", false /* IsPacked */, true /* IsArtificial */); 46 47 for(const_param_iterator PI = params_begin(); 48 PI != params_end(); 49 PI++, Index++) 50 ParamPacketType->mFields.push_back( new RSExportRecordType::Field((*PI)->getType(), (*PI)->getName(), ParamPacketType, Index) ); 51 52 mParamPacketType = ParamPacketType; 53 } 54 55 return mParamPacketType; 56} 57 58RSExportFunc::~RSExportFunc() { 59 for(const_param_iterator PI = params_begin(); 60 PI != params_end(); 61 PI++) 62 delete *PI; 63 64 if(mParamPacketType != NULL) 65 delete mParamPacketType; 66 67 return; 68} 69 70} /* namespace slang */ 71