mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 16:28:12 +03:00
Add linting
This commit is contained in:
parent
8c31e5ea60
commit
9d64150a47
49
compiler/desugared/linting.ml
Normal file
49
compiler/desugared/linting.ml
Normal file
@ -0,0 +1,49 @@
|
||||
(* This file is part of the Catala compiler, a specification language for tax
|
||||
and social benefits computation rules. Copyright (C) 2023 Inria, contributor:
|
||||
Denis Merigoux <denis.merigoux@inria.fr>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
use this file except in compliance with the License. You may obtain a copy of
|
||||
the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
License for the specific language governing permissions and limitations under
|
||||
the License. *)
|
||||
|
||||
open Shared_ast
|
||||
open Ast
|
||||
open Catala_utils
|
||||
|
||||
(** If the variable is not an input, then it should be defined somewhere. *)
|
||||
let detect_empty_definitions
|
||||
(scope : ScopeName.t)
|
||||
(def_info : ScopeDef.t)
|
||||
(def : scope_def) : unit =
|
||||
if
|
||||
RuleName.Map.is_empty def.scope_def_rules
|
||||
&& (not def.scope_def_is_condition)
|
||||
&&
|
||||
match Marked.unmark def.scope_def_io.io_input with
|
||||
| Ast.NoInput -> true
|
||||
| _ -> false
|
||||
then
|
||||
Errors.format_spanned_warning
|
||||
(ScopeDef.get_position def_info)
|
||||
"The variable %a is declared but never defined in scope %a"
|
||||
(Cli.format_with_style [ANSITerminal.yellow])
|
||||
(Format.asprintf "\"%a\"" Ast.ScopeDef.format_t def_info)
|
||||
(Cli.format_with_style [ANSITerminal.yellow])
|
||||
(Format.asprintf "\"%a\"" ScopeName.format_t scope)
|
||||
|
||||
let lint_program (p : program) : unit =
|
||||
ScopeName.Map.iter
|
||||
(fun scope_name scope ->
|
||||
ScopeDefMap.iter
|
||||
(fun scope_def_key scope_def ->
|
||||
detect_empty_definitions scope_name scope_def_key scope_def)
|
||||
scope.scope_defs)
|
||||
p.program_scopes
|
@ -174,6 +174,8 @@ let driver source_file (options : Cli.options) : int =
|
||||
let prgm = Desugared.From_surface.translate_program ctxt prgm in
|
||||
Cli.debug_print "Disambiguating...";
|
||||
let prgm = Desugared.Disambiguate.program prgm in
|
||||
Cli.debug_print "Linting...";
|
||||
Desugared.Linting.lint_program prgm;
|
||||
Cli.debug_print "Collecting rules...";
|
||||
let prgm = Scopelang.From_desugared.translate_program prgm in
|
||||
match backend with
|
||||
|
Loading…
Reference in New Issue
Block a user