src/Pure/PIDE/resources.ML
changeset 72638 2a7fc87495e0
parent 72637 fd68c9c1b90b
child 72669 5e7916535860
equal deleted inserted replaced
72637:fd68c9c1b90b 72638:2a7fc87495e0
    11     {html_symbols: (string * int) list,
    11     {html_symbols: (string * int) list,
    12      session_positions: (string * Properties.T) list,
    12      session_positions: (string * Properties.T) list,
    13      session_directories: (string * string) list,
    13      session_directories: (string * string) list,
    14      session_chapters: (string * string) list,
    14      session_chapters: (string * string) list,
    15      bibtex_entries: (string * string list) list,
    15      bibtex_entries: (string * string list) list,
       
    16      command_timings: Properties.T list,
    16      docs: string list,
    17      docs: string list,
    17      global_theories: (string * string) list,
    18      global_theories: (string * string) list,
    18      loaded_theories: string list} -> unit
    19      loaded_theories: string list} -> unit
    19   val init_session_yxml: string -> unit
    20   val init_session_yxml: string -> unit
    20   val init_session_file: Path.T -> unit
    21   val init_session_file: Path.T -> unit
    22   val global_theory: string -> string option
    23   val global_theory: string -> string option
    23   val loaded_theory: string -> bool
    24   val loaded_theory: string -> bool
    24   val html_symbols: unit -> HTML.symbols
    25   val html_symbols: unit -> HTML.symbols
    25   val check_session: Proof.context -> string * Position.T -> string
    26   val check_session: Proof.context -> string * Position.T -> string
    26   val session_chapter: string -> string
    27   val session_chapter: string -> string
       
    28   val last_timing: Toplevel.transition -> Time.time
    27   val check_doc: Proof.context -> string * Position.T -> string
    29   val check_doc: Proof.context -> string * Position.T -> string
    28   val master_directory: theory -> Path.T
    30   val master_directory: theory -> Path.T
    29   val imports_of: theory -> (string * Position.T) list
    31   val imports_of: theory -> (string * Position.T) list
    30   val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
    32   val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
    31   val thy_path: Path.T -> Path.T
    33   val thy_path: Path.T -> Path.T
    48 end;
    50 end;
    49 
    51 
    50 structure Resources: RESOURCES =
    52 structure Resources: RESOURCES =
    51 struct
    53 struct
    52 
    54 
       
    55 (* command timings *)
       
    56 
       
    57 type timings = ((string * Time.time) Inttab.table) Symtab.table;  (*file -> offset -> name, time*)
       
    58 
       
    59 val empty_timings: timings = Symtab.empty;
       
    60 
       
    61 fun update_timings props =
       
    62   (case Markup.parse_command_timing_properties props of
       
    63     SOME ({file, offset, name}, time) =>
       
    64       Symtab.map_default (file, Inttab.empty)
       
    65         (Inttab.map_default (offset, (name, time)) (fn (_, t) => (name, t + time)))
       
    66   | NONE => I);
       
    67 
       
    68 fun make_timings command_timings =
       
    69   fold update_timings command_timings empty_timings;
       
    70 
       
    71 fun approximative_id name pos =
       
    72   (case (Position.file_of pos, Position.offset_of pos) of
       
    73     (SOME file, SOME offset) =>
       
    74       if name = "" then NONE else SOME {file = file, offset = offset, name = name}
       
    75   | _ => NONE);
       
    76 
       
    77 fun get_timings timings tr =
       
    78   (case approximative_id (Toplevel.name_of tr) (Toplevel.pos_of tr) of
       
    79     SOME {file, offset, name} =>
       
    80       (case Symtab.lookup timings file of
       
    81         SOME offsets =>
       
    82           (case Inttab.lookup offsets offset of
       
    83             SOME (name', time) => if name = name' then SOME time else NONE
       
    84           | NONE => NONE)
       
    85       | NONE => NONE)
       
    86   | NONE => NONE)
       
    87   |> the_default Time.zeroTime;
       
    88 
       
    89 
    53 (* session base *)
    90 (* session base *)
    54 
    91 
    55 val default_qualifier = "Draft";
    92 val default_qualifier = "Draft";
    56 
    93 
    57 type entry = {pos: Position.T, serial: serial};
    94 type entry = {pos: Position.T, serial: serial};
    63   {html_symbols = HTML.no_symbols,
   100   {html_symbols = HTML.no_symbols,
    64    session_positions = []: (string * entry) list,
   101    session_positions = []: (string * entry) list,
    65    session_directories = Symtab.empty: Path.T list Symtab.table,
   102    session_directories = Symtab.empty: Path.T list Symtab.table,
    66    session_chapters = Symtab.empty: string Symtab.table,
   103    session_chapters = Symtab.empty: string Symtab.table,
    67    bibtex_entries = Symtab.empty: string list Symtab.table,
   104    bibtex_entries = Symtab.empty: string list Symtab.table,
       
   105    timings = empty_timings,
    68    docs = []: (string * entry) list,
   106    docs = []: (string * entry) list,
    69    global_theories = Symtab.empty: string Symtab.table,
   107    global_theories = Symtab.empty: string Symtab.table,
    70    loaded_theories = Symtab.empty: unit Symtab.table};
   108    loaded_theories = Symtab.empty: unit Symtab.table};
    71 
   109 
    72 val global_session_base =
   110 val global_session_base =
    73   Synchronized.var "Sessions.base" empty_session_base;
   111   Synchronized.var "Sessions.base" empty_session_base;
    74 
   112 
    75 fun init_session
   113 fun init_session
    76     {html_symbols, session_positions, session_directories, session_chapters,
   114     {html_symbols, session_positions, session_directories, session_chapters,
    77       bibtex_entries, docs, global_theories, loaded_theories} =
   115       bibtex_entries, command_timings, docs, global_theories, loaded_theories} =
    78   Synchronized.change global_session_base
   116   Synchronized.change global_session_base
    79     (fn _ =>
   117     (fn _ =>
    80       {html_symbols = HTML.make_symbols html_symbols,
   118       {html_symbols = HTML.make_symbols html_symbols,
    81        session_positions = sort_by #1 (map (apsnd make_entry) session_positions),
   119        session_positions = sort_by #1 (map (apsnd make_entry) session_positions),
    82        session_directories =
   120        session_directories =
    83          fold_rev (fn (dir, name) => Symtab.cons_list (name, Path.explode dir))
   121          fold_rev (fn (dir, name) => Symtab.cons_list (name, Path.explode dir))
    84            session_directories Symtab.empty,
   122            session_directories Symtab.empty,
    85        session_chapters = Symtab.make session_chapters,
   123        session_chapters = Symtab.make session_chapters,
    86        bibtex_entries = Symtab.make bibtex_entries,
   124        bibtex_entries = Symtab.make bibtex_entries,
       
   125        timings = make_timings command_timings,
    87        docs = sort_by #1 (map (apsnd make_entry o rpair []) docs),
   126        docs = sort_by #1 (map (apsnd make_entry o rpair []) docs),
    88        global_theories = Symtab.make global_theories,
   127        global_theories = Symtab.make global_theories,
    89        loaded_theories = Symtab.make_set loaded_theories});
   128        loaded_theories = Symtab.make_set loaded_theories});
    90 
   129 
    91 fun init_session_yxml yxml =
   130 fun init_session_yxml yxml =
    92   let
   131   let
    93     val (html_symbols, (session_positions, (session_directories, (session_chapters,
   132     val (html_symbols, (session_positions, (session_directories, (session_chapters,
    94           (bibtex_entries, (docs, (global_theories, loaded_theories))))))) =
   133           (bibtex_entries, (command_timings, (docs, (global_theories, loaded_theories)))))))) =
    95       YXML.parse_body yxml |>
   134       YXML.parse_body yxml |>
    96         let open XML.Decode in
   135         let open XML.Decode in
    97           pair (list (pair string int)) (pair (list (pair string properties))
   136           pair (list (pair string int))
    98             (pair (list (pair string string)) (pair (list (pair string string))
   137             (pair (list (pair string properties))
    99               (pair (list (pair string (list string))) (pair (list string)
   138               (pair (list (pair string string)) (pair (list (pair string string))
   100                 (pair (list (pair string string)) (list string)))))))
   139                 (pair (list (pair string (list string))) (pair (list properties)
       
   140                   (pair (list string) (pair (list (pair string string)) (list string))))))))
   101         end;
   141         end;
   102   in
   142   in
   103     init_session
   143     init_session
   104       {html_symbols = html_symbols,
   144       {html_symbols = html_symbols,
   105        session_positions = session_positions,
   145        session_positions = session_positions,
   106        session_directories = session_directories,
   146        session_directories = session_directories,
   107        session_chapters = session_chapters,
   147        session_chapters = session_chapters,
   108        bibtex_entries = bibtex_entries,
   148        bibtex_entries = bibtex_entries,
       
   149        command_timings = command_timings,
   109        docs = docs,
   150        docs = docs,
   110        global_theories = global_theories,
   151        global_theories = global_theories,
   111        loaded_theories = loaded_theories}
   152        loaded_theories = loaded_theories}
   112   end;
   153   end;
   113 
   154 
   120       {html_symbols = HTML.no_symbols,
   161       {html_symbols = HTML.no_symbols,
   121        session_positions = [],
   162        session_positions = [],
   122        session_directories = Symtab.empty,
   163        session_directories = Symtab.empty,
   123        session_chapters = Symtab.empty,
   164        session_chapters = Symtab.empty,
   124        bibtex_entries = Symtab.empty,
   165        bibtex_entries = Symtab.empty,
       
   166        timings = empty_timings,
   125        docs = [],
   167        docs = [],
   126        global_theories = global_theories,
   168        global_theories = global_theories,
   127        loaded_theories = loaded_theories});
   169        loaded_theories = loaded_theories});
   128 
   170 
   129 fun get_session_base f = f (Synchronized.value global_session_base);
   171 fun get_session_base f = f (Synchronized.value global_session_base);
   142       Markup.entity Markup.sessionN name
   184       Markup.entity Markup.sessionN name
   143       |> Markup.properties (Position.entity_properties_of false serial pos));
   185       |> Markup.properties (Position.entity_properties_of false serial pos));
   144 
   186 
   145 fun session_chapter name =
   187 fun session_chapter name =
   146   the_default "Unsorted" (Symtab.lookup (get_session_base #session_chapters) name);
   188   the_default "Unsorted" (Symtab.lookup (get_session_base #session_chapters) name);
       
   189 
       
   190 fun last_timing tr = get_timings (get_session_base #timings) tr;
   147 
   191 
   148 val check_doc = check_name #docs "documentation" (Markup.doc o #1);
   192 val check_doc = check_name #docs "documentation" (Markup.doc o #1);
   149 
   193 
   150 
   194 
   151 (* manage source files *)
   195 (* manage source files *)