-
Notifications
You must be signed in to change notification settings - Fork 17
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
generate enum type traits automatically. #124
Conversation
We are using Apache License Version 2.0.
From now, we can use |bacardi| command in three major platforms.
This change includes the following things: - Use node-gyp to build Native codes. - Add examples directory to put .cc files. - Add some guides to build.
Introduce build automation for Linux platform.
After this patch, we can build and test napi-modules simply.
The file has a list of all contributors for Bacardi.
Add CODEOWNERS file to define teams are responsible for code in a repo.
After this patch, to automatically format a pending patch according to our coding style, from the command line, simply run: ./bacardi format.
We should use bootstrap node command instead of global node command. If not so, it might not work well. (e.g. not support n-api)
After this patch, generator/generator.js can take idl files that defined in binding.gyp.
Delete hard-coded value and pass aguments to process. ISSUE=lunchclass#4
The comparing value was wrong. So after formatting, test doesn't work. We fixed the checking value. ISSUE=none
Update README.md and .travis.yml in order to support for Mac OSX. ISSUE=none
this Assert module[1] is a default module of node.js. so it does not need to additional install. [1] https://nodejs.org/api/assert.html ISSUE=none
We added sub, mul, div function to test bacardi project. Then we will modularization them with next patch. ISSUE=lunchclass#10
Upgrade nodejs from v8.2.1 to v8.4.0. In the latest version, napi_create_number was deprecated. We should use napi_create_double instead[1]. Also, napi_type_error's signature was changed[2]; [1] https://nodejs.org/api/n-api.html#n_api_napi_create_double [2] https://nodejs.org/api/n-api.html#n_api_napi_throw_type_error ISSUE=lunchclass#18
It's better to use TypeScript instead of JS with node. ISSUE=lunchclass#14
This change adds WebIDL parser and then implement a simple code generator. It can not generate actual codes but it shows how code generator works. (It will print a simple C++ class that maps with IDL file.) ISSUE=lunchclass#22
This change is introducing Nunjucks template engine that is essentially a port of python jinja2. So, replaces existing simple output with rendered output by Nunjucks with template file. ISSUE=lunchclass#22
There's an error that cannot found example.tpl file during build. I modified example.tpl to example.njk.
After this patch, we can use relative path from bacardi root directory. ISSUE=none
This change is implementing an initial codes for NativeTypeTraits to convert JS value to Native value easier. After this patch, we can use NativeTypeTraits instead of individual converting in example codes. ISSUE=lunchclass#29
Mocha is a simple, flexible, fun JavaScript test framework for node.js and the browser. ISSUE=none
Even although build is failed in travis bot, test is succeded sometimes. So, we add a new clean command and then use it in travis script. ISSUE=none
package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. so sometimes it might be made to bother when use git command. ISSUE=none
The Init() function is used to expose Native interfaces to JS layer. So, the function should be separated from specific example codes(e.g. calculator). ISSUE=none
In the current calculator example, all static operations don't belong to any class. It's a little bit weird because another example can be define in the same scope. So, this change defines a new Calculator class in JS side and then move all static methods into bacardi.Calculator namespace. ISSUE=none
This change includes the following things: - Travis bot badge to display latest bot status for Linux and Mac. - How to test. - Coding style and how to format source codes automatically. ISSUE=none
The package contains header-only C++ wrapper classes for the N-API, along with library code that enables backward-compatibility with use with older versions of Node.js that do not have N-API built-in. ISSUE=none
We need to implement overloading feature. First I implement constructor overloading with just argument count. Next, we should check argument type also. ISSUE=lunchclass#79
We already have ./bacardi format command to format our source code automatically. But it works only when the change is in stage. For example, if someone already commits some changes locally, there is no opportunity to format the source code. So, this patch increases the range of applying format. (HEAD~20) Also, this patch is fixing some format errors. ISSUE=none
lunchclass#112) This is removing hard-coded value(examples/) in generateInterface() in generator/main.ts. This is also resolving a problem that the CWD path is differnt in Windows during generating. ISSUE=lunchclass#101
This patch is adding a new test IDL interface to test/ directory. After this patch, we can build a multiple IDL files and use them. ISSUE=lunchclass#99,lunchclass#100 TBR=@hwanseung,@yjaeseok
We are already using Mocha as testing framework but for some reasons such as readability and convenience, we decided to use jest instead of Mocha. After this patch, ./bacardi test will run both of Mocha and jest. Once we write test codes enough in jest, we will deprecate Mocha. ISSUE=lunchclass#99,lunchclass#100 TBR=@hwanseung,@yjaeseok
In the bridge classes, we should keep the instance of impl class. ISSUE=none
Rewrite examples/ tests using jest. ISSUE=lunchclass#99,lunchclass#100
This patch also changes getCalledConstructorInfo() to static method and rename it with getLastCallInfo() and then use it use generally. ISSUE=lunchclass#99,lunchclass#100
Need more tests. ISSUE=lunchclass#99,lunchclass#100
Write a test for Basic Types such as boolean, short, double, and string. Not include long type testing in this patch because it has some problem. We should fix the issue in follow-up patch. ISSUE=lunchclass#99,lunchclass#100
Implement IDL enum feature. Some part of codes should be generated automatically at another files but this patch doesn't do that yet. So, it will be finished in follow-up patch. ISSUE=lunchclass#80
It's better to inform details. ISSUE=lunchclass#99,lunchclass#100
Write a test for enum type using jest. ISSUE=lunchclass#99,lunchclass#100
Generate JSTypeTraits by macro functions In the future, we can auto-generate js_type_traits during bacardi build time by using some information of types with template. e.g types = { 'Number': { int32_t, int64_t, float, long . . }, 'String': { char*, std::string, . } } And this is the just pseudo code for concept. if type in types['Number']: generate("JS_TYPE_TRAITS_NUMBER("+type+")"); if type in types['String']: generate("JS_TYPE_TRAITS_STRING("+type+")"); ISSUE=lunchclass#120
This patch includes the following things. - Add electron and electron-rebuild - Patch file to disable using internal N-API in node-addon-api. - Electron example - Electron build scripts. After this patch, we can build the example and then run as follows: $ ./bacardi build_electron $ ./bacardi electron ISSUE=lunchclass#129
Usually programmers used to count from zero when counting index. But loop.index count from 1. so we have to minus 1 to make 0. Actually Nunjunks provide loop.index0 which count from 0. https://mozilla.github.io/nunjucks/templating.html#for ISSUE=none
template/native_enum_type_traits.njk
Outdated
|
||
{% for enum in enums %} | ||
template <> | ||
struct NativeTypeTraits<IDL{{enum.name}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, the enum type can be just unique enum type(because it's just string) and there is no reason to be NativeTypeTraits.
This generating code will generate C++ code per one enum type. It generates too much codes and can make build time increased.
We should check whether the type is enum or not in generator first.
And then, we make other logics fixed and just generate enumuration strings by generator.
For examples,
// This is not actual code, so, I ignores convention and grammar in my convenience.
{% if type == 'enum' %}
const char* validEnums = [
{% for each enum strings %}
{%e enum_string %}
{% endfor %}
];
if (!IsValidEnum(validEnums, inputEnum)) return;
{% else %}
// Previsous codes
{% endif %}
template/native_enum_type_traits.njk
Outdated
return js_value.ToString().Utf8Value(); | ||
} | ||
|
||
static bool IsTypeEquals(const Napi::Value& js_value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an another problem. IsTypeEquals() is used for method overloading check, right?
If developers defines two enums and then two method overloading for each enums, unexpected behavior might occur.
enum A {
...
};
enum B {
...
};
void method(A a);
void method(B b);
In WebIDL level, they seems to have different signature but the enum is just string in JS level. So, they can not be method-overloaded. So, it's a reason that we should not generate this file repeatedly.
There is no repository and license field in package.json files. For this reason we get some warnings when build bacardi project. npm WARN bacardi No repository field. npm WARN bacardi No license field. So I add repository and license information in package.json file. "license": "Apache-2.0", "repository": { "type": "git", "url": "https://github.com/lunchclass/bacardi" } ISSUE=none
Modified the comment "build_electrona" as "build_electron". ISSUE=none
Previous PR lunchclass#131 has some error. repository url must include ".git". I refer to gulp-typescript github page ISSUE=none
Original Repository: - https://github.com/roukaour/simrank ISSUE=lunchclass#129
This change is a good example of how we can easily bind Native code to JS side if using Bacardi. ISSUE=lunchclass#129
33d398a
to
1f60422
Compare
@hwanseung Hi Hwanseung, did you come back? If you have a spare time, please re-upload this patch in new PR. (Open PRs were broken due to my mistakes.. :( ) |
generate enum type traits automatically.
ISSUE=#80