codelist_entry *process_line(){ eat_whitespace(); codelist_entry *ret = NULL; printf("Processing line: %s -- len: %d\n", input_file_stack->line_buffer, (int)strlen(input_file_stack->line_buffer)); if(!is_line_blank() && !is_line_comment()){ if(is_line_label()){ printf("Line is label\n"); return process_label(); }else if(is_line_dat()){ printf("Line is data\n"); return process_dat(); }else if(is_line_include()){ printf("Line is include\n"); open_input_m4(get_include_filename()); return NULL; }else{ printf("Processing code line\n"); return process_op(); } }else{ printf("Line comment/empty/blank\n"); } return ret; }
void CompilationCppParser::parse_src_file_rec( CompilationEnvironment &ce, const String &filename ) { if ( is_a_directory( filename ) ) return; String current_dir = directory_of( filename ) + "/"; File file( filename, "r" ); for ( const char *c = file.c_str(); *c; ) { // string ? if ( c[ 0 ] == '"' ) { go_after_next_double_quote( ++c ); continue; } // comment ? if ( c[ 0 ] == '/' ) { if ( c[ 1 ] == '/' ) { go_to_next_line( c += 2 ); continue; } if ( c[ 1 ] == '*' ) { go_to_next_mul_slash( c += 2 ); continue; } } // QOBJECT ? if ( c[ 0 ] == 'Q' ) { if ( strncmp( c + 1, "_OBJECT", 7 ) == 0 ) { c += 8; if ( not filename.begins_by( "/usr/" ) ) // hum !! moc_files.push_back_unique( filename ); continue; } } // if ( c[ 0 ] == '#' ) { if ( c[ 1 ] == 'd' and c[ 2 ] == 'e' and c[ 3 ] == 'f' and c[ 4 ] == 'i' and c[ 5 ] == 'n' and c[ 6 ] == 'e' and c[ 7 ] == ' ' ) { defines[ get_next_word( c += 8 ) ]; continue; } if ( c[ 1 ] == 'i' ) { if ( c[ 2 ] == 'f' ) { if ( c[ 3 ] == 'd' and c[ 4 ] == 'e' and c[ 5 ] == 'f' and c[ 6 ] == ' ' ) { if ( not defines.count( get_next_word( c += 7 ) ) ) skip_lines_until_endif_or_else( c ); continue; } if ( c[ 3 ] == 'n' and c[ 4 ] == 'd' and c[ 5 ] == 'e' and c[ 6 ] == 'f' and c[ 7 ] == ' ' ) { if ( defines.count( get_next_word( c += 8 ) ) ) skip_lines_until_endif_or_else( c ); continue; } } if ( c[ 2 ] == 'n' and c[ 3 ] == 'c' and c[ 4 ] == 'l' and c[ 5 ] == 'u' and c[ 6 ] == 'd' and c[ 7 ] == 'e' and c[ 8 ] == ' ' ) { bool syst; String bas_name = get_include_filename( c += 9, syst ); String inc_file = ce.find_src( bas_name, current_dir, inc_paths, not syst ); if ( not inc_file ) inc_file = ce.find_src( bas_name, current_dir, ce_inc_paths, not syst ); // formulation. if ( not inc_file ) { int form_ind = bas_name.find( "formulation." ); if ( form_ind >= 0 and bas_name != "formulation.h" ) { String h_py = bas_name + ".py"; if ( not file_exists( h_py ) ) { int beg_form = form_ind + 12; int end_form = bas_name.find( ".", beg_form ); String form = bas_name.beg_upto( end_form ).end_from( beg_form ); int beg_elem = end_form + 1; int end_elem = bas_name.find( ".", beg_elem ); String elem = bas_name.beg_upto( end_elem ).end_from( beg_elem ); BasicVec<String> elem_list = tokenize( elem, ',' ); int beg_parm = end_elem + 1; int end_parm = bas_name.find( ".", beg_parm ); String parm = bas_name.beg_upto( end_parm ).end_from( beg_parm ); BasicVec<String> parm_list = tokenize( parm, ',' ); BasicVec<String> der_vars; BasicVec<String> dim; for( int np = 0; np < parm_list.size(); ++np ) { if ( parm_list[ np ].begins_by( "name_der_vars=" ) ) der_vars << parm_list[ np ].end_from( 14 ); else if ( parm_list[ np ].begins_by( "dim=" ) ) dim << parm_list[ np ].end_from( 4 ); } File f( h_py, "w" ); // f << "import sys, os\n"; // f << "sys.path.append( os.getcwd() + '/LMT' )\n"; // f << "sys.path.append( os.getcwd() + '/LMTpp' )\n"; f << "import formal_lf\n"; f << "formal_lf.write_pb(\n"; f << " name = '" << form << "',\n"; f << " formulations = ['" << form << "'],\n"; f << " elements = ["; for( int i = 0; i < elem_list.size(); ++i ) f << ( i ? ",'" : "'" ) << elem_list[ i ] << "'"; f << "],\n"; f << " incpaths = ['.'"; for( int i = 0; i < ce_inc_paths.size(); ++i ) if ( ce_inc_paths[ i ].find( "LMT" ) >= 0 ) f << ",'" << ce_inc_paths[ i ].beg_upto( ce_inc_paths[ i ].find( "/include" ) ) << "/formulations'"; f << "],\n"; f << " name_der_vars=["; for( int nd = 0; nd < der_vars.size(); ++nd ) f << ( nd ? "," : "" ) << '"' << der_vars[ nd ] << '"'; f << "],\n"; if ( dim.size() ) f << " dim='" << dim[ 0 ] << "',\n"; f << ")\n"; // f << " options = { 'behavior_simplification' : 'plane stress', 'behavior_law' : s }, // f << " # name_der_vars = [ "frac_E2", "frac_G12", "nu12" ] # } } } // .h.py ? if ( bas_name.ends_with( ".h" ) ) { if ( String h_py = ce.find_src( bas_name + ".py", current_dir ) ) { inc_file = h_py.beg_upto( h_py.size() - 3 ); if ( last_modification_time_or_zero_of_file_named( h_py ) > last_modification_time_or_zero_of_file_named( inc_file ) ) make_h_py( h_py, inc_file ); } } // parse rec if ( inc_file ) { inc_file = canonicalize_filename( inc_file ); inc_files << inc_file; // if ( not already_parsed.contains( inc_file ) ) { already_parsed << inc_file; parse_src_file_rec( ce, inc_file ); } } continue; } } if ( c[ 1 ] == 'p' and c[ 2 ] == 'r' and c[ 3 ] == 'a' and c[ 4 ] == 'g' and c[ 5 ] == 'm' and c[ 6 ] == 'a' and c[ 7 ] == ' ' ) { c += 8; if ( strncmp( c, "src_file ", 9 ) == 0 ) { String o = get_pragma_arg( c += 9 ); String s = ce.find_src( o, current_dir ); if ( s.size() ) src_files << s; else cerrn << "Impossible to find src '" << o << "'"; continue; } if ( strncmp( c, "lib_path ", 9 ) == 0 ) { lib_paths << ce.find_src( get_pragma_arg( c += 9 ), current_dir ); continue; } if ( strncmp( c, "lib_name ", 9 ) == 0 ) { lib_names << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "fra_name ", 9 ) == 0 ) { fra_names << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "inc_path ", 9 ) == 0 ) { String path = ce.find_src( get_pragma_arg( c += 9 ), current_dir ); if ( not ( path.ends_with( '/' ) or path.ends_with( '\\' ) ) ) path += '/'; inc_paths << path; continue; } if ( strncmp( c, "cpp_flag ", 9 ) == 0 ) { cpp_flags << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "lnk_flag ", 9 ) == 0 ) { lnk_flags << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "gpu_flag ", 9 ) == 0 ) { gpu_flags << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "template ", 9 ) == 0 ) { var_templ << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "cxx_name ", 9 ) == 0 ) { cxx_name << get_pragma_arg( c += 9 ); continue; } } } // ++c; } }