Commit 1747c65d authored by Serval MARTINOT-LAGARDE's avatar Serval MARTINOT-LAGARDE 🐯
Browse files

TC-W: create warnings step

* source/compiler_stages/compiler_stages.rst,
* source/compiler_stages/tc_w/all-used.tig,
* source/compiler_stages/tc_w/code_to_write.rst,
* source/compiler_stages/tc_w/many-unused.tig,
* source/compiler_stages/tc_w/samples.rst,
* source/compiler_stages/tc_w/simple-unused.tig,
* source/compiler_stages/tc_w/tc_w.rst,
* source/reference_manual/implementation/invoking_tc/invoking_tc.rst,
* source/source_code/project_layout/index.rst,
* source/source_code/project_layout/src_warning.rst: Here.
parent 31f94240
......@@ -17,6 +17,8 @@ The compiler will be written in several steps, described below.
..
.. **TC-E**: Computing the Escaping Variables
..
.. **TC-W**: Warnings
..
.. **TC-4**: Type Checking
..
.. **TC-D**: Removing the syntactic sugar
......@@ -55,6 +57,7 @@ The compiler will be written in several steps, described below.
tc_3/tc_3
tc_r/tc_r
tc_e/tc_e
tc_w/tc_w
tc_4/tc_4
tc_d/tc_d
tc_i/tc_i
......
let
var hello := "Hello World\n"
function say_hello(name : string) =
if size(name) = 0 then
print(hello)
else
print(concat(concat("Hello ", name), "\n"))
in
say_hello("Tigrou")
end
.. _TC-W Code to Write:
TC-W Code to Write
------------------
See :ref:`src/warning`.
Complete the :code:`warning::Unused`
Implement the visitor of :code:`--wunused`.
Create library function
Write a function to run the :code:`warning::Unused` that return a
:code:`misc::error`.
Implement tasks
Create boolean task :code:`--werror` and create task :code:`--wunused` which
depends on :code:`bound`.
let
var a := 1
var a := 2
function e(c : int, d : int) : int = c * 3
var b := 4
in
a
end
.. _TC-W Samples:
TC-W Samples
------------
In this step we want to create some warnings on a bound Ast. To invoke this
warnings, you have to implement the option :code:`--wunused`.
.. literalinclude:: simple-unused.tig
:language: tiger
:caption:
.. command-output:: tc --wunused simple-unused.tig
:shell:
:cwd: .
:caption:
When :code:`--werror` is used, the execution must return a binding error on
unused variable or functions.
.. command-output:: tc --werror --wunused simple-unused.tig
:shell:
:cwd: .
:caption:
The option :code:`--werror` only set a boolean task and run nothing.
.. command-output:: tc --werror simple-unused.tig
:shell:
:cwd: .
:caption:
.. literalinclude:: all-used.tig
:language: tiger
:caption:
.. command-output:: tc --werror --wunused all-used.tig
:shell:
:cwd: .
:caption:
.. literalinclude:: many-unused.tig
:language: tiger
:caption:
.. command-output:: tc --werror --wunused many-unused.tig
:shell:
:cwd: .
:caption:
let
var a := 1
var b := a + 1
in
end
.. _TC-W:
TC-W, Warning visitor
---------------------
TC-W is not a real step.
At the end of this stage, the compiler must be able to send some warnings
from a bound AST. These features are triggered by the options :code:`--wunused`
and the :code:`--werror` flag which allows warnings to be transformed into
errors.
.. **TC-W Samples**: See TC-W work
.. **TC-W Code to Write**: What you have to do
.. toctree::
samples
code_to_write
......@@ -151,6 +151,16 @@ Options relating to escapes computation (TC-E)
Pass ``-A`` afterward to see its result.
Options relating to warnings (TC-W)
"""""""""""""""""""""""""""""""""""
--werror
Warnings are errors and return a binding error.
--wunused
Warn about unused declarations.
Options relating to type checking (TC-4)
""""""""""""""""""""""""""""""""""""""""
......
......@@ -14,6 +14,7 @@ This section desribes the mandatory layout of the package.
.. :src/bind: Abstract Syntax Tree
.. :src/escapes: Binding uses to definitions
.. :src/type: Type Checking
.. :src/warning: Warnings
.. :src/object: Handling Object-Oriented Constructs
.. :src/overload: Function Overloading
.. :src/astclone: Duplicating an Abstract Syntax Tree
......@@ -44,6 +45,7 @@ This section desribes the mandatory layout of the package.
src_ast
src_bind
src_escapes
src_warning
src_type
src_object
src_overload
......
.. _src/warning:
The :code:`src/warning` Directory
---------------------------------
Namespace :code:`warning`. Binding uses to definitions.
**File: libwarning.\* (src/warning/)**
The interface of the :code:`warning` module. It exports one procedure, :code:`warn_unused`.
**File: unused.* (src/warning/)**
The :code:`warning::Unused` visitor. Send warnings on a bound Ast.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment