Changeset 194

Show
Ignore:
Timestamp:
10/20/09 16:44:00 (5 weeks ago)
Author:
lb
Message:

Ordering and schema changing

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tools/log2sqlite/log2sqlite_optim.ml

    r191 r194  
    55open Sqlite3 
    66open Sqlite3.Rc 
    7  
     7open Str 
     8open List 
     9 
     10exception BadLocation of string 
    811let filename = ref None 
    912 
     
    1316 
    1417let refs_num = ref 0 
     18 
     19let conf_opt_order = ref 0 
    1520 
    1621let anonymous s =  
     
    7075     value, refId) 
    7176values("^quote_ref_loc^","^quote_kind^","^quote_keyLoc^","^quote_bool_val^","^string_of_int(!refs_num)^");" in 
     77      
    7278      exec db insert_q; 
    7379      ()       
     
    7985    List.iter (insert_keys db loc_str) keys; 
    8086    () 
     87 
     88 
     89let refLoc_token refLocation=  
     90        match refLocation with  
     91        Location(file_path, line, col) -> 
     92            let split_path = Str.split (regexp "/") file_path in  
     93            let file_name = nth split_path (length split_path - 1)  in 
     94            let tmp_str =  "\""^file_name^"\", "^string_of_int(line)^", 
     95            "^string_of_int(col) in 
     96            (match string_match (regexp ".*c$") file_name 0 with 
     97                true -> "\"Regular\", "^tmp_str 
     98              | false -> "\"Header\", "^tmp_str) 
    8199 
    82100let insert_new_ref db kind location name defLoc use_cond movb mova convb 
     
    87105    let conva_field = conv_conva conva in  
    88106    let insert_update =  
    89         "INSERT INTO ref(id, kind, name, refLoc, defLoc, useCond, movableBefore, 
     107        "INSERT INTO ref(id, kind, name, refLoc, fileKind, fileName, lineNum, 
     108        colNum, defLoc, useCond, movableBefore, 
    90109        convertibleBefore, convertibleAfter) values( 
    91110            "^string_of_int(!refs_num)^",\" "^ kind_field 
    92         ^"\",\""^name^"\",\""^conv_location location^"\",\""^conv_defLoc 
     111            ^"\",\""^name^"\",\""^conv_location location^"\", "^refLoc_token 
     112            location^" , \""^conv_defLoc 
    93113        defLoc^"\",\""^ conv_use_cond 
    94114        use_cond^"\",\""^movb_field^"\",\""^convb_field^"\",\""^conva_field^"\");" 
    95115    in  
    96         refs_num := !refs_num + 1; 
    97         insert_ref:=!insert_ref^insert_update 
    98      
     116        insert_ref:=!insert_ref^insert_update; 
     117        refs_num := !refs_num + 1  
    99118    (**conv_mova db mova location**) 
    100119 
     
    102121    let loc = "\""^conv_location location^"\"" in  
    103122    let confOpt = "\""^configOption^"\"" in   
    104     let insert_q = "INSERT INTO "^table^"(refLocation, configOption, refId) values 
    105     ("^loc^","^confOpt^", "^string_of_int(!refs_num)^");" in 
     123    let insert_q = "INSERT INTO "^table^"(refLocation, configOption, 
     124    confOpt_order, refId) values 
     125    ("^loc^","^confOpt^", "^string_of_int(!conf_opt_order)^", "^string_of_int(!refs_num)^");" in 
     126    conf_opt_order := !conf_opt_order + 1; 
    106127    exec db insert_q; 
    107128    () 
    108129 
     130 
     131let re_init_conf_opt_order =  
     132    conf_opt_order := 0 
    109133 
    110134let insert_defconfOpts db location def_copt =  
    111135    match def_copt with  
    112     Some(ConfOpt(c)) -> List.iter (insert_confOpts db location "defConfOpts") 
     136    Some(ConfOpt(c)) -> re_init_conf_opt_order; List.iter (insert_confOpts db location "defConfOpts") 
    113137    c; 
    114138    () 
     
    117141let insert_uconfOpts db location use_copt = 
    118142    match use_copt with  
    119     Some(ConfOpt(c)) -> List.iter (insert_confOpts db location "usageConfOpts") 
     143    Some(ConfOpt(c)) -> re_init_conf_opt_order; List.iter (insert_confOpts db location "usageConfOpts") 
    120144    c; 
    121145    () 
     
    150174    match x with 
    151175    | Log(file_list) -> 
    152        Printf.printf "NEW LOG "; 
    153176       List.iter (conv_file db) file_list  
    154177       
     
    176199        let references =  
    177200        exec db "CREATE TABLE IF NOT EXISTS ref (id INTEGER PRIMARY KEY, 
    178         kind TEXT, name TEXT, refLoc TEXT, defLoc TEXT, useCond TEXT, 
     201        kind TEXT, name TEXT, refLoc TEXT, fileKind TEXT, fileName TEXT, 
     202        lineNum INTEGER, colNum INTEGER, defLoc TEXT, useCond TEXT, 
    179203        movableBefore BOOLEAN, convertibleBefore BOOLEAN, 
    180204        convertibleAfter BOOLEAN); " in 
     
    183207        value BOOL, refId INTEGER); " in  
    184208        let usageConfOpts = exec db "CREATE TABLE IF NOT EXISTS usageConfOpts ( 
    185             id INTEGER PRIMARY KEY  
    186         ASC, refLocation TEXT, configOption TEXT, refId INTEGER); " in 
     209            id INTEGER PRIMARY KEY ASC, refLocation TEXT, configOption TEXT, 
     210            confOpt_order INTEGER, refId INTEGER); " in 
    187211        let defConfOpts = exec db "CREATE TABLE IF NOT EXISTS defConfOpts ( id 
    188212        INTEGER PRIMARY KEY  
    189         ASC, refLocation TEXT, configOption TEXT, refId INTEGER); " in  
     213        ASC, refLocation TEXT, configOption TEXT, confOpt_order INTEGER, refId INTEGER); " in  
    190214        Printf.printf "Checking creations\n";  
    191215        creation_check references afterKeys usageConfOpts defConfOpts;