Skip to content

Commit

Permalink
Split core codes into detailed steps(parser, constructor, generator)
Browse files Browse the repository at this point in the history
This change splits core codes into detailed steps in high-level.
  - parser: The parser module is responsible for webidl parsing using
    the webidl2 parser internally. In this step, should create a unique
    type map(key: definition type name, value: AST) as an output.
  - constructor: The constructor module is responsible for constructing
    definition object to generate binding code in generate module.
  - generator: The generator module is responsible for generating actual
    native binding codes.

ISSUE=#207
  • Loading branch information
romandev committed Jan 11, 2018
1 parent 1352e61 commit 21edc13
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 24 deletions.
22 changes: 22 additions & 0 deletions core/constructor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2017 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as types from 'core/types';

export async function construct(typeMap: types.IDLTypeMap) {
// Not implemented yet
return [];
}
21 changes: 21 additions & 0 deletions core/generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2017 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as types from 'core/types';

export async function build(definitions: types.IRDefinition[]) {
// Not implemented yet
}
28 changes: 8 additions & 20 deletions core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,16 @@
* limitations under the License.
*/

import {IDLTypeMap} from 'core/parser/idl_type_map';
import {DefinitionInfo} from 'core/parser/idl_types';
import {Parser} from 'core/parser/parser';
import * as file from 'generator/base/file';

async function readAndParse(idlFilePath: string): Promise<void> {
const idlFragment: string = await file.read(idlFilePath);
const idlDefinitionInfos: DefinitionInfo[] = await Parser.parse(idlFragment);
IDLTypeMap.update(idlDefinitionInfos);
}

async function buildIDLTypeMap(idlFilePaths: string[]): Promise<void> {
const tasks: Promise<void>[] = [];
idlFilePaths.forEach((idlFilePath) => {
tasks.push(readAndParse(idlFilePath));
});

await Promise.all(tasks);
}
import * as constructor from 'core/constructor';
import * as generator from 'core/generator';
import * as parser from 'core/parser';
import * as types from 'core/types';

export async function run(idlFilePaths: string[]): Promise<number> {
await buildIDLTypeMap(idlFilePaths);
const typeMap: types.IDLTypeMap = await parser.parse(idlFilePaths);
const definitions: types.IRDefinition[] =
await constructor.construct(typeMap);
await generator.build(definitions);

return 0;
}
22 changes: 22 additions & 0 deletions core/parser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2018 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {Parser} from 'core/parser/parser';
import * as types from 'core/types';

export async function parse(idlFilePaths: string[]): Promise<types.IDLTypeMap> {
return Parser.parse(idlFilePaths);
}
24 changes: 21 additions & 3 deletions core/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,32 @@
* limitations under the License.
*/

import {DefinitionInfo} from 'core/parser/idl_types';
import * as types from 'core/types';
import * as file from 'generator/base/file';
import * as webidl from 'webidl2';

async function readAndParse(idlFilePath: string): Promise<void> {
const idlFragment: string = await file.read(idlFilePath);
const idlDefinitionInfos: types.DefinitionInfo[] = webidl.parse(idlFragment);
types.IDLTypeMap.update(idlDefinitionInfos);
}

async function buildIDLTypeMap(idlFilePaths: string[]): Promise<void> {
const tasks: Promise<void>[] = [];
idlFilePaths.forEach((idlFilePath) => {
tasks.push(readAndParse(idlFilePath));
});

await Promise.all(tasks);
}

/**
* WebIDL Parser
*/
export class Parser {
public static async parse(idlFragment: string): Promise<DefinitionInfo[]> {
return webidl.parse(idlFragment);
public static async parse(idlFilePaths: string[]): Promise<types.IDLTypeMap> {
await buildIDLTypeMap(idlFilePaths);

return types.IDLTypeMap;
}
}
2 changes: 1 addition & 1 deletion core/parser/idl_type_map.ts → core/types/idl_type_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {
DefinitionInfo, DictionaryInfo, EnumInfo, InterfaceInfo
} from 'core/parser/idl_types';
} from 'core/types/idl_types';

interface DefinitionInfoStore {
[index: string]: DefinitionInfo;
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions core/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2018 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export {IDLTypeMap} from 'core/types/idl_type_map';
export {DefinitionInfo} from 'core/types/idl_types';
export {IRDefinition} from 'core/types/ir_definition';
18 changes: 18 additions & 0 deletions core/types/ir_definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2018 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class IRDefinition {
}

0 comments on commit 21edc13

Please sign in to comment.