flitter/h_program-lang/entity_code.ml
Joey Yakimowich-Payne fa600b98f7 Add poc files
2018-05-26 10:55:38 +09:00

165 lines
4.4 KiB
OCaml

(* 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
| 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)