void main() { int i; struct map_type **points, *result; function *functions; functions = get_functions(); points = get_start_points(); for( i = 0; i < 5; i++ ) { printf("<func %d>\n", i + 1 ); show( "Start X", *( points + i ) ); result = dfp( *( functions + i ), *( points + i ), 0.0000100f, 0.0000100f, 500 ); printf( "Value %.10Lf\n", (long double)( *( functions + i ) )( result ) ); show( "X", result ); printf("</func %d>\n\n", i + 1 ); } free( points ); free( functions ); }
/** * Helper to initialize the PDH library. Loads the library and sets up the functions. * Note that once loaded, we will never unload the PDH library. * * @return CONFIG_SUCCESSFUL if successful, negative on failure. */ int perfInit(void) { static HMODULE h; static BOOL running, inited; int error; if (running) { return CONFIG_SUCCESSFUL; } error = CONFIG_SUCCESSFUL; // this is double checked locking again, but we try to bypass the worst by // implicit membar at end of lock. EnterCriticalSection(&initializationLock); { if (!inited) { char buf[64] = ""; SYSTEM_INFO si; // CMH. But windows will not care about our affinity when giving // us measurements. Need the real, raw num cpus. GetSystemInfo(&si); num_cpus = si.dwNumberOfProcessors; // Initialize the denominator for the jvm load calculations cpuFactor = num_cpus * 100; /** * Do this dynamically, so we don't fail to start on systems without pdh. */ if ((h = LoadLibrary("pdh.dll")) == NULL) { /* printf("Could not load pdh.dll (%d)", GetLastError()); */ error = -2; } else if (get_functions(h, buf, sizeof(buf)) < 0) { FreeLibrary(h); h = NULL; error = -2; /* printf("Failed to init pdh functions: %s.\n", buf); */ } else { if (initProcessorCounters() != 0) { /* printf("Failed to init system load counters.\n"); */ } else if (initProcLoadCounter() != 0) { /* printf("Failed to init process load counter.\n"); */ } else if (initProcSystemLoadCounter() != 0) { /* printf("Failed to init process system load counter.\n"); */ } else { inited = true; } } } } LeaveCriticalSection(&initializationLock); if (inited && error == CONFIG_SUCCESSFUL) { running = true; } return error; }
int before_block_exec(CPUState *env, TranslationBlock *tb) { target_ulong callers[64]; if (tb->pc == blockpc) { printf("Func stack @ 0x" TARGET_FMT_lx ": ", blockpc); int n = get_functions(callers, 64, env); for (int i = n - 1; i >= 0; i--) { printf(TARGET_FMT_lx " ", callers[i]); } printf("\n"); } return 0; }
bool ScriptTextEditor::goto_method(const String& p_method) { Vector<String> functions = get_functions(); String method_search = p_method + ":"; for (int i=0;i<functions.size();i++) { String function=functions[i]; if (function.begins_with(method_search)) { int line=function.get_slice(":",1).to_int(); goto_line(line-1); return true; } } return false; }
void testFuncParser(char *buf) { printf("===== Testing function parser ======\n"); // time_t start = GetTickCount(); FunctionList li; //fflush(stdout); std::map<std::string, std::string> ignoreTokens; get_functions(buf, li, ignoreTokens); // time_t end = GetTickCount(); for (FunctionList::iterator iter = li.begin(); iter != li.end(); iter++) { //test the var parser on the function argument list: clFunction f = (*iter); f.Print(); //testVarParser((char*)f.m_signature.c_str()); printf("%s\n", f.m_name.c_str()); } // printf("total time: %d\n", end-start); printf("matches found: %d\n", li.size()); }
int main(void) { get_functions(&funcs); test_lib_info(); #ifdef HW_TESTS test_initalize(); test_token_info(); test_mechanism_list_and_info(); test_session(); test_login(); test_import_and_sign_all_10(); test_import_and_sign_all_10_RSA(); #else fprintf(stderr, "HARDWARE TESTS DISABLED!, skipping...\n"); #endif return EXIT_SUCCESS; }
void remove_virtual_functionst::remove_virtual_function( goto_programt &goto_program, goto_programt::targett target) { const code_function_callt &code= to_code_function_call(target->code); const auto &vcall_source_loc=target->source_location; const exprt &function=code.function(); assert(function.id()==ID_virtual_function); assert(!code.arguments().empty()); functionst functions; get_functions(function, functions); if(functions.empty()) { target->make_skip(); return; // give up } // only one option? if(functions.size()==1) { assert(target->is_function_call()); if(functions.begin()->symbol_expr==symbol_exprt()) target->make_skip(); else to_code_function_call(target->code).function()= functions.begin()->symbol_expr; return; } // the final target is a skip goto_programt final_skip; goto_programt::targett t_final=final_skip.add_instruction(); t_final->source_location=vcall_source_loc; t_final->make_skip(); // build the calls and gotos goto_programt new_code_calls; goto_programt new_code_gotos; exprt this_expr=code.arguments()[0]; // If necessary, cast to the last candidate function to // get the object's clsid. By the structure of get_functions, // this is the parent of all other classes under consideration. const auto &base_classid=functions.back().class_id; const auto &base_function_symbol=functions.back().symbol_expr; symbol_typet suggested_type(base_classid); exprt c_id2=get_class_identifier_field(this_expr, suggested_type, ns); std::map<irep_idt, goto_programt::targett> calls; // Note backwards iteration, to get the least-derived candidate first. for(auto it=functions.crbegin(), itend=functions.crend(); it!=itend; ++it) { const auto &fun=*it; auto insertit=calls.insert( {fun.symbol_expr.get_identifier(), goto_programt::targett()}); // Only create one call sequence per possible target: if(insertit.second) { goto_programt::targett t1=new_code_calls.add_instruction(); t1->source_location=vcall_source_loc; if(!fun.symbol_expr.get_identifier().empty()) { // call function t1->make_function_call(code); auto &newcall=to_code_function_call(t1->code); newcall.function()=fun.symbol_expr; pointer_typet need_type(symbol_typet(fun.symbol_expr.get(ID_C_class))); if(!type_eq(newcall.arguments()[0].type(), need_type, ns)) newcall.arguments()[0].make_typecast(need_type); } else { // No definition for this type; shouldn't be possible... t1->make_assertion(false_exprt()); } insertit.first->second=t1; // goto final goto_programt::targett t3=new_code_calls.add_instruction(); t3->source_location=vcall_source_loc; t3->make_goto(t_final, true_exprt()); } // If this calls the base function we just fall through. // Otherwise branch to the right call: if(fun.symbol_expr!=base_function_symbol) { exprt c_id1=constant_exprt(fun.class_id, string_typet()); goto_programt::targett t4=new_code_gotos.add_instruction(); t4->source_location=vcall_source_loc; t4->make_goto(insertit.first->second, equal_exprt(c_id1, c_id2)); } } goto_programt new_code; // patch them all together new_code.destructive_append(new_code_gotos); new_code.destructive_append(new_code_calls); new_code.destructive_append(final_skip); // set locations Forall_goto_program_instructions(it, new_code) { const irep_idt property_class=it->source_location.get_property_class(); const irep_idt comment=it->source_location.get_comment(); it->source_location=target->source_location; it->function=target->function; if(!property_class.empty()) it->source_location.set_property_class(property_class); if(!comment.empty()) it->source_location.set_comment(comment); } goto_programt::targett next_target=target; next_target++; goto_program.destructive_insert(next_target, new_code); // finally, kill original invocation target->make_skip(); }
void remove_virtual_functionst::remove_virtual_function( goto_programt &goto_program, goto_programt::targett target) { const code_function_callt &code= to_code_function_call(target->code); const exprt &function=code.function(); assert(function.id()==ID_virtual_function); assert(!code.arguments().empty()); functionst functions; get_functions(function, functions); if(functions.empty()) { target->make_skip(); return; // give up } // the final target is a skip goto_programt final_skip; goto_programt::targett t_final=final_skip.add_instruction(); t_final->make_skip(); // build the calls and gotos goto_programt new_code_calls; goto_programt new_code_gotos; for(functionst::const_iterator it=functions.begin(); it!=functions.end(); it++) { // call function goto_programt::targett t1=new_code_calls.add_instruction(); t1->make_function_call(code); to_code_function_call(t1->code).function()=it->symbol_expr; // goto final goto_programt::targett t3=new_code_calls.add_instruction(); t3->make_goto(t_final, true_exprt()); exprt this_expr=code.arguments()[0]; if(this_expr.type().id()!=ID_pointer || this_expr.type().id()!=ID_struct) { symbol_typet symbol_type(it->class_id); this_expr=typecast_exprt(this_expr, pointer_typet(symbol_type)); } exprt deref=dereference_exprt(this_expr, this_expr.type().subtype()); exprt c_id1=constant_exprt(it->class_id, string_typet()); exprt c_id2=build_class_identifier(deref); goto_programt::targett t4=new_code_gotos.add_instruction(); t4->make_goto(t1, equal_exprt(c_id1, c_id2)); } goto_programt new_code; // patch them all together new_code.destructive_append(new_code_gotos); new_code.destructive_append(new_code_calls); new_code.destructive_append(final_skip); // set locations Forall_goto_program_instructions(it, new_code) { irep_idt property_class=it->source_location.get_property_class(); irep_idt comment=it->source_location.get_comment(); it->source_location=target->source_location; it->function=target->function; if(!property_class.empty()) it->source_location.set_property_class(property_class); if(!comment.empty()) it->source_location.set_comment(comment); }
void ScriptTextEditor::_edit_option(int p_op) { switch(p_op) { case EDIT_UNDO: { code_editor->get_text_edit()->undo(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_REDO: { code_editor->get_text_edit()->redo(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_CUT: { code_editor->get_text_edit()->cut(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_COPY: { code_editor->get_text_edit()->copy(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_PASTE: { code_editor->get_text_edit()->paste(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_SELECT_ALL: { code_editor->get_text_edit()->select_all(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_MOVE_LINE_UP: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = script; if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); int from_col = tx->get_selection_from_column(); int to_line = tx->get_selection_to_line(); int to_column = tx->get_selection_to_column(); for (int i = from_line; i <= to_line; i++) { int line_id = i; int next_id = i - 1; if (line_id == 0 || next_id < 0) return; swap_lines(tx, line_id, next_id); } int from_line_up = from_line > 0 ? from_line-1 : from_line; int to_line_up = to_line > 0 ? to_line-1 : to_line; tx->select(from_line_up, from_col, to_line_up, to_column); } else { int line_id = tx->cursor_get_line(); int next_id = line_id - 1; if (line_id == 0 || next_id < 0) return; swap_lines(tx, line_id, next_id); } tx->end_complex_operation(); tx->update(); } break; case EDIT_MOVE_LINE_DOWN: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); int from_col = tx->get_selection_from_column(); int to_line = tx->get_selection_to_line(); int to_column = tx->get_selection_to_column(); for (int i = to_line; i >= from_line; i--) { int line_id = i; int next_id = i + 1; if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) return; swap_lines(tx, line_id, next_id); } int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line; int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line; tx->select(from_line_down, from_col, to_line_down, to_column); } else { int line_id = tx->cursor_get_line(); int next_id = line_id + 1; if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) return; swap_lines(tx, line_id, next_id); } tx->end_complex_operation(); tx->update(); } break; case EDIT_INDENT_LEFT: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { tx->indent_selection_left(); } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); // begins with tab if (line_text.begins_with("\t")) { line_text = line_text.substr(1, line_text.length()); tx->set_line(begin, line_text); } // begins with 4 spaces else if (line_text.begins_with(" ")) { line_text = line_text.substr(4, line_text.length()); tx->set_line(begin, line_text); } } tx->end_complex_operation(); tx->update(); //tx->deselect(); } break; case EDIT_INDENT_RIGHT: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { tx->indent_selection_right(); } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); line_text = '\t' + line_text; tx->set_line(begin, line_text); } tx->end_complex_operation(); tx->update(); //tx->deselect(); } break; case EDIT_CLONE_DOWN: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; int from_line = tx->cursor_get_line(); int to_line = tx->cursor_get_line(); int column = tx->cursor_get_column(); if (tx->is_selection_active()) { from_line = tx->get_selection_from_line(); to_line = tx->get_selection_to_line(); column = tx->cursor_get_column(); } int next_line = to_line + 1; tx->begin_complex_operation(); for (int i = from_line; i <= to_line; i++) { if (i >= tx->get_line_count() - 1) { tx->set_line(i, tx->get_line(i) + "\n"); } String line_clone = tx->get_line(i); tx->insert_at(line_clone, next_line); next_line++; } tx->cursor_set_column(column); if (tx->is_selection_active()) { tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column()); } tx->end_complex_operation(); tx->update(); } break; case EDIT_TOGGLE_COMMENT: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { int begin = tx->get_selection_from_line(); int end = tx->get_selection_to_line(); // End of selection ends on the first column of the last line, ignore it. if(tx->get_selection_to_column() == 0) end -= 1; for (int i = begin; i <= end; i++) { String line_text = tx->get_line(i); if (line_text.begins_with("#")) line_text = line_text.substr(1, line_text.length()); else line_text = "#" + line_text; tx->set_line(i, line_text); } } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); if (line_text.begins_with("#")) line_text = line_text.substr(1, line_text.length()); else line_text = "#" + line_text; tx->set_line(begin, line_text); } tx->end_complex_operation(); tx->update(); //tx->deselect(); } break; case EDIT_COMPLETE: { code_editor->get_text_edit()->query_code_comple(); } break; case EDIT_AUTO_INDENT: { TextEdit *te = code_editor->get_text_edit(); String text = te->get_text(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; int begin,end; if (te->is_selection_active()) { begin=te->get_selection_from_line(); end=te->get_selection_to_line(); } else { begin=0; end=te->get_line_count()-1; } scr->get_language()->auto_indent_code(text,begin,end); te->set_text(text); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { trim_trailing_whitespace(); } break; case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); } break; case SEARCH_FIND_NEXT: { code_editor->get_find_replace_bar()->search_next(); } break; case SEARCH_FIND_PREV: { code_editor->get_find_replace_bar()->search_prev(); } break; case SEARCH_REPLACE: { code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_LOCATE_FUNCTION: { quick_open->popup(get_functions()); } break; case SEARCH_GOTO_LINE: { goto_line_dialog->popup_find_line(code_editor->get_text_edit()); } break; case DEBUG_TOGGLE_BREAKPOINT: { int line=code_editor->get_text_edit()->cursor_get_line(); bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak); ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak); } break; case DEBUG_REMOVE_ALL_BREAKPOINTS: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); for(List<int>::Element *E=bpoints.front();E;E=E->next()) { int line = E->get(); bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak); ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak); } } case DEBUG_GOTO_NEXT_BREAKPOINT: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { return; } int line=code_editor->get_text_edit()->cursor_get_line(); // wrap around if (line >= bpoints[bpoints.size() - 1]) { code_editor->get_text_edit()->cursor_set_line(bpoints[0]); } else { for(List<int>::Element *E=bpoints.front();E;E=E->next()) { int bline = E->get(); if (bline > line) { code_editor->get_text_edit()->cursor_set_line(bline); return; } } } } break; case DEBUG_GOTO_PREV_BREAKPOINT: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { return; } int line=code_editor->get_text_edit()->cursor_get_line(); // wrap around if (line <= bpoints[0]) { code_editor->get_text_edit()->cursor_set_line(bpoints[bpoints.size() - 1]); } else { for(List<int>::Element *E=bpoints.back();E;E=E->prev()) { int bline = E->get(); if (bline < line) { code_editor->get_text_edit()->cursor_set_line(bline); return; } } } } break; case HELP_CONTEXTUAL: { String text = code_editor->get_text_edit()->get_selection_text(); if (text == "") text = code_editor->get_text_edit()->get_word_under_cursor(); if (text != "") { emit_signal("request_help_search",text); } } break; } }
void StructAccessExpressionBuilder::build(VMProgram* program, VMExpressionVisitor* visitor, StructAccessExpression* expression, const ElsaType* current) { // If we do not have a base expression we can expect the base to already be on the stack e.g. chained array access. if(expression->get_base() != nullptr) IdentifierExpressionBuilder::build(program, visitor, expression->get_base()); auto current_type = current; if (current_type == nullptr) { current_type = visitor->current_type(); if (expression->get_base() != nullptr) current_type = expression->get_base()->get_type(); } for (const auto& exp : expression->get_expressions()) { auto current_struct = get_current_struct(current_type); if (exp->get_expression_type() == ExpressionType::FieldAccess) { for (const auto& field : current_struct->get_fields()) { if (field->get_name() == exp->get_name()) { if (field->get_type()->get_type() == ObjectType::GCOPtr) current_type = field->get_type(); program->emit(OpCode::l_field); program->emit(static_cast<int>(field->get_index())); break; } } } else if(exp->get_expression_type() == ExpressionType::FuncCall) { for (const auto& function : current_struct->get_functions()) { if (function->get_name() == exp->get_name()) { const auto fi = program->get_struct(current_type->get_struct_declaration_expression()->get_name(true))->get_function(function->get_name()); if (function->get_return_type()->get_type() == ObjectType::GCOPtr) current_type = function->get_return_type(); FuncCallExpressionBuilder::build_member(program, visitor, dynamic_cast<FuncCallExpression*>(exp.get()), fi); break; } } } else if (exp->get_expression_type() == ExpressionType::ArrayAccess) { for (const auto& field : current_struct->get_fields()) { if (field->get_name() == exp->get_name()) { current_type = field->get_type()->get_struct_declaration_expression()->get_generic_type(); program->emit(OpCode::l_field); program->emit(static_cast<int>(field->get_index())); dynamic_cast<ArrayAccessExpression*>(exp.get())->get_index_expression()->accept(visitor); program->emit(OpCode::l_ele); break; } } } else if (exp->get_expression_type() == ExpressionType::Identifier) { if (exp->get_type()->get_type() == ObjectType::Function) { for (const auto& function : current_struct->get_functions()) { if (function->get_name() == exp->get_name()) { const auto fi = program->get_struct(current_type->get_struct_declaration_expression()->get_name(true))->get_function(function->get_name()); program->emit(OpCode::fnconst); program->emit(static_cast<int>(fi->get_addr())); break; } } } else { throw CodeGenException("Unsupported type -> StructAccessExpressionBuilder -> ExpressionType::Identifier"); } } } }