mirror of https://github.com/mono/CppSharp.git
11 changed files with 10424 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||||
|
<PropertyGroup> |
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget> |
||||||
|
<OutputType>Exe</OutputType> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\AST\CppSharp.AST.csproj" /> |
||||||
|
</ItemGroup> |
||||||
|
</Project> |
@ -0,0 +1,106 @@ |
|||||||
|
using System; |
||||||
|
using CppSharp.AST; |
||||||
|
using WebIdlCSharp; |
||||||
|
|
||||||
|
namespace CppSharp.WebIDL |
||||||
|
{ |
||||||
|
public class WebIDLGenerator |
||||||
|
{ |
||||||
|
public static Declaration ConvertWebIDLMemberNode(WebIdlMemberDefinition type) |
||||||
|
{ |
||||||
|
switch (type.Type) |
||||||
|
{ |
||||||
|
case "attribute": |
||||||
|
{ |
||||||
|
var prop = new Property(); |
||||||
|
return prop; |
||||||
|
} |
||||||
|
case "constructor": |
||||||
|
{ |
||||||
|
var ctor = new Method {Kind = CXXMethodKind.Constructor}; |
||||||
|
return ctor; |
||||||
|
} |
||||||
|
case "operation": |
||||||
|
{ |
||||||
|
var method = new Method {Kind = CXXMethodKind.Normal}; |
||||||
|
return method; |
||||||
|
} |
||||||
|
case "const": |
||||||
|
{ |
||||||
|
var @const = new Variable(); |
||||||
|
return @const; |
||||||
|
} |
||||||
|
case "iterable": |
||||||
|
{ |
||||||
|
var @const = new Variable(); |
||||||
|
return @const; |
||||||
|
} |
||||||
|
default: |
||||||
|
throw new Exception($"Unknown member type definition: {type.Type}"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static Declaration ConvertWebIDLNode(WebIdlTypeDefinition type) |
||||||
|
{ |
||||||
|
Declaration decl; |
||||||
|
|
||||||
|
switch (type.Type) |
||||||
|
{ |
||||||
|
case "enum": |
||||||
|
{ |
||||||
|
decl = new Enumeration(); |
||||||
|
break; |
||||||
|
} |
||||||
|
case "interface": |
||||||
|
{ |
||||||
|
decl = new Class(); |
||||||
|
foreach (var member in type.Members) |
||||||
|
ConvertWebIDLMemberNode(member); |
||||||
|
break; |
||||||
|
} |
||||||
|
case "dictionary": |
||||||
|
{ |
||||||
|
decl = new Class(); |
||||||
|
break; |
||||||
|
} |
||||||
|
case "callback": |
||||||
|
{ |
||||||
|
decl = new Class(); |
||||||
|
break; |
||||||
|
} |
||||||
|
case "callback interface": |
||||||
|
{ |
||||||
|
decl = new Class(); |
||||||
|
break; |
||||||
|
} |
||||||
|
case "interface mixin": |
||||||
|
{ |
||||||
|
decl = new Class(); |
||||||
|
break; |
||||||
|
} |
||||||
|
case "includes": |
||||||
|
{ |
||||||
|
decl = new Class(); |
||||||
|
break; |
||||||
|
} |
||||||
|
default: |
||||||
|
throw new Exception($"Unknown type definition: {type.Type}"); |
||||||
|
} |
||||||
|
|
||||||
|
return decl; |
||||||
|
} |
||||||
|
|
||||||
|
public static void Main(string[] args) |
||||||
|
{ |
||||||
|
var domPath = "/home/joao/dev/CppSharp/tests2/webidl/dom.json"; |
||||||
|
var types = WebIdlParser.LoadTypesFromFile(domPath); |
||||||
|
|
||||||
|
var translationUnit = new TranslationUnit(); |
||||||
|
|
||||||
|
foreach (var type in types) |
||||||
|
{ |
||||||
|
var decl = ConvertWebIDLNode(type); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
SetupExternalManagedProject("CppSharp.WebIDL") |
@ -0,0 +1,13 @@ |
|||||||
|
{ |
||||||
|
"name": "webidl-json", |
||||||
|
"version": "1.0.0", |
||||||
|
"lockfileVersion": 1, |
||||||
|
"requires": true, |
||||||
|
"dependencies": { |
||||||
|
"webidl2": { |
||||||
|
"version": "23.13.0", |
||||||
|
"resolved": "https://registry.npmjs.org/webidl2/-/webidl2-23.13.0.tgz", |
||||||
|
"integrity": "sha512-YfBvnpujLVLZ1zKP/aZO1XOtFhMUMFSnXjp88Q4iTMC/i1MUiv7YWq45SN8DrPHCjmnXhzjBouG0tJKg/+o0lg==" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
{ |
||||||
|
"name": "webidl-json", |
||||||
|
"version": "1.0.0", |
||||||
|
"main": "index.js", |
||||||
|
"type": "module", |
||||||
|
"scripts": { |
||||||
|
"test": "echo \"Error: no test specified\" && exit 1" |
||||||
|
}, |
||||||
|
"author": "", |
||||||
|
"license": "ISC", |
||||||
|
"dependencies": { |
||||||
|
"webidl2": "^23.13.0" |
||||||
|
}, |
||||||
|
"devDependencies": {}, |
||||||
|
"description": "" |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
import * as fs from "fs"; |
||||||
|
import webidl2 from "webidl2"; |
||||||
|
|
||||||
|
const fileName = "/home/joao/dev/CppSharp/tests2/webidl/wpt/interfaces/dom.idl" |
||||||
|
const outputFileName = "dom.json" |
||||||
|
|
||||||
|
const content = fs.readFileSync(fileName); |
||||||
|
const parsingStructure = webidl2.parse(content.toString()); |
||||||
|
fs.writeFileSync(outputFileName, JSON.stringify(parsingStructure, null, 2)); |
@ -0,0 +1,8 @@ |
|||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
||||||
|
# yarn lockfile v1 |
||||||
|
|
||||||
|
|
||||||
|
webidl2@^23.13.0: |
||||||
|
version "23.13.0" |
||||||
|
resolved "https://registry.yarnpkg.com/webidl2/-/webidl2-23.13.0.tgz#1f3766e52429a129d407867dd43ad2c9e6fa9040" |
||||||
|
integrity sha512-YfBvnpujLVLZ1zKP/aZO1XOtFhMUMFSnXjp88Q4iTMC/i1MUiv7YWq45SN8DrPHCjmnXhzjBouG0tJKg/+o0lg== |
Loading…
Reference in new issue