Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[feature] opatrack: Printer with source locations.

  • Loading branch information...
commit f0aca58d86a611e6ca2f7bdaf96b36e4d79ddf31 1 parent 695fb31
@fpessaux fpessaux authored
Showing with 41 additions and 0 deletions.
  1. +29 −0 libqmlcompil/qmlPrint.ml
  2. +12 −0 libqmlcompil/qmlTracker.ml
View
29 libqmlcompil/qmlPrint.ml
@@ -667,6 +667,34 @@ object(self)
annotation_node_factory QmlAst.QAnnot.pat self#pat0 fmt expr
end
+
+
+(* ************************************************************************** *)
+(** {b Descr}: Prints an AST element and its source code location. Used by the
+ position printer below which is made available in opatrack via file
+ qmlTracker.ml.
+ {b Visibility}: Not exported outside this module. *)
+(* ************************************************************************** *)
+let position_node_factory pos pp fmt ast =
+ Format.fprintf fmt "(%a : § %a)" pp ast FilePos.pp (pos ast)
+
+
+
+(* ************************************************************************** *)
+(** {b Descr}: Printer decorating source code with positions of its elements.
+ {b Visibility}: Exported outside this module. *)
+(* ************************************************************************** *)
+class position_printer =
+object(self)
+ inherit base_printer_with_sugared_types
+ method expr_node fmt expr =
+ position_node_factory QmlAst.Pos.expr self#expr0 fmt expr
+ method pat_node fmt expr =
+ position_node_factory QmlAst.Pos.pat self#pat0 fmt expr
+end
+
+
+
exception Bad_printer
(* you cannot create instances of these two printers
@@ -759,6 +787,7 @@ let pp_light_ident = new light_ident_printer
let pp_very_light_ident = new very_light_ident_printer
let pp_declaration = new declaration_printer
let pp_annotation = new annotation_printer
+let pp_position = new position_printer
let pp_value_restriction = new pp_value_restriction
(**
View
12 libqmlcompil/qmlTracker.ml
@@ -77,6 +77,15 @@ struct
QmlPrint.pp_annotation#code fmt code;
Format.fprintf fmt "@."
+ (* ************************************************************************ *)
+ (** {b Descr}: Printer for position in source code.
+ {b Visibility} : Not exported outside this module. *)
+ (* ************************************************************************ *)
+ let position fmt code =
+ Format.fprintf fmt "/* printer: --print position */@\n@\n";
+ QmlPrint.pp_position#code fmt code;
+ Format.fprintf fmt "@."
+
let tracked fmt code =
Format.fprintf fmt "/* printer: --print tracked */" ;
let bind kw rec_ (s, e) =
@@ -110,6 +119,7 @@ let for_ei_id = define "for_ei"
let size_id = define "size"
let declaration_id = define "declaration"
let annotation_id = define "annotation"
+let position_id = define "position"
let tracked_id = define "tracked"
let gamma_id = define "gamma"
@@ -129,6 +139,8 @@ let printers extract _ =
very_light_ident_id, make_code Printer.very_light_ident ;
declaration_id, make_code Printer.declaration ;
annotation_id, make_code Printer.annotation;
+ (* Source code positions printer registered. *)
+ position_id, make_code Printer.position;
size_id, make_code Printer.size ;
with_type_id, make_ac Printer.code_with_type;
for_ei_id, make_ac Printer.code_for_ei;
Please sign in to comment.
Something went wrong with that request. Please try again.