Skip to content

Commit

Permalink
introduce Fragments class which is to be upper concept of interface.
Browse files Browse the repository at this point in the history
present barcardi is focused to interfaces, but Fragments are needed
to implment other things.
(eg. enums, dictionaries, typedefs and implements statements)

https://heycam.github.io/webidl/#dfn-idl-fragment

ISSUE=lunchclass#80
  • Loading branch information
hwanseung committed Sep 25, 2017
1 parent c1e7c1f commit a1117b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
30 changes: 27 additions & 3 deletions generator/idl_parser/idls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,36 @@ export class InterfaceImpl implements Interface {
name: string;
members: Array<InterfaceMemberImpl>;

constructor(raw_idl_info: any) {
this.name = raw_idl_info.name;
constructor(interface_info: any) {
this.name = interface_info.name;

this.members = new Array<InterfaceMemberImpl>();
raw_idl_info.members.forEach(member => {
interface_info.members.forEach(member => {
this.members.push(new InterfaceMemberImpl(member));
});
}
}

export class EnumImpl {
// FIXME(hwanseung): should be implement Enum
constructor(enum_info: any) {}
}

export class Fragments {
interfaces: Array<InterfaceImpl>;
enums: Array<EnumImpl>;

constructor(raw_idl_infos: any) {
raw_idl_infos.forEach(raw_idl_info => {
this.interfaces = new Array<InterfaceImpl>();
this.enums = new Array<EnumImpl>();
if (raw_idl_info['type'] == 'interface') {
this.interfaces.push(new InterfaceImpl(raw_idl_info));
} else if (raw_idl_info['type'] == 'enum') {
this.enums.push(new EnumImpl(raw_idl_info));
} else {
// FIXME: should implement dictionary, typedefs or etc.
}
});
}
}
7 changes: 4 additions & 3 deletions generator/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function generateInterface(
env: nunjucks.Environment, input_idl_path: string, output_path: string) {
const parsedData =
webidl.parse(await file.read(path.resolve(input_idl_path)));
const idl_interface: idls.Interface = new idls.InterfaceImpl(parsedData[0]);
const idl_fragments: idls.Fragments = new idls.Fragments(parsedData);

const [header_tmpl, cpp_tmpl] = await Promise.all([
file.read(path.resolve(TEMPLATE_DIR, 'interface_header.njk')),
Expand All @@ -37,9 +37,10 @@ async function generateInterface(
const header_file_path = path.resolve(output_path, idl_name + '_bridge.h');
const cpp_file_path = path.resolve(output_path, idl_name + '_bridge.cc');

// FIXME: should make each files per interfaces.
return Promise.all([
file.write(header_file_path, env.renderString(header_tmpl, idl_interface)),
file.write(cpp_file_path, env.renderString(cpp_tmpl, idl_interface))
file.write(header_file_path, env.renderString(header_tmpl, idl_fragments.interfaces[0])),
file.write(cpp_file_path, env.renderString(cpp_tmpl, idl_fragments.interfaces[0]))
]);
}

Expand Down

0 comments on commit a1117b5

Please sign in to comment.