def get(CCFactory, Name): """Implement the default counter for a given Counter Database. In case the line and column number increment cannot be determined before- hand, a something must be there that can count according to the rules given in 'CCFactory'. This function generates the code for a general counter function which counts line and column number increments starting from the begin of a lexeme to its end. The implementation of the default counter is a direct function of the 'CCFactory', i.e. the database telling how characters influence the line and column number counting. Multiple modes may have the same character counting behavior. If so, then there's only one counter implemented while others refer to it. --------------------------------------------------------------------------- RETURNS: function_name, string --> Function name and the implementation of the character counter. function_name, None --> The 'None' implementation indicates that NO NEW counter is implemented. An appropriate counter can be accessed by the 'function name'. --------------------------------------------------------------------------- """ function_name = DefaultCounterFunctionDB.get_function_name(CCFactory) if function_name is not None: return function_name, None # Implementation has been done before. function_name = Lng.DEFAULT_COUNTER_FUNCTION_NAME(Name) door_id_return = dial_db.new_door_id() code, \ door_id_beyond = loop.do(CCFactory, AfterBeyond = [ GotoDoorId(door_id_return) ], LexemeEndCheckF = True, EngineType = engine.CHARACTER_COUNTER) implementation = __frame(function_name, Lng.INPUT_P(), code, door_id_return, door_id_beyond) DefaultCounterFunctionDB.enter(CCFactory, function_name) return function_name, implementation
def get_test_application(encoding, ca_map): # (*) Setup the buffer encoding ___________________________________________ # if encoding == "utf_32_le": byte_n_per_code_unit = 4 elif encoding == "ascii": byte_n_per_code_unit = 1 elif encoding == "utf_8": byte_n_per_code_unit = 1 elif encoding == "utf_16_le": byte_n_per_code_unit = 2 elif encoding == "cp737": byte_n_per_code_unit = 1 else: assert False Setup.buffer_setup("", byte_n_per_code_unit, encoding.replace("_le", "").replace("_", "")) Setup.analyzer_class_name = "Lexer" # (*) Generate Code _______________________________________________________ # counter_str = run_time_counter.get(ca_map, "TEST_MODE") counter_str = counter_str.replace("static void", "void") # Double check if reference delta counting has been implemented as expected. expect_reference_p_f = ca_map.get_column_number_per_code_unit() is not None assert_reference_delta_count_implementation(counter_str, expect_reference_p_f) counter_str = adapt.do(counter_str, "data", "") open("./data/test.c", "wb").write("#include <data/check.h>\n\n" + counter_str) # (*) Compile _____________________________________________________________ # counter_function_name = Lng.DEFAULT_COUNTER_FUNCTION_NAME("TEST_MODE") os.system("rm -f test") compile_str = "gcc -Wall -Werror -I. -ggdb ./data/check.c ./data/test.c " \ + " -DQUEX_OPTION_COUNTER" \ + " -DDEF_COUNTER_FUNCTION='%s' " % counter_function_name \ + " -DDEF_FILE_NAME='\"data/input.txt\"' " \ + " -DDEF_CHARACTER_TYPE=%s" % Setup.lexatom.type \ + " -o test" # + " -DDEF_DEBUG_TRACE " print "## %s" % compile_str os.system(compile_str)
def get(CaMap, ModeName): """Implement the default counter for a given Counter Database. In case the line and column number increment cannot be determined before- hand, a something must be there that can count according to the rules given in 'CaMap'. This function generates the code for a general counter function which counts line and column number increments starting from the begin of a lexeme to its end. The implementation of the default counter is a direct function of the 'CaMap', i.e. the database telling how characters influence the line and column number counting. Multiple modes may have the same character counting behavior. If so, then there's only one counter implemented while others refer to it. --------------------------------------------------------------------------- RETURNS: function_name, string --> Function name and the implementation of the character counter. function_name, None --> The 'None' implementation indicates that NO NEW counter is implemented. An appropriate counter can be accessed by the 'function name'. --------------------------------------------------------------------------- """ if not (Setup.count_line_number_f or Setup.count_column_number_f): return "" dial_db = DialDB() mode_with_same_counter = DefaultCounterFunctionDB.get_mode_name(CaMap) if mode_with_same_counter is not None: # Use previously done implementation for this 'CaMap' return __frame(Lng.DEFAULT_COUNTER_FUNCTION_NAME(ModeName), [ Lng.DEFAULT_COUNTER_CALL(mode_with_same_counter) ], None, None, None) door_id_return = dial_db.new_door_id() analyzer_list, \ terminal_list, \ dummy_loop_map, \ dummy_door_id_loop, \ required_register_set, \ dummy_run_time_counter_f = loop.do(CaMap, OnLoopExitDoorId = door_id_return, LexemeEndCheckF = True, EngineType = engine.CHARACTER_COUNTER, dial_db = dial_db, ModeName = ModeName, CutSignalLexatomsF = False) code = generator.do_analyzer_list(analyzer_list) code.extend( generator.do_terminals(terminal_list, TheAnalyzer=None, dial_db=dial_db) ) variable_db.require_registers(required_register_set) implementation = __frame(Lng.DEFAULT_COUNTER_FUNCTION_NAME(ModeName), code, Lng.INPUT_P(), door_id_return, dial_db) DefaultCounterFunctionDB.enter(CaMap, ModeName) return implementation