static void double_continuate_construct(FILE* output, const char* prefix, const char* c, int width, int* column) { // This is a naive but easy-to-reason-about-it implementation // It refuses to reuse the last column for other than continuation, // it will put a continuation even if only one character remains // this avoids having *column > width. char prefix_start[64]; snprintf(prefix_start, 63, "!$%s&", prefix); for (; *c != '\0'; c++) { // If we are at the last column but this is not an EOS if ((*column == width) && (*c != '\n')) { // Double continue fprintf(output, "&\n%s", prefix_start); *column = 1 + strlen(prefix_start); DEBUG_CODE() DEBUG_MESSAGE("Cutting at '%c'", *c); } DEBUG_CODE() DEBUG_MESSAGE("%d - Letter - '%c'", *column, *c); fprintf(output, "%c", *c); (*column)++; } }
/** * sendMemoryPackage - uses Memory-Mapped files to do IPC messaging * with the Java AccessBridge DLL, informing the * Java AccessBridge DLL via SendMessage that something * is waiting for it in the shared file... * * In the SendMessage call, the third param (WPARAM) is * the source HWND (ourAccessBridgeWindow in this case), * and the fourth param (LPARAM) is the size in bytes of * the package put into shared memory. * */ BOOL AccessBridgeJavaVMInstance::sendMemoryPackage(char *buffer, long bufsize) { // Protect against race condition where the memory mapped file is // deallocated before the memory package is being sent if (goingAway) { return FALSE; } BOOL retval = FALSE; DEBUG_CODE(char outputBuf[256]); DEBUG_CODE(sprintf(outputBuf, "AccessBridgeJavaVMInstance::sendMemoryPackage(, %d)", bufsize)); DEBUG_CODE(AppendToCallInfo(outputBuf)); DEBUG_CODE(PackageType *type = (PackageType *) buffer); DEBUG_CODE(if (*type == cGetAccessibleTextRangePackage) { ) DEBUG_CODE(AppendToCallInfo(" 'buffer' contains:")); DEBUG_CODE(GetAccessibleTextRangePackage *pkg = (GetAccessibleTextRangePackage *) (buffer + sizeof(PackageType))); DEBUG_CODE(sprintf(outputBuf, " PackageType = %X", *type)); DEBUG_CODE(AppendToCallInfo(outputBuf)); DEBUG_CODE(sprintf(outputBuf, " GetAccessibleTextRange: start = %d, end = %d, rText = %ls", pkg->start, pkg->end, pkg->rText)); DEBUG_CODE(AppendToCallInfo(outputBuf)); DEBUG_CODE( })
/** * [CompCoroutine_s_Task_InitStack description] * @param pTask [description] * @param pStack [description] * @param iSize [description] * @param pMain [description] * @param pParam [description] */ void CompCoroutine_s_Task_InitStack(struct CompCoroutine_s_Task* pTask, void* pStack, unsigned iSize, CompCoroutine_p_Task pMain, void* pParam) { DEBUG_ASSERT_PARAM(NULL != pTask, "null pointer"); DEBUG_ASSERT_PARAM(iSize > 0, "null pointer"); DEBUG_ASSERT_PARAM(NULL != pMain, "null pointer"); DEBUG_CODE(memset(pStack, 0, iSize)); pTask->_iStack = Context_Init(pStack, iSize, pMain, pParam); #if (DEBUG) pTask->iSetStack = (uintptr_t)pStack; pTask->iSetSize = iSize; #endif }
AccessBridgeJavaVMInstance::~AccessBridgeJavaVMInstance() { DEBUG_CODE(char buffer[256]); DEBUG_CODE(AppendToCallInfo("***** in AccessBridgeJavaVMInstance::~AccessBridgeJavaVMInstance\r\n")); EnterCriticalSection(&sendMemoryIPCLock); // if IPC memory mapped file view is valid, unmap it goingAway = TRUE; if (memoryMappedView != (char *) 0) { DEBUG_CODE(sprintf(buffer, " unmapping memoryMappedView; view = %p\r\n", memoryMappedView)); DEBUG_CODE(AppendToCallInfo(buffer)); UnmapViewOfFile(memoryMappedView); memoryMappedView = (char *) 0; } // if IPC memory mapped file handle map is open, close it if (memoryMappedFileMapHandle != (HANDLE) 0) { DEBUG_CODE(sprintf(buffer, " closing memoryMappedFileMapHandle; handle = %p\r\n", memoryMappedFileMapHandle)); DEBUG_CODE(AppendToCallInfo(buffer)); CloseHandle(memoryMappedFileMapHandle); memoryMappedFileMapHandle = (HANDLE) 0; } LeaveCriticalSection(&sendMemoryIPCLock); }
scope_entry_t* query_name_with_locus(decl_context_t decl_context, AST locus, const char* name) { scope_entry_t* result = query_name_no_implicit(decl_context, name); if (result == NULL) { if (decl_context.implicit_info != NULL && decl_context.implicit_info->data != NULL && decl_context.implicit_info->data->implicit_letter_set != NULL) { DEBUG_CODE() { fprintf(stderr, "SCOPE: Getting implicit entity for name '%s'\n", name); } result = new_implicit_symbol(decl_context, locus, name); }
char is_sound_type(type_t* t, decl_context_t decl_context) { ERROR_CONDITION(t == NULL, "Invalid NULL here", 0); if (is_array_type(t)) { type_t* element_type = array_type_get_element_type(t); if (is_void_type(element_type) || is_lvalue_reference_type(element_type) || is_function_type(element_type)) { DEBUG_CODE() { fprintf(stderr, "TYPEORDER: Deduced type is not sound because it is an array of void/references/functions\n"); } return 0; }
type_t* solve_class_template(decl_context_t decl_context, type_t* template_type, type_t* specialized_type, deduction_set_t** unification_set, const char *filename, int line) { template_argument_list_t* specialized = template_specialized_type_get_template_arguments( get_actual_class_type(specialized_type)); int i; int num_specializations = template_type_get_num_specializations(template_type); type_t** matching_set = NULL; int num_matching_set = 0; deduction_set_t **deduction_results = NULL; int num_deductions = 0; for (i = 0; i < num_specializations; i++) { type_t* current_specialized_type = template_type_get_specialization_num(template_type, i); DEBUG_CODE() { scope_entry_t* entry = named_type_get_symbol(current_specialized_type); fprintf(stderr, "SOLVETEMPLATE: Checking with specialization defined in '%s:%d'\n", entry->file, entry->line); } // We do not want these for instantiation purposes if (class_type_is_incomplete_independent( get_actual_class_type(current_specialized_type)) || class_type_is_incomplete_dependent( get_actual_class_type(current_specialized_type))) { DEBUG_CODE() { scope_entry_t* entry = named_type_get_symbol(current_specialized_type); fprintf(stderr, "SOLVETEMPLATE: Discarding '%s:%d' since it is incomplete\n", entry->file, entry->line); } continue; }
type_t* solve_class_template(type_t* template_type, type_t* specialized_type, template_parameter_list_t** deduced_template_arguments, const locus_t* locus) { template_parameter_list_t* specialized = template_specialized_type_get_template_arguments( get_actual_class_type(specialized_type)); int i; int num_specializations = template_type_get_num_specializations(template_type); type_t** matching_set = NULL; int num_matching_set = 0; template_parameter_list_t **deduction_results = NULL; int num_deductions = 0; for (i = 0; i < num_specializations; i++) { type_t* current_specialized_type = template_type_get_specialization_num(template_type, i); DEBUG_CODE() { scope_entry_t* entry = named_type_get_symbol(current_specialized_type); fprintf(stderr, "SOLVETEMPLATE: Checking with specialization defined in '%s'\n", locus_to_str(entry->locus)); } // We do not want these for instantiation purposes if (!named_type_get_symbol(current_specialized_type)->entity_specs.is_instantiable) { DEBUG_CODE() { scope_entry_t* entry = named_type_get_symbol(current_specialized_type); fprintf(stderr, "SOLVETEMPLATE: Discarding '%s' (%s) since it has been created by the typesystem\n", print_type_str(current_specialized_type, entry->decl_context), locus_to_str(entry->locus)); } continue; }
/** * initiateIPC - sets up the memory-mapped file to do IPC messaging * 1 file is created: to handle requests for information * initiated from Windows AT. The package is placed into * the memory-mapped file (char *memoryMappedView), * and then a special SendMessage() is sent. When the * JavaDLL returns from SendMessage() processing, the * data will be in memoryMappedView. The SendMessage() * return value tells us if all is right with the world. * * The set-up proces involves creating the memory-mapped * file, and handshaking with the JavaDLL so it knows * about it as well. * */ LRESULT AccessBridgeJavaVMInstance::initiateIPC() { DEBUG_CODE(char debugBuf[256]); DWORD errorCode; DEBUG_CODE(AppendToCallInfo(" in AccessBridgeJavaVMInstance::initiateIPC()\r\n")); // create Windows-initiated IPC file & map it to a ptr memoryMappedFileMapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, // 8 bytes for return code sizeof(WindowsInitiatedPackages) + 8, memoryMappedFileName); if (memoryMappedFileMapHandle == NULL) { errorCode = GetLastError(); DEBUG_CODE(sprintf(debugBuf, " Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode)); DEBUG_CODE(AppendToCallInfo(debugBuf)); return errorCode; } else { DEBUG_CODE(sprintf(debugBuf, " CreateFileMapping worked - filename: %s\r\n", memoryMappedFileName)); DEBUG_CODE(AppendToCallInfo(debugBuf)); } memoryMappedView = (char *) MapViewOfFile(memoryMappedFileMapHandle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (memoryMappedView == NULL) { errorCode = GetLastError(); DEBUG_CODE(sprintf(debugBuf, " Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode)); DEBUG_CODE(AppendToCallInfo(debugBuf)); return errorCode; } else { DEBUG_CODE(sprintf(debugBuf, " MapViewOfFile worked - view: %p\r\n", memoryMappedView)); DEBUG_CODE(AppendToCallInfo(debugBuf)); } // write some data to the memory mapped file strcpy(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_QUERY); // inform the JavaDLL that we've a memory mapped file ready for it char buffer[sizeof(PackageType) + sizeof(MemoryMappedFileCreatedPackage)]; PackageType *type = (PackageType *) buffer; MemoryMappedFileCreatedPackage *pkg = (MemoryMappedFileCreatedPackage *) (buffer + sizeof(PackageType)); *type = cMemoryMappedFileCreatedPackage; pkg->bridgeWindow = ABHandleToLong(ourAccessBridgeWindow); strncpy(pkg->filename, memoryMappedFileName, cMemoryMappedNameSize); sendPackage(buffer, sizeof(buffer)); // look for the JavaDLL's answer to see if it could read the file if (strcmp(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_ANSWER) != 0) { DEBUG_CODE(sprintf(debugBuf, " JavaVM failed to deal with memory mapped file %s\r\n", memoryMappedFileName)); DEBUG_CODE(AppendToCallInfo(debugBuf)); return -1; } else { DEBUG_CODE(sprintf(debugBuf, " Success! JavaVM accpeted our file\r\n")); DEBUG_CODE(AppendToCallInfo(debugBuf)); } return 0; }
void fortran_split_lines(FILE* input, FILE* output, int width) { ERROR_CONDITION(width <= 0, "Invalid width = %d\n", width); int length; char* line; while ((line = read_whole_line(input)) != NULL) { // We must remove trailing spaces before "\n" (if any) // since we cannot continuate to an empty line trim_right_line(line); // Comments that will reach here are those created within the compiler // (e.g. TPL) because scanner always trims them char prefix[33] = { 0 }; char is_construct = check_for_construct(line, prefix, 32); char is_comment = check_for_comment(line); length = strlen(line); // Many times we will fall here by means of length <= width if ((length <= width)) { fputs(line, output); } else if (is_construct) { // Do not complicate ourselves, rely on a double continuation int column = 1; double_continuate_construct(output, prefix, line, width, &column); fprintf(output, "\n"); } else if (is_comment) { fputs(line, output); } else { int column, next_column; char* position; char* next_position; mf03_prepare_string_for_scanning(line); // Initialize stuff column = 1; position = line; // Scan int token = mf03lex(); while (token != EOS) { // Find the token as there can be spaces // next_position has the first character of the token next_position = strstr(position, mf03lval.token_atrib.token_text); if (next_position == NULL) { fatal_error("Serious problem when splitting line. '%s' not found:\n\n %s", mf03lval.token_atrib.token_text, position); } // Next column has the column where the token will start next_column = column + (next_position - position); // Check if we have reached the last column or if spaces plus // token will not fit in this line if (column == width || (next_column + (int)strlen(mf03lval.token_atrib.token_text) >= width)) { DEBUG_CODE() DEBUG_MESSAGE("Cutting at '%s'", mf03lval.token_atrib.token_text); // Nothing fits here already fprintf(output, "&\n"); column = 1; } // Write the blanks char* c; for (c = position; c < next_position; c++) { DEBUG_CODE() DEBUG_MESSAGE("%d - Blank - '%c'", column, *c); fprintf(output, "%c", *c); column++; } if ((column + (int)strlen(mf03lval.token_atrib.token_text)) >= width) { // We are very unlucky, the whole token still does not fit // in this line ! double_continuate(output, mf03lval.token_atrib.token_text, width, &column); } else { // Write the token DEBUG_CODE() DEBUG_MESSAGE("%d - Token '%s'", column, mf03lval.token_atrib.token_text); fprintf(output, "%s", mf03lval.token_atrib.token_text); column += strlen(mf03lval.token_atrib.token_text); } // Update state to be coherent before entering the next iteration // column has been updated before position = next_position + strlen(mf03lval.token_atrib.token_text); token = mf03lex(); } // The EOS fprintf(output, "\n"); } DELETE(line); } }