зеркало из https://github.com/mono/CppSharp.git
Add WebIDL generator.
This commit is contained in:
Родитель
c515fce422
Коммит
d8af3f93ae
|
@ -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 @@
|
|||
Subproject commit daf12d17074402551f6e1f65d65a8cf7be2e7b9b
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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 @@
|
|||
Subproject commit 5c315e92969ea106c6f03474d4b8e3b2bfbff9bf
|
|
@ -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==
|
Загрузка…
Ссылка в новой задаче