esseks / monicelli

An esoteric programming language, come se fosse antani.
GNU General Public License v3.0
1.32k stars 52 forks source link

Provide a dependency analysis mechanism for emitting only required includes #14

Closed esseks closed 9 years ago

esseks commented 9 years ago

As per the title. For instance, if assert() is never used in the program, then:

#include <cassert>

should not be emitted.

massix commented 9 years ago

My guess is that we could be able to do it by analyzing the AST built from Clang (cr #17) and emitting the dependencies of the module. The idea is that we begin by including everything, then we parse the dependencies and we remove what is unnecessary, unluckily we have to include everything first, otherwise the libclang will refuse to compile.

Otherwise we can just do something static and analyze the keywords emitted by the Nodes, easier to implement.

esseks commented 9 years ago

An easier strategy could be keeping a set of requirements at Program level and pushing new Module objects to it from semantic rules at parse time. For instance, every time an assert_stmt is parsed, the semantic rule could contain:

program.addModule(Module("cassert"));