enum CXChildVisitResult visit_enum(CXCursor cursor, CXCursor parent, CXClientData data) { json_t* structure = (json_t*)data; json_t* js = NULL; switch (clang_getCursorKind(cursor)) { case CXCursor_EnumConstantDecl: js = json_object(); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); json_object_set_new(js, "value", json_integer(clang_getEnumConstantDeclValue(cursor))); json_object_set_new(js, "type", render_type(clang_getCursorType(cursor))); json_array_append_new(json_object_get(structure, "values"), js); break; default: break; } return CXChildVisit_Continue; }
void ZFramework3D::updateUi() { ZMeshSpace::ZMeshAlgorithms* handler = ZDataManager::getDataManager()->getAlgorithmHandler(); QGLViewerWidget* wiget = this->ui.widget; MeshRenderer* mr = (MeshRenderer*)wiget->getRenderer(); if (ui.cobIsoLines->currentText()==render_type(RENDER_TYPE_IP_LINES_BY_CLUSTERID)) { int clusterK = handler->getIsoLineContainer().getKmeansK(); ui.hSliderIsoLine->setMinimum(-1); ui.hSliderIsoLine->setMaximum(clusterK-1); ui.hSliderIsoLine->setSliderPosition(-1); } else { int isoSize = handler->getIsoLineSize(); ui.hSliderIsoLine->setMinimum(-1); ui.hSliderIsoLine->setMaximum(isoSize-1); ui.hSliderIsoLine->setSliderPosition(-1); } }
void ZFramework3D::slot_update_render_opt() { //updateUi(); QGLViewerWidget* wiget = this->ui.widget; MeshRenderer* mr = (MeshRenderer*)wiget->getRenderer(); ZMeshSpace::ZMeshAlgorithms* handler = ZDataManager::getDataManager()->getAlgorithmHandler(); mr->setRenderWireFrame(ui.cbRenderWireframe->isChecked()); mr->setRenderType(ui.cobRenderType->currentText().toStdString()); mr->getRenderOption().show_iso_lines = ui.cbIsoLines->isChecked(); mr->getRenderOption().show_iso_plane = ui.cbShowIsoLines->isChecked(); mr->getRenderOption().translucent = ui.cbTransparency->isChecked(); mr->getRenderOption().strRenderIsoPlaneMethod = ui.cobIsoLines->currentText().toStdString(); mr->getRenderOption().show_kmeans_center_plane = ui.cbShowKmeanPlane->isChecked(); mr->getRenderOption().show_iso_plane_plane_list = ui.cbClusteredLines->isChecked(); mr->getRenderOption().show_face_normals = ui.cbShowNormals->isChecked(); ui.cobIsoLines->setEnabled(ui.cbShowIsoLines->isChecked()); mr->getRenderOption().show_iso_line_by_id = ui.cbOneByOne->isChecked(); ui.hSliderIsoLine->setEnabled(ui.cbOneByOne->isChecked()); ui.labelIsoLineIdx->setEnabled(ui.cbOneByOne->isChecked()); mr->getRenderOption().show_cvt_init_samples = ui.cbShowCVTSamples->isChecked(); mr->getRenderOption().show_cvt_delaunay = ui.cbShowCVTDelaunay->isChecked(); mr->getRenderOption().show_cvt_voronoi = ui.cbShowCVTVoronoi->isChecked(); mr->getRenderOption().show_cvt_clippingRegion = ui.cbShowCVTClippingRegion->isChecked(); mr->getRenderOption().show_cvt_voronoi_vertices = ui.cbShowCVTVoronoiVertices->isChecked(); mr->getRenderOption().show_cvt_vertices = ui.cbShowCVTDelaunayVertices->isChecked(); int curPos = ui.hSliderIsoLine->sliderPosition(); handler->setCurrentIsoLineIdx(curPos); bool bCluster = (ui.cobIsoLines->currentText()==render_type(RENDER_TYPE_IP_LINES_BY_CLUSTERID)); QString str;//("IsoLineIdx: "); str = bCluster ? ("ClusterId: ") : ("IsoLineIdx: "); str += QString::number(curPos); ui.labelIsoLineIdx->setText(str); updateViews(); }
int render_av_rule(avtab_key_t * key, avtab_datum_t * datum, uint32_t what, policydb_t * p, FILE * fp) { if (!(what & RENDER_UNCONDITIONAL)) { if (what != RENDER_CONDITIONAL && (((what & RENDER_ENABLED) && !(key-> specified & AVTAB_ENABLED)) || ((what & RENDER_DISABLED) && (key-> specified & AVTAB_ENABLED)))) { return 0; /* doesn't match selection criteria */ } } if (!(what & RENDER_UNCONDITIONAL)) { if (key->specified & AVTAB_ENABLED) fprintf(fp, "[enabled] "); else if (!(key->specified & AVTAB_ENABLED)) fprintf(fp, "[disabled] "); } if (key->specified & AVTAB_AV) { if (key->specified & AVTAB_ALLOWED) { fprintf(fp, "allow "); render_key(key, p, fp); render_access_mask(datum->data, key, p, fp); fprintf(fp, ";\n"); } if (key->specified & AVTAB_AUDITALLOW) { fprintf(fp, "auditallow "); render_key(key, p, fp); render_access_mask(datum->data, key, p, fp); fprintf(fp, ";\n"); } if (key->specified & AVTAB_AUDITDENY) { fprintf(fp, "dontaudit "); render_key(key, p, fp); /* We inverse the mask for dontaudit since the mask is internally stored * as a auditdeny mask */ render_access_mask(~datum->data, key, p, fp); fprintf(fp, ";\n"); } } else if (key->specified & AVTAB_TYPE) { if (key->specified & AVTAB_TRANSITION) { fprintf(fp, "type_transition "); render_key(key, p, fp); render_type(datum->data, p, fp); fprintf(fp, ";\n"); } if (key->specified & AVTAB_MEMBER) { fprintf(fp, "type_member "); render_key(key, p, fp); render_type(datum->data, p, fp); fprintf(fp, ";\n"); } if (key->specified & AVTAB_CHANGE) { fprintf(fp, "type_change "); render_key(key, p, fp); render_type(datum->data, p, fp); fprintf(fp, ";\n"); } } else if (key->specified & AVTAB_OP) { if (key->specified & (AVTAB_OPNUM_ALLOWED|AVTAB_OPTYPE_ALLOWED)) fprintf(fp, "allow "); else if (key->specified & (AVTAB_OPNUM_AUDITALLOW|AVTAB_OPTYPE_AUDITALLOW)) fprintf(fp, "auditallow "); else if (key->specified & (AVTAB_OPNUM_DONTAUDIT|AVTAB_OPTYPE_DONTAUDIT)) fprintf(fp, "dontaudit "); render_key(key, p, fp); render_operations(datum->ops, key, fp); fprintf(fp, ";\n"); } else { fprintf(fp, " ERROR: no valid rule type specified\n"); return -1; } return 0; }
json_t* render_type(CXType type) { int i; CXCursor decl = clang_getTypeDeclaration(type); json_t* js = json_object(); enum CXTypeKind kind = type.kind; if (type.kind == CXType_Unexposed) { // workaround for libclang bug if (clang_getResultType(type).kind != CXType_Invalid) { kind = CXType_FunctionProto; } } if (clang_isVolatileQualifiedType(type)) { json_object_set_new(js, "volatile", json_true()); } if (clang_isConstQualifiedType(type)) { json_object_set_new(js, "const", json_true()); } if (clang_isRestrictQualifiedType(type)) { json_object_set_new(js, "restrict", json_true()); } static const struct { enum CXTypeKind kind; const char* name; } PRIMITIVE_TYPES[] = { {CXType_Void, "void"}, {CXType_Bool, "bool"}, {CXType_Char_U, "char"}, {CXType_Char_S, "char"}, {CXType_UChar, "unsigned char"}, {CXType_SChar, "signed char"}, {CXType_WChar, "wchar_t"}, {CXType_Char16, "char16_t"}, {CXType_Char32, "char32_t"}, {CXType_Short, "short"}, {CXType_UShort, "unsigned short"}, {CXType_Int, "int"}, {CXType_UInt, "unsigned int"}, {CXType_Long, "long"}, {CXType_ULong, "unsigned long"}, {CXType_LongLong, "unsigned long"}, {CXType_ULongLong, "unsigned long long"}, {CXType_Int128, "__int128"}, {CXType_UInt128, "unsigned __int128"}, {CXType_Float, "float"}, {CXType_Double, "double"}, {CXType_LongDouble, "long double"} }; switch (kind) { case CXType_Pointer: json_object_set_new(js, "kind", json_string("pointer")); json_object_set_new(js, "pointee", render_type(clang_getPointeeType(type))); return js; case CXType_ConstantArray: json_object_set_new(js, "kind", json_string("array")); json_object_set_new(js, "element", render_type(clang_getArrayElementType(type))); json_object_set_new(js, "length", json_integer(clang_getArraySize(type))); return js; case CXType_FunctionNoProto: case CXType_FunctionProto: json_object_set_new(js, "kind", json_string("function")); json_object_set_new(js, "return", render_type(clang_getResultType(type))); switch (clang_getFunctionTypeCallingConv(type)) { case CXCallingConv_C: json_object_set_new(js, "calling_convention", json_string("cdecl")); break; case CXCallingConv_X86StdCall: json_object_set_new(js, "calling_convention", json_string("stdcall")); break; case CXCallingConv_X86FastCall: json_object_set_new(js, "calling_convention", json_string("fastcall")); break; case CXCallingConv_X86ThisCall: json_object_set_new(js, "calling_convention", json_string("thiscall")); break; case CXCallingConv_X86Pascal: json_object_set_new(js, "calling_convention", json_string("pascal")); break; case CXCallingConv_AAPCS: json_object_set_new(js, "calling_convention", json_string("aapcs")); break; case CXCallingConv_AAPCS_VFP: json_object_set_new(js, "calling_convention", json_string("aapcs-vfp")); break; default: break; } json_t* arguments = json_array(); for (i=0; i<clang_getNumArgTypes(type); i++) { json_array_append_new(arguments, render_type(clang_getArgType(type, i))); } json_object_set_new(js, "arguments", arguments); return js; default: if (clang_getCursorKind(decl) != CXCursor_NoDeclFound) { json_object_set_new(js, "kind", json_string("ref")); json_object_set_new(js, "id", render_string(clang_getCursorUSR(decl))); } else { int found = 0, i; for (i=0; i<sizeof(PRIMITIVE_TYPES)/sizeof(PRIMITIVE_TYPES[0]); i++) { if (PRIMITIVE_TYPES[i].kind == kind) { json_object_set_new(js, "kind", json_string("primitive")); json_object_set_new(js, "primitive", json_string(PRIMITIVE_TYPES[i].name)); found = 1; break; } } if (!found) { json_object_set_new(js, "kind", json_string("unknown")); json_object_set_new(js, "clang_kind", render_string(clang_getTypeKindSpelling(kind))); } } return js; } }
enum CXChildVisitResult visit_program(CXCursor cursor, CXCursor parent, CXClientData data){ json_t* program = (json_t*)data; json_t* js = NULL; enum CXChildVisitResult ret = CXChildVisit_Continue; switch (clang_getCursorKind(cursor)) { case CXCursor_FunctionDecl: case CXCursor_VarDecl: js = json_object(); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); json_object_set_new(js, "display_name", render_string(clang_getCursorDisplayName(cursor))); json_object_set_new(js, "type", render_type(clang_getCursorType(cursor))); if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) { json_object_set_new(js, "argument_names", json_array()); json_object_set_new(js, "kind", json_string("function")); } else { json_object_set_new(js, "kind", json_string("variable")); } switch (clang_getCursorLinkage(cursor)) { case CXLinkage_Internal: json_object_set_new(js, "linkage", json_string("static")); break; case CXLinkage_UniqueExternal: json_object_set_new(js, "linkage", json_string("anonymous")); break; case CXLinkage_External: break; default: json_object_set_new(js, "linkage", json_string("unknown")); } clang_visitChildren(cursor, visit_object, (CXClientData)js); break; case CXCursor_StructDecl: case CXCursor_UnionDecl: js = json_object(); json_object_set_new(js, "kind", json_string(clang_getCursorKind(cursor) == CXCursor_UnionDecl ? "union" : "struct")); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); json_object_set_new(js, "fields", json_array()); clang_visitChildren(cursor, visit_structure, (CXClientData)js); ret = CXChildVisit_Recurse; break; case CXCursor_EnumDecl: js = json_object(); json_object_set_new(js, "kind", json_string("enum")); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); json_object_set_new(js, "values", json_array()); clang_visitChildren(cursor, visit_enum, (CXClientData)js); break; case CXCursor_TypedefDecl: js = json_object(); json_object_set_new(js, "kind", json_string("typedef")); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); json_object_set_new(js, "type", render_type(clang_getTypedefDeclUnderlyingType(cursor))); ret = CXChildVisit_Recurse; break; case CXCursor_FieldDecl: break; case CXCursor_MacroDefinition: js = json_object(); json_object_set_new(js, "kind", json_string("macro")); { CXToken* tokens; unsigned ntokens, i; CXString name = clang_getCursorSpelling(cursor); char value_buf[1024] = ""; json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); clang_tokenize(TU, clang_getCursorExtent(cursor), &tokens, &ntokens); for (i=0; i<ntokens; i++) { CXString str = clang_getTokenSpelling(TU, tokens[i]); CXTokenKind tkind = clang_getTokenKind(tokens[i]); if (i == 0 && !strcmp(clang_getCString(name), clang_getCString(str))) { // macro name } else if (i == ntokens - 1 && tkind == CXToken_Punctuation && !strcmp("#", clang_getCString(str))) { // weird clang terminator thingy } else if (tkind == CXToken_Comment) { // comment } else { if (strlen(value_buf) > 0) { strncat(value_buf, " ", sizeof(value_buf) - strlen(value_buf) - 1); } strncat(value_buf, clang_getCString(str), sizeof(value_buf) - strlen(value_buf) - 1); } clang_disposeString(str); } clang_disposeTokens(TU, tokens, ntokens); if (strlen(value_buf) > 0) { long int intval; double dblval; char* endptr_int; char* endptr_dbl; intval = strtol(value_buf, &endptr_int, 0); dblval = strtod(value_buf, &endptr_dbl); if (endptr_int[0] == 0 || (endptr_int[1] == 0 && strchr("UuLl", endptr_int[0]) != NULL)) { json_object_set_new(js, "value", json_integer(intval)); } else if (endptr_dbl[0] == 0 || (endptr_dbl[1] == 0 && strchr("fF", endptr_dbl[0]) != NULL)) { json_object_set_new(js, "value", json_real(dblval)); } else { json_object_set_new(js, "value", json_string(value_buf)); } } } break; /* case CXCursor_PreprocessingDirective: case CXCursor_MacroExpansion: js = json_object(); json_object_set_new(js, "kind", json_string("macro")); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); putstring(clang_getCursorSpelling(cursor)); putstring(clang_getCursorDisplayName(cursor)); printf("%d\n", clang_getEnumConstantDeclValue(cursor)); ret = CXChildVisit_Recurse; */ default: js = json_object(); json_object_set_new(js, "name", render_string(clang_getCursorSpelling(cursor))); json_object_set_new(js, "type", render_type(clang_getCursorType(cursor))); json_object_set_new(js, "kind", json_string("wtf")); json_object_set_new(js, "wtf", render_string(clang_getCursorKindSpelling(clang_getCursorKind(cursor)))); } if (js) { json_t* str; if (!json_object_get(program, "")) json_object_set_new(program, "", json_array()); str = render_string(clang_getCursorUSR(cursor)); if (strlen(json_string_value(str)) == 0) { json_decref(str); json_array_append_new(json_object_get(program, ""), js); } else { json_object_set_with_key_new(program, render_string(clang_getCursorUSR(cursor)), js); } } return ret; }