Ejemplo n.º 1
0
 boost::python::list get_children(clang::DeclContext& decl)
 { 
     boost::python::list children = boost::python::list();
     for(auto it = decl.decls_begin(), it_end = decl.decls_end(); it != it_end; ++it)
     { children.append(boost::python::ptr(*it)); }
     return children; 
 }
Ejemplo n.º 2
0
  void init(clang::Decl *D) {
    clang::FunctionDecl *FD = clang::dyn_cast<clang::FunctionDecl>(D);
    for (clang::FunctionDecl::param_iterator P = FD->param_begin();
            P != FD->param_end(); ++P) {
        clang::ParmVarDecl *Parm = *P;
        const char *varName = Parm->getNameAsString().c_str();
        clang::QualType ty = Parm->getType();
        if (ty->isScalarType()) {
            char *s = strdup_e(varName);
            numerics.insert(s);
            printf("Tracking numeric paramater variable %s\n", s);
        }
    }
    
    dc = clang::cast<clang::DeclContext>(D);

    for (clang::DeclContext::specific_decl_iterator<clang::VarDecl>
           I(dc->decls_begin()), E(dc->decls_end()); I != E; ++I) {
        const clang::VarDecl *vd = *I;
  
        if (!isTrackedVar(vd))
            continue;
  
        const char *varName = vd->getNameAsString().c_str();
        clang::QualType ty = vd->getType();
        if (ty->isScalarType()) {
            char *name = strdup_e(varName);
            numerics.insert(name);
            printf("Tracking numeric variable %s\n", name);
        } else if (ty->isArrayType()) {
            const clang::ArrayType *at = ty->getAsArrayTypeUnsafe();
            const clang::ConstantArrayType *cat;
            if (!(cat = clang::dyn_cast<const clang::ConstantArrayType>(at))) {
                printf("Can't handle non-constant arrays (%s). Aborting\n",
                        varName);
                exit(1);
            }
            char *name = strdup_e(varName);
            const unsigned long size = *cat->getSize().getRawData();
            array2size[name] = size;
            printf("Tracking array variable %s\n", name);
        }
    }

    ap_var_t temp_ap_var_array[numerics.size()];
    int i = 0;
    for (std::set<char *>::iterator it = numerics.begin(); it != numerics.end();
            ++it) {
        temp_ap_var_array[i++] = (ap_var_t)(*it);
    }

    // Assuming integers only. The allocation copies the content of
    // temp_ap_var_array so its OK its local
    env = ap_environment_alloc(temp_ap_var_array, numerics.size(), NULL, 0);
  }