Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split core codes into detailed steps(parser, constructor, generator) #229

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) 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 [];
}
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) 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<void> {
// 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;
}
}
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 {
}