monasca-analytics/monasca_analytics/banana/typeck
Daisuke Fujita 6c7316ebbd Support python3.5 for monasca-analytics
This patch implements followings for py35 support using six(er) and 2to3.

- Python 3 map/filter returns iterator, must be converted to list
- use six.string_types instead of basestring
- use six.iteritems instead of iteritems
- use six.moves for using cPickle and SocketServer packages
- use six.assertCountEqual instead of assertItemsEqual
- remove relative imports
- update BytecodeAssembler(monasca_analytics/
  banana/bytecode/assembler.py) for python3

Can be tested with:
  tox -e py35

Change-Id: If1b92d0ffc56492950f6a02ebdbe1596d0dce368
2019-01-28 09:47:45 +00:00
..
README.md This commit introduces the first version of Banana configuration language. 2016-08-22 14:29:26 +01:00
__init__.py This commit introduces the first version of Banana configuration language. 2016-08-22 14:29:26 +01:00
config.py Support python3.5 for monasca-analytics 2019-01-28 09:47:45 +00:00
connections.py Improve error message and span calculation. 2016-09-21 15:55:24 +01:00
type_table.py Support python3.5 for monasca-analytics 2019-01-28 09:47:45 +00:00
type_util.py Support python3.5 for monasca-analytics 2019-01-28 09:47:45 +00:00

README.md

Type-checker

This folder is all about the type checking of banana files. The type checker purpose is to verify that components exist, the type of local variable matches the requirements of components parameters and assignments between them are correct. It also checks that connections between components are valid.

The biggest difference between the old validation of the JSON format is that we have more information available. We can warn users when they make mistakes and point at the exact locations using Span. Also, the type table generated is used by other passes to perform other static analyses.

This is the second step of the pipeline:

       +-------+                  +---------------------+
       |       |                  |                     |
 --->  |  AST  | ---- typeck ---> |   AST & TypeTable   | --->
       |       |                  |                     |
       +-------+                  +---------------------+

The module type_util.py contains all the possible types that are known by the type checker. The TypeTable built lives in the type_table.py module.

Current status

  • Type check numbers
  • Type check string literals
  • Type check variable assignments
  • Type check component assignments
  • Type check component parameters
  • Type check connections
  • Resolve variable names
  • Resolve imports
  • Type check disconnections

Tests

All tests for the type checker (i.e. making sure that inferred types are correct and that errors are raised in appropriate situation) lives in test/banana/typeck.

This folder looks like this:

test/banana/typeck
├── should_fail
│   ├── ...
│   └── file.banana
├── should_pass
│   ├── ...
│   └── file.banana
└── test_typeck_config.py

The test_typeck_config, generates one test for each file in the should_pass and should_fail directories.

For each generated test, we basically run the following passes:

  • grammar: convert the input text into an AST.
  • typeck: run the type checker.

Tests can assert various things in banana comments:

  • In the should_fail directory, a test is expected to use the RAISE instruction to specify a type of exceptions that should be raised by the test.
  • In the should_pass directory, a test is expected to not raised any exception and to specify the state of the TypeTable when the type checker has type checked everything in the file. This is done with the TYPE_TABLE_EQ instruction.

Available instruction

  • # RAISE <exception-name>: Check that exception-name is raised.
  • # TYPE_TABLE_EQ <string-version-of-the-type-table>
  • # NEW_TEST: This instruction splits the file into two tests. However, the expected exception or type table should still be the same. It allows us to verify what should be semantically equivalent in the grammar.