package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file entity_code.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
(* Yoann Padioleau
 *
 * Copyright (C) 2009, 2010 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
 * license.txt for more details.
 *)
open Common

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)
(*
 * The code in this module used to be in database_code.ml but many stuff
 * now have their own view on how to represent a code database 
 * (database_code.ml but also graph_code.ml, prolog_code.ml, etc)
 *)

(*****************************************************************************)
(* Type *)
(*****************************************************************************)
(* 
 * Code entities.
 * 
 * See also http://ctags.sourceforge.net/FORMAT and the doc on 'kind'
 * note: if you change this, you may want to bump graph_code.version.
 * 
 * coupling: If you add a constructor modify also entity_kind_of_string()!
 * coupling: if you add a new kind of entity, then don't forget to modify
 *  also size_font_multiplier_of_categ in code_map/.
 * 
 * less: could perhaps factorize code with highlight_code.ml? see 
 *  entity_kind_of_highlight_category_def|use
 *)
type entity_kind = 
  | Package
  (* when we use the database for completion purpose, then files/dirs
   * are also useful "entities" to get completion for.
   *)
  | Dir

  | Module 
  | File 

  | Function
  | Class (* Less: Obj, because in JS it differs from Class *)
  | Type
  | Constant | Global
  | Macro
  | Exception
  | TopStmts

  (* nested entities *)
  | Field
  | Method
  | ClassConstant
  | Constructor (* for ml *)

  (* forward decl *)
  | Prototype | GlobalExtern

  (* people often spread the same component in multiple dirs with the same
   * name (hmm could be merged now with Package)
   *)
  | MultiDirs

  | Other of string

      
(* todo: IsInlinedMethod, ...
 * todo: IsOverriding, IsOverriden
 *)
type property = 
   (* mostly function properties *)

   (* todo: could also say which argument is dataflow involved in the
    * dynamic call if any 
    *)
   | ContainDynamicCall
   | ContainReflectionCall

    (* the argument position taken by ref; 0-index based *)
   | TakeArgNByRef of int

   | UseGlobal of string
   | ContainDeadStatements

   | DeadCode (* the function itself is dead, e.g. never called *)
   | CodeCoverage of int list (* e.g. covered lines by unit tests *)

   (* for class *)
   | ClassKind of class_kind

   | Privacy of privacy
   | Abstract
   | Final
   | Static

   (* used for the xhp @required fields for now *)
   | Required
   | Async

   (* todo: git info, e.g. Age, Authors, Age_profile (range) *)
  and privacy = Public | Protected | Private

  and class_kind = Struct | Class_ | Interface | Trait | Enum


(*****************************************************************************)
(* String of *)
(*****************************************************************************)

(* todo: should be autogenerated !! *)
let string_of_entity_kind e = 
  match e with
  | Function -> "Function"
  | Prototype -> "Prototype"
  | GlobalExtern -> "GlobalExtern"
  | Class -> "Class"

  | Module -> "Module"
  | Package -> "Package"
  | Type -> "Type"
  | Constant -> "Constant"
  | Global -> "Global"
  | Macro -> "Macro"
  | TopStmts -> "TopStmts"
  | Method -> "Method"
  | Field -> "Field"
  | ClassConstant -> "ClassConstant"
  | Other s -> "Other:" ^ s
  | File -> "File"
  | Dir -> "Dir"
  | MultiDirs -> "MultiDirs"
  | Exception -> "Exception"
  | Constructor -> "Constructor"

let entity_kind_of_string s =
  match s with
  | "Function" -> Function
  | "Class" -> Class
  | "Module" -> Module
  | "Type" -> Type
  | "Constant" -> Constant
  | "Global" -> Global
  | "Macro" -> Macro
  | "TopStmts" -> TopStmts
  | "Method" -> Method
  | "Field" -> Field
  | "ClassConstant" -> ClassConstant
  | "File" -> File
  | "Dir" -> Dir
  | "MultiDirs" -> MultiDirs
  | "Exception" -> Exception
  | "Constructor" -> Constructor
  | _ when s =~ "Other:\\(.*\\)" -> Other (Common.matched1 s)

  | _ -> failwith ("entity_of_string: bad string = " ^ s)
OCaml

Innovation. Community. Security.