Developer Notes on CQL Development
We have extensive documentation at CQL Internals.
If you aren't good with
yacc
/lex
you probably should do some homework before you start. CQL development is all about building and walking a syntax tree. It's possible to make local changes without knowing the details but it can be hard to figure out where to make changes without context.CQL development is basically test driven, to create a new feature:
- Add the language feature to
test.sql
- run
test.sh
; it will fail due to parse error - Add the syntax to
cql.y
and create the necessary tree pieces inast.h
- run
test.sh
; accept any file differences to install this as the new reference baseline. - Add a test case to
sem_test.sql
that uses your new feature.sem_test.sql
can contain pattern matching for the semantic output. - run
test.sh
; it will fail because it will find an AST node it doesn't understand - edit
sem.c
to do the analysis for your new node type - adjust the verification in
sem_test.sql
accordingly - run
test.sh
until it passes making fixes as needed - there will be new diff output and it will be spitting out the diffs; if you are happy with the new output, accept the diffs to update the reference outputs; note the pattern matching validations will still fail if the output goes bad even if the reference comparison is good, the reference output is a double check
- add code that uses your new feature to
cg_test.sql
, this is the code gen test, verifications using pattern matching are also allowed there - run
test.sh
- it will fail because codegen doesn't know about your new feature
- edit
cg_c.c
(or a different code gen if you're doing test helpers or some such) to support your new code - cycle running
test.sh
until it passes - accept each diff when you're happy with the new output
- Add code that runs your new feature using run_test.sql
- Run
test.sh
, if your codegen was perfect it could pass; it probably won't at first - fix your code until it's done; you shouldn't need to accept any more diffs at this point
- run
cov.sh
to confirm 100% coverage - sanity check the GCC build (I use a linux box for this)
- Add the language feature to
Get a solid code review and land as usual.
By the time you have done this you will have passed the tests dozens of times and you will know exactly what your code is doing to the entire battery of cql combinations. Missing tests can be painful and cause downstream regressions so be ruthless about adding enough combinations and validating the essential parts. The snapshot diffing is helpful but the real gating is done by the pattern matching logic.
Note: none of this works unless you are standing the main source directory
Note: the test scripts make a lot of turds, at this point almost everything should be going into the out
directory but it wasn't always so. You can use make clean
to get rid of the build stuff wherever it may be.
Alternatively use source control to get rid of any junk.