Skip to content

Commit

Permalink
Add a logic to process interface and partial interface
Browse files Browse the repository at this point in the history
After this patch, `DefinitionInfoMap` can process `interface` and
`partial interface`. Other definitions will be ignored for now.

ISSUE=#207
  • Loading branch information
romandev committed Dec 20, 2017
1 parent 122c7ca commit aa3cab4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
38 changes: 36 additions & 2 deletions generator/new_parser/definition_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@
* limitations under the License.
*/

export interface DefinitionInfo {
name: string;
export interface TypeInfo {
readonly sequence: boolean;
readonly generic?: string;
readonly idlType: string;
readonly nullable: boolean;
readonly union: boolean;
}

export interface ArgumentInfo {
readonly optional: boolean;
readonly variadic: boolean;
readonly idlType: TypeInfo;
readonly name: string;
}

export interface InterfaceInfo {
readonly type: 'interface';
readonly name: string;
partial: boolean;
members: InterfaceMemberInfo[];
inheritance: string;
}

export interface OperationMemberInfo {
readonly type: 'operation';
readonly getter: boolean;
readonly setter: boolean;
readonly deleter: boolean;
readonly static: boolean;
readonly stringifier: boolean;
readonly idlType: TypeInfo;
readonly name: string;
readonly arguments: ArgumentInfo[];
}

export type InterfaceMemberInfo = OperationMemeberInfo;
export type DefinitionInfo = InterfaceInfo;
30 changes: 27 additions & 3 deletions generator/new_parser/definition_info_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,45 @@
* limitations under the License.
*/

import {DefinitionInfo} from 'generator/new_parser/definition_info';
import {DefinitionInfo, InterfaceInfo} from 'generator/new_parser/definition_info';

interface DefinitionInfoStore {
[index: string]: DefinitionInfo;
}

const store: DefinitionInfoStore = {};

function updateInterfaceInfo(info: InterfaceInfo): void {
const storedInfo = store[info.name];

if (storedInfo === undefined) {
store[info.name] = info;
return;
}

if (storedInfo.type !== info.type) {
throw new SyntaxError('IDL defintions are duplicated');
}

// In this case, one of thing is partial interface. So, we should merge them.
storedInfo.partial = false;
storedInfo.inheritance = storedInfo.inheritance || info.inheritance;
storedInfo.members = storedInfo.members.concat(info.members);
}

function updateDefinitionInfo(info: DefinitionInfo): void {
switch (info.type) {
case 'interface': updateInterfaceInfo(info as InterfaceInfo);
}
}

/**
* Raw definition information mapping table (exposed to global scope)
*/
export class DefinitionInfoMap {
public static update(definitionInfos: DefinitionInfo[]): void {
definitionInfos.forEach((definitionInfo: DefinitionInfo) => {
store[definitionInfo.name] = definitionInfo;
definitionInfos.forEach((info: DefinitionInfo) => {
updateDefinitionInfo(info);
});
}

Expand Down

0 comments on commit aa3cab4

Please sign in to comment.