diff --git a/core/constructor/index.ts b/core/constructor/index.ts new file mode 100644 index 0000000..f5d3b32 --- /dev/null +++ b/core/constructor/index.ts @@ -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 * as types from 'core/types'; + +export async function construct(typeMap: types.IDLTypeMap) { + // Not implemented yet + return []; +} diff --git a/core/generator/index.ts b/core/generator/index.ts new file mode 100644 index 0000000..e40433c --- /dev/null +++ b/core/generator/index.ts @@ -0,0 +1,21 @@ +/** + * 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 * as types from 'core/types'; + +export async function build(definitions: types.IRDefinition[]): Promise { + // Not implemented yet +} diff --git a/core/index.ts b/core/index.ts index 844f465..b19aa77 100644 --- a/core/index.ts +++ b/core/index.ts @@ -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 { - const idlFragment: string = await file.read(idlFilePath); - const idlDefinitionInfos: DefinitionInfo[] = await Parser.parse(idlFragment); - IDLTypeMap.update(idlDefinitionInfos); -} - -async function buildIDLTypeMap(idlFilePaths: string[]): Promise { - const tasks: Promise[] = []; - 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 { - 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; } diff --git a/core/parser/index.ts b/core/parser/index.ts new file mode 100644 index 0000000..dda9819 --- /dev/null +++ b/core/parser/index.ts @@ -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 { + return Parser.parse(idlFilePaths); +} diff --git a/core/parser/parser.ts b/core/parser/parser.ts index 2c20127..41794c8 100644 --- a/core/parser/parser.ts +++ b/core/parser/parser.ts @@ -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 { + const idlFragment: string = await file.read(idlFilePath); + const idlDefinitionInfos: types.DefinitionInfo[] = webidl.parse(idlFragment); + types.IDLTypeMap.update(idlDefinitionInfos); +} + +async function buildIDLTypeMap(idlFilePaths: string[]): Promise { + const tasks: Promise[] = []; + idlFilePaths.forEach((idlFilePath) => { + tasks.push(readAndParse(idlFilePath)); + }); + + await Promise.all(tasks); +} + /** * WebIDL Parser */ export class Parser { - public static async parse(idlFragment: string): Promise { - return webidl.parse(idlFragment); + public static async parse(idlFilePaths: string[]): Promise { + await buildIDLTypeMap(idlFilePaths); + + return types.IDLTypeMap; } } diff --git a/core/parser/idl_type_map.ts b/core/types/idl_type_map.ts similarity index 98% rename from core/parser/idl_type_map.ts rename to core/types/idl_type_map.ts index f2b5960..3698dfc 100644 --- a/core/parser/idl_type_map.ts +++ b/core/types/idl_type_map.ts @@ -16,7 +16,7 @@ import { DefinitionInfo, DictionaryInfo, EnumInfo, InterfaceInfo - } from 'core/parser/idl_types'; + } from 'core/types/idl_types'; interface DefinitionInfoStore { [index: string]: DefinitionInfo; diff --git a/core/parser/idl_types.ts b/core/types/idl_types.ts similarity index 100% rename from core/parser/idl_types.ts rename to core/types/idl_types.ts diff --git a/core/types/index.ts b/core/types/index.ts new file mode 100644 index 0000000..660d56f --- /dev/null +++ b/core/types/index.ts @@ -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'; diff --git a/core/types/ir_definition.ts b/core/types/ir_definition.ts new file mode 100644 index 0000000..c7e5c91 --- /dev/null +++ b/core/types/ir_definition.ts @@ -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 { +}