src/Pure/context_position.ML
author nipkow
Fri, 11 Dec 2020 17:58:01 +0100
changeset 72884 50f18a822ee9
parent 71680 e20e117c3735
child 76804 3e8340fcaa16
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/context_position.ML
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     3
28409
a1feb819b0a2 renamed report to report_visible;
wenzelm
parents: 28405
diff changeset
     4
Context position visibility flag.
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     5
*)
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     6
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     7
signature CONTEXT_POSITION =
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     8
sig
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents: 52700
diff changeset
     9
  val is_visible_generic: Context.generic -> bool
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    10
  val is_visible: Proof.context -> bool
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    11
  val is_visible_global: theory -> bool
60858
7bf2188a0998 evaluate ML expressions within debugger context;
wenzelm
parents: 57858
diff changeset
    12
  val set_visible_generic: bool -> Context.generic -> Context.generic
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    13
  val set_visible: bool -> Proof.context -> Proof.context
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    14
  val set_visible_global: bool -> theory -> theory
57858
39d9c7f175e0 refined context visibility again (amending f5f9fad3321c, 8e3e004f1c31): avoid spurious warning due to global config options;
wenzelm
parents: 56333
diff changeset
    15
  val is_really_visible: Proof.context -> bool
39d9c7f175e0 refined context visibility again (amending f5f9fad3321c, 8e3e004f1c31): avoid spurious warning due to global config options;
wenzelm
parents: 56333
diff changeset
    16
  val not_really: Proof.context -> Proof.context
63030
4e7eff53bee7 avoid massive multiplication of reports due to interpretation;
wenzelm
parents: 60858
diff changeset
    17
  val restore_visible_generic: Context.generic -> Context.generic -> Context.generic
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    18
  val restore_visible: Proof.context -> Proof.context -> Proof.context
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    19
  val restore_visible_global: theory -> theory -> theory
71675
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    20
  val pide_reports: unit -> bool
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    21
  val reports_enabled_generic: Context.generic -> bool
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    22
  val reports_enabled: Proof.context -> bool
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    23
  val reports_enabled_global: theory -> bool
55923
wenzelm
parents: 55672
diff changeset
    24
  val is_reported_generic: Context.generic -> Position.T -> bool
wenzelm
parents: 55672
diff changeset
    25
  val is_reported: Proof.context -> Position.T -> bool
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    26
  val is_reported_global: theory -> Position.T -> bool
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    27
  val report_generic: Context.generic -> Position.T -> Markup.T -> unit
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    28
  val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    29
  val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    30
  val report: Proof.context -> Position.T -> Markup.T -> unit
48767
7f0c469cc796 reports with body text, not just markup;
wenzelm
parents: 47813
diff changeset
    31
  val reports_text: Proof.context -> Position.report_text list -> unit
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    32
  val reports_generic: Context.generic -> Position.report list -> unit
44736
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    33
  val reports: Proof.context -> Position.report list -> unit
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    34
  val reports_global: theory -> Position.report list -> unit
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    35
end;
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    36
33383
12d79ece3f7e modernized structure Context_Position;
wenzelm
parents: 29606
diff changeset
    37
structure Context_Position: CONTEXT_POSITION =
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    38
struct
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    39
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    40
(* visible context *)
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    41
71680
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    42
val really = Config.declare_bool ("really", Position.none) (K true);
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    43
val visible = Config.declare_bool ("visible", Position.none) (K true);
47813
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    44
71680
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    45
val is_visible_generic = Config.apply_generic visible;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    46
val is_visible = Config.apply visible;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    47
val is_visible_global = Config.apply_global visible;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    48
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    49
val set_visible_generic = Config.put_generic visible;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    50
val set_visible = Config.put visible;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    51
val set_visible_global = Config.put_global visible;
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    52
71680
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    53
val is_really = Config.apply really;
57858
39d9c7f175e0 refined context visibility again (amending f5f9fad3321c, 8e3e004f1c31): avoid spurious warning due to global config options;
wenzelm
parents: 56333
diff changeset
    54
fun is_really_visible ctxt = is_really ctxt andalso is_visible ctxt;
71680
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    55
val not_really = Config.put really false;
57858
39d9c7f175e0 refined context visibility again (amending f5f9fad3321c, 8e3e004f1c31): avoid spurious warning due to global config options;
wenzelm
parents: 56333
diff changeset
    56
71680
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    57
fun restore_visible_generic context =
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    58
  Config.restore_generic really context #>
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    59
  Config.restore_generic visible context;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    60
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    61
val restore_visible = Context.proof_map o restore_visible_generic o Context.Proof;
e20e117c3735 tuned -- prefer Config.T over Data;
wenzelm
parents: 71675
diff changeset
    62
val restore_visible_global = Context.theory_map o restore_visible_generic o Context.Theory;
38831
4933a3dfd745 more careful treatment of context visibility flag wrt. spurious warnings;
wenzelm
parents: 38481
diff changeset
    63
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    64
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    65
(* PIDE reports *)
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    66
71675
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    67
fun pide_reports () = Options.default_bool "pide_reports";
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    68
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    69
fun reports_enabled_generic context = pide_reports () andalso is_visible_generic context;
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    70
val reports_enabled = reports_enabled_generic o Context.Proof;
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    71
val reports_enabled_global = reports_enabled_generic o Context.Theory;
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    72
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    73
fun is_reported_generic context pos =
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    74
  reports_enabled_generic context andalso Position.is_reported pos;
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    75
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    76
val is_reported = is_reported_generic o Context.Proof;
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    77
val is_reported_global = is_reported_generic o Context.Theory;
55923
wenzelm
parents: 55672
diff changeset
    78
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    79
fun report_generic context pos markup =
55923
wenzelm
parents: 55672
diff changeset
    80
  if is_reported_generic context pos then
56333
38f1422ef473 support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents: 56294
diff changeset
    81
    Output.report [Position.reported_text pos markup ""]
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    82
  else ();
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    83
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    84
fun reported_text ctxt pos markup txt =
55923
wenzelm
parents: 55672
diff changeset
    85
  if is_reported ctxt pos then Position.reported_text pos markup txt else "";
38481
81ec258c4cd3 Output_Position.report_text -- markup with potential "arguments";
wenzelm
parents: 38237
diff changeset
    86
56333
38f1422ef473 support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents: 56294
diff changeset
    87
fun report_text ctxt pos markup txt = Output.report [reported_text ctxt pos markup txt];
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    88
fun report ctxt pos markup = report_text ctxt pos markup "";
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    89
71675
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    90
fun reports_text ctxt reps =
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    91
  if reports_enabled ctxt then Position.reports_text reps else ();
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    92
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    93
fun reports_generic context reps =
55cb4271858b less redundant markup reports;
wenzelm
parents: 71674
diff changeset
    94
  if reports_enabled_generic context then Position.reports reps else ();
71674
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    95
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    96
val reports = reports_generic o Context.Proof;
48ff625687f5 more accurate context position reports;
wenzelm
parents: 63030
diff changeset
    97
val reports_global = reports_generic o Context.Theory;
44736
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    98
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    99
end;