Implement dependency resolver
(WIP: To be updated design document)
Basic steps
- Read IDL file
- Parsing IDL fragment
- Generate binding code
Read IDL file
- One IDL file should be represented to one IDL fragment.
Parsing IDL fragment
- Use WebIDL2 parser to create AST(Abstract Syntax Tree)
- In this step, should create IDL definition objects(interface, enum and so on) from IDL fragment.
Create IDL definition object
We should create IDL definition object(e.g. IDL interface, IDL enum and so on) from IDL fragment. For example, if there is an IDL fragment,
interface Hello {
attribute World world;
attribute double yaho;
};
enum World {
"absolute",
"bacardi"
};
We can create two IDL definition objects for Hello and World. Once the IDL definition object is created, it should keep the object in map-like data structure we called IDL definition map.
Dependency check
During creating IDL definition objects from IDL fragment, each task should check whether some type is already defined or not. For example, if there is an IDL fragment as follows:
interface Hello {
attribute World world;
attribute double yaho;
};
The above Hello interface needs World type and double type. The double type is a kind of basic types but the World type is not. If IDL definition of World type exists in the same IDL fragment, then might be no problem fortunately. But if not exists in above case, we have to wait for IDL definition object which is defined from external another IDL fragment.
To check this dependency, we should have IDL definition map in global area and update it whenever creating a new IDL definition object. For example, creating IDL definition object for Hello interface, it's only possible if IDL definition object for World is already created.
Undefined type map
While creating IDL definition object in parsing step, if we faced undefined type, we should wait for the type to be resolved. BTW, there is no way to block thread in code level in JavaScript(TypeScript as well). So, we should use Promise and if the type is already defined, the Promise should be resolved.
In other words, if we faced undefined type, we should queue the task into pending queue we called undefined type map.
No dependency
Happy case!
Generate binding code
- If the generator code doesn't