expression_ast unary_op::evaluate(filter_handler handler) const { factory::un_op_type impl = factory::get_unary_operator(op); value_type type = get_return_type(op, type_invalid); if (type_is_int(type)) { return impl->evaluate(handler, subject); } handler->error(_T("Missing operator implementation")); return expression_ast(int_value(FALSE)); }
void searchTree(TreeNode* root, ConstTable* MainConstTable, TypeTable* MainTypeTable, VarTable* MainVarTable, ProcedureTable* MainProcedureTable) { enumlist = NULL; errorOccur = 0; current_procedure = (char*)malloc(100); memset(current_procedure, 0, 100); strcpy(current_procedure, "main"); TreeNode *head = root->child->sibling->child;//routine_heads TreeNode *const_type = getChild(2, head); makeNewConstTable(const_type, MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable); makeNewTypeTable(getChild(3, head), MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable); makeNewVarTable((TreeNode*)getChild(4,head), MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable); ProcedureTableNode* mainnode = makeNewProcedureTableNode(); mainnode->name = "main"; mainnode->returntype = NULL; mainnode->next = NULL; mainnode->paranum = mainnode->line_no = mainnode->size = 0; mainnode->paralist = NULL; int t = insertIntoProcedureTable(mainnode, MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable); if(t == -1) return; makeNewProcedureTable((TreeNode*)getChild(5,head), MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable); //if(getType("days", "main", MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable) != NULL) // printType(getType("days", "main", MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable)); /* printf("\nnum: %d\n", get_args_list_num("testfunc", MainProcedureTable)); */ printType(get_args_type(1, "testfunc", "main", MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable)); printType(get_return_type("testfunc", "main_testfunc", MainProcedureTable)); int size, address, totallevel, leveltofather; char* label = (char*)malloc(100); memset(label, 0, 100); getAddress("k", "main_testfunc", &size, &label, &address, &totallevel, &leveltofather, MainConstTable, MainVarTable, MainProcedureTable); printf("size:%d address:%d totallevel:%d leveltofather:%d label:%s\n", size, address, totallevel, leveltofather, label); free(label); printf("ifexists: %d", ifExists("dt.year", "main_testfunc", MainConstTable, MainTypeTable, MainVarTable, MainProcedureTable)); }
MonoObject *GDMonoMethod::invoke(MonoObject *p_object, const Variant **p_params, MonoObject **r_exc) { if (get_return_type().type_encoding != MONO_TYPE_VOID || get_parameters_count() > 0) { MonoArray *params = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(MonoObject), get_parameters_count()); for (int i = 0; i < params_count; i++) { MonoObject *boxed_param = GDMonoMarshal::variant_to_mono_object(p_params[i], param_types[i]); mono_array_set(params, MonoObject *, i, boxed_param); } MonoObject *exc = NULL; MonoObject *ret = mono_runtime_invoke_array(mono_method, p_object, params, &exc); if (exc) { ret = NULL; if (r_exc) { *r_exc = exc; } else { GDMonoUtils::print_unhandled_exception(exc); } } return ret; } else { MonoObject *exc = NULL; mono_runtime_invoke(mono_method, p_object, NULL, &exc); if (exc) { if (r_exc) { *r_exc = exc; } else { GDMonoUtils::print_unhandled_exception(exc); } } return NULL; } }
inline ndt::type resolve(const ndt::type *src_tp) const { if (resolve_dst_type != NULL) { ndt::type result; resolve_dst_type(this, result, src_tp, true); return result; } else { intptr_t param_count = get_param_count(); const ndt::type *param_types = get_param_types(); std::map<nd::string, ndt::type> typevars; for (intptr_t i = 0; i != param_count; ++i) { if (!ndt::pattern_match(src_tp[i].value_type(), param_types[i], typevars)) { std::stringstream ss; ss << "parameter " << (i + 1) << " to arrfunc does not match, "; ss << "expected " << param_types[i] << ", received " << src_tp[i]; throw std::invalid_argument(ss.str()); } } // TODO: // return ndt::substitute_type_vars(get_return_type(), typevars); return get_return_type(); } }
int check_expression(Resources *res, TToken **last_token, index_t *last_index) { args_assert(res != NULL, INTERNAL_ERROR); TToken *input_token = NULL; TToken *top_token = NULL; TToken *tmp = NULL; index_t top_index = ZERO_INDEX; index_t input_index = ZERO_INDEX; TStack stack; int iRet = RETURN_OK; int return_type; init_stack(&stack); new_item(&res->struct_buff, top_index, top_token); top_token->token_type = END_OF_EXPR; push(&res->struct_buff, &stack, top_index); // $ on top of the stack if ((*last_token) != NULL) input_index = *last_index; else input_index = get_token(res->source, &res->string_buff, &res->struct_buff); catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)&input_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); if (input_token->token_type == ERRORT) { iRet = LEXICAL_ERROR; goto EXIT; } catch_internal_error( dereference_structure(&res->struct_buff, top_index, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); do { #if DEBUG print_stack(&res->struct_buff, &stack); #endif debug_print("%s %d\n", "TOP", top_token->token_type); debug_print("%s %d\n", "INPUT", input_token->token_type); if (top_token->token_type == IDENTIFIER && input_token->token_type == OPENING_BRACKET) { debug_print("%s\n", "FUNCTION CALL IN EXPR"); index_t last_id = top_token->token_index; catch_undefined_error(is_func_declared(res, last_id), SEMANTIC_ERROR, "Function declaration check failed.", 1 ); dereference_structure(&res->struct_buff, input_index, (void **)last_token); if ((iRet = generate_function_call(res, last_id)) != 0) goto EXIT; return_type = get_return_type(res, top_token->token_index); catch_internal_error(return_type, SYNTAX_ERROR, "Failed to get function return type."); // Reduction of function call if((iRet = reduce(&res->struct_buff, &stack, return_type)) != RETURN_OK) goto EXIT; top_index = stack.top; catch_syntax_error( get_first_token(&res->struct_buff, &stack, &top_index), INTERNAL_ERROR, "Failed to get first token", 1 ); input_index = get_token(res->source, &res->string_buff, &res->struct_buff); catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)&input_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); if (input_token->token_type == ERRORT) { iRet = LEXICAL_ERROR; goto EXIT; } catch_internal_error( dereference_structure(&res->struct_buff, top_index, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); if (type_filter(top_token->token_type) == END_OF_EXPR && type_filter(input_token->token_type) == END_OF_EXPR) break; } switch(precedence_table[type_filter(top_token->token_type)] [type_filter(input_token->token_type)]) { case H: debug_print("%s\n", "CASE H"); top_index = input_index; push(&res->struct_buff, &stack, top_index); input_index = get_token(res->source, &res->string_buff, &res->struct_buff); catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)&input_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); if (input_token->token_type == ERRORT) { iRet = LEXICAL_ERROR; goto EXIT; } catch_internal_error( dereference_structure(&res->struct_buff, top_index, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); break; case S: debug_print("%s\n", "CASE S"); new_item(&res->struct_buff, top_index, top_token); catch_internal_error( dereference_structure(&res->struct_buff, stack.top, (void **)&tmp), INTERNAL_ERROR, "Failed to dereference structure buffer." ); top_token->token_type = SHIFT; if (tmp->token_type == RVALUE) { index_t rvalue_index = stack.top; pop(&res->struct_buff, &stack); push(&res->struct_buff, &stack, top_index); push(&res->struct_buff, &stack, rvalue_index); } else push(&res->struct_buff, &stack, top_index); catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)&input_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); top_index = input_index; push(&res->struct_buff, &stack, top_index); input_index = get_token(res->source, &res->string_buff, &res->struct_buff); catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)&input_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); if (input_token->token_type == ERRORT) { iRet = LEXICAL_ERROR; goto EXIT; } catch_internal_error( dereference_structure(&res->struct_buff, top_index, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); break; case R: debug_print("%s\n", "CASE R"); if ((iRet = get_rule(res, &stack)) != RETURN_OK) goto EXIT; top_index = stack.top; catch_syntax_error( get_first_token(&res->struct_buff, &stack, &top_index), INTERNAL_ERROR, "Failed to get first token", 1 ); catch_internal_error( dereference_structure(&res->struct_buff, top_index, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); break; case E: debug_print("%s\n", "CASE E"); if (type_filter(top_token->token_type) == END_OF_EXPR && type_filter(input_token->token_type) == CLOSING_BRACKET) { catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)last_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); catch_internal_error( dereference_structure(&res->struct_buff, stack.top, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); if (top_token->original_type == 0) { // Empty expression, there was nothing reduced on top debug_print("%s: %d\n", "EMPTY EXPRESSION RETURN", SYNTAX_ERROR); iRet = SYNTAX_ERROR; goto EXIT; } goto FINISH; } iRet = SYNTAX_ERROR; goto EXIT; default: debug_print("%s", "DEFAULT\n"); iRet = INTERNAL_ERROR; goto EXIT; } } while (type_filter(top_token->token_type) != END_OF_EXPR || type_filter(input_token->token_type) != END_OF_EXPR); catch_internal_error( dereference_structure(&res->struct_buff, input_index, (void **)last_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); catch_internal_error( dereference_structure(&res->struct_buff, stack.top, (void **)&top_token), INTERNAL_ERROR, "Failed to dereference structure buffer." ); FINISH: debug_print("%s: %d\n", "TYPE OF EXPRESSION", top_token->original_type); // send type of expression back to syntax_analysis (*last_token)->original_type = top_token->original_type; // set type of stack top on runtime stack catch_internal_error(new_instruction_int_int(&res->instruction_buffer, 0lu, top_token->original_type, 0, SET_TYPE), INTERNAL_ERROR, "Failed to generate new instruction"); EXIT: debug_print("%s: %d\n", "RETURN", iRet); return iRet; }
void QuickEdit::SetupOperationController() { operationController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>()); operationController->SetColumns(columns); ADD_GETSET(BrowserOperation, operationController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toString().toLatin1().constData, get_name, set_name); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("type"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toString, get_return_type().get_type, set_return_type); ADD_GETSET_CONVERTED(BrowserOperation, operationController, columns.indexOf("visibility"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toString,BrowserNode::encode_visibility,visibility_as_string, pointer->def->set_uml_visibility); ADD_GETSET(BrowserOperation, operationController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool, deletedp, set_deleted); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("static"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_isa_class_operation, set_isa_class_operation); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("abstract"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_is_abstract, set_is_abstract); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("const"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_const, set_cpp_const); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("volatile"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_is_volatile, set_is_volatile); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("friend"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_friend, set_cpp_friend); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("virtual"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_virtual, set_cpp_virtual); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("inline"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_inline, set_cpp_inline); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("defaulted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_default, set_cpp_default); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("delete"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_delete, set_cpp_delete); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("override"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_override, set_cpp_override); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("final"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_final, set_cpp_final); std::function<void(BrowserNode*,const QModelIndex& index)> f = [](BrowserNode* node ,const QModelIndex& index) { Q_UNUSED(index); BrowserOperation* oper = static_cast<BrowserOperation*>(node); oper->modified(); oper->setText(0,oper->get_name() ); oper->package_modified(); oper->get_data()->modified(); }; operationController->AddPostProcessors(columns.indexOf("name"), QVector<int>(QVector<int>({Qt::DisplayRole,Qt::EditRole})),f); ADD_PIXMAP_GETTER(BrowserOperation, operationController, columns.indexOf("name"),QVector<int>({Qt::DecorationRole}), pixmap); operationController->AddFlagsFunctor ( [&](const QModelIndex& index) { Qt::ItemFlags result; result |= Qt::ItemIsSelectable; if(!(index.column() *in(columns.indexOf("name"),columns.indexOf("type"),columns.indexOf("static"),columns.indexOf("visibility"),columns.indexOf("abstract"), columns.indexOf("const"), columns.indexOf("volatile"),columns.indexOf("friend"),columns.indexOf("virtual"),columns.indexOf("inline") ,columns.indexOf("defaulted"),columns.indexOf("delete"),columns.indexOf("override"),columns.indexOf("final"), columns.indexOf("deleted")))) return result; TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer()); if(!iface) return result; BrowserOperation* pointer = static_cast<BrowserOperation*>(iface->InternalPointer()); if(!pointer) return result; if(pointer->is_writable() && !((OperationData*)pointer->get_data())->get_or_set()) result |= Qt::ItemIsEditable; result |= Qt::ItemIsEnabled; return result; } ); }