Skip to content
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
6 changes: 6 additions & 0 deletions .astylerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--style=linux
--indent=spaces=2
--attach-namespaces
--attach-classes
--attach-inlines
--attach-extern-c
36 changes: 34 additions & 2 deletions generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ const file = require("./util/file");
const idefs = require("./idefs");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const js_beautify = require('js-beautify').js_beautify;
const beautify = function (input) {
return js_beautify(input, {
"brace_style": "end-expand",
"max_preserve_newlines": 2,
"preserve_newlines": true,
"indent_size": 2,
"indent_char": " "
});
}


var exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});

// Customize the delimiters so as to not process `{{{` or `}}}`.
combyne.settings.delimiters = {
Expand Down Expand Up @@ -83,7 +98,7 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() {
return fse.copy(path.resolve(__dirname, "./manual/"), path.resolve(__dirname, "../"));
}).then(function() {
// Write out single purpose templates.
file.write("../binding.gyp", templates.binding.render(enabled));
file.write("../binding.gyp", beautify(templates.binding.render(enabled)));
file.write("../src/nodegit.cc", templates.nodegit.render(enabled));


Expand All @@ -106,5 +121,22 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() {
}
});

file.write("../lib/enums.js", templates.enums.render(enabled));

file.write("../lib/enums.js", beautify(templates.enums.render(enabled)));
}).then(function() {
return exec('command -v astyle').then(function(astyle) {
if (astyle) {
return exec(
'astyle --options=\".astylerc\" '
+ path.resolve(__dirname, "../src") + "/*.cc "
+ path.resolve(__dirname, "../include") + "/*.h"
).then(function() {
return exec(
'rm '
+ path.resolve(__dirname, "../src") + "/*.cc.orig "
+ path.resolve(__dirname, "../include") + "/*.h.orig "
);
});
}
})
});
141 changes: 70 additions & 71 deletions generate/partials/async_function.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

{%partial doc .%}
{% partial doc . %}
NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
NanScope();
{%partial guardArguments .%}
{% partial guardArguments . %}

if (args.Length() == {{args|jsArgsCount}} || !args[{{args|jsArgsCount}}]->IsFunction()) {
return NanThrowError("Callback is required and must be a Function.");
}
Expand All @@ -12,87 +13,85 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
baton->error_code = GIT_OK;
baton->error = NULL;

{%each args|argsInfo as arg %}
{%if not arg.isReturn %}
{%if arg.isSelf %}
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
{%elsif arg.name %}
{%partial convertFromV8 arg%}
{%if not arg.isPayload %}
baton->{{ arg.name }} = from_{{ arg.name }};
{%endif%}
{%endif%}
{%elsif arg.shouldAlloc %}
baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }}));
{%endif%}
{%endeach%}
{% each args|argsInfo as arg %}
{% if not arg.isReturn %}
{% if arg.isSelf %}
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
{% elsif arg.name %}
{% partial convertFromV8 arg %}
{% if not arg.isPayload %}
baton->{{ arg.name }} = from_{{ arg.name }};
{% endif %}
{% endif %}
{% elsif arg.shouldAlloc %}
baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }}));
{% endif %}
{% endeach %}

NanCallback *callback = new NanCallback(Local<Function>::Cast(args[{{args|jsArgsCount}}]));
{{ cppFunctionName }}Worker *worker = new {{ cppFunctionName }}Worker(baton, callback);
{%each args|argsInfo as arg %}
{%if not arg.isReturn %}
{%if arg.isSelf %}
{% each args|argsInfo as arg %}
{% if not arg.isReturn %}
{% if arg.isSelf %}
worker->SaveToPersistent("{{ arg.name }}", args.This());
{%else%}
{% else %}
if (!args[{{ arg.jsArg }}]->IsUndefined() && !args[{{ arg.jsArg }}]->IsNull())
worker->SaveToPersistent("{{ arg.name }}", args[{{ arg.jsArg }}]->ToObject());
{%endif%}
{%endif%}
{%endeach%}
{% endif %}
{% endif %}
{% endeach %}

NanAsyncQueueWorker(worker);
NanReturnUndefined();
}

// startexecute {{ cppFunctionName }}
void {{ cppClassName }}::{{ cppFunctionName }}Worker::Execute() {
{%if .|hasReturnType %}
{{ return.cType }} result = {{ cFunctionName }}(
{%else%}
{{ cFunctionName }}(
{%endif%}
{%-- Insert Function Arguments --%}
{%each args|argsInfo as arg %}
{%-- turn the pointer into a ref --%}
{%if arg.isReturn|and arg.cType|isDoublePointer %}&{%endif%}baton->{{ arg.name }}{%if not arg.lastArg %},{%endif%}

{%endeach%}
);

{%if return.isErrorCode %}
baton->error_code = result;

if (result != GIT_OK && giterr_last() != NULL) {
baton->error = git_error_dup(giterr_last());
}

{%elsif not return.cType == 'void' %}

baton->result = result;

{%endif%}
{% if .|hasReturnType %}
{{ return.cType }} result = {{ cFunctionName }}
{% else %}
{{ cFunctionName }}
{% endif %}
(

{% each .args|argsInfo as arg %}
{% if arg.isReturn|and arg.cType|isDoublePointer %}&{% endif %}baton->{{ arg.name }}{% if not arg.lastArg %},{% endif %}
{% endeach %}
);

{% if return.isErrorCode %}
baton->error_code = result;

if (result != GIT_OK && giterr_last() != NULL) {
baton->error = git_error_dup(giterr_last());
}
{% elsif not return.cType == 'void' %}
baton->result = result;
{% endif %}
}
// done

void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
TryCatch try_catch;

if (baton->error_code == GIT_OK) {
{%if not .|returnsCount %}
{% if not .|returnsCount %}
Handle<Value> result = NanUndefined();
{%else%}
{% else %}
Handle<Value> to;
{%if .|returnsCount > 1 %}
{% if .|returnsCount > 1 %}
Handle<Object> result = NanNew<Object>();
{%endif%}
{%each .|returnsInfo 0 1 as _return %}
{%partial convertToV8 _return %}
{%if .|returnsCount > 1 %}
{% endif %}
{% each .|returnsInfo 0 1 as _return %}
{% partial convertToV8 _return %}
{% if .|returnsCount > 1 %}
result->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
{% endif %}
{% endeach %}
{% if .|returnsCount == 1 %}
Handle<Value> result = to;
{%endif%}
{%endif%}
{% endif %}
{% endif %}
Handle<Value> argv[2] = {
NanNull(),
result
Expand All @@ -111,26 +110,26 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
callback->Call(0, NULL);
}

{%each args as arg %}
{%if arg.shouldAlloc %}
{% each args as arg %}
{% if arg.shouldAlloc %}
free((void*)baton->{{ arg.name }});
{%endif%}
{%endeach%}
{% endif %}
{% endeach %}
}

if (try_catch.HasCaught()) {
node::FatalException(try_catch);
}

{%each args|argsInfo as arg %}
{%if arg.isCppClassStringOrArray %}
{%if arg.freeFunctionName %}
{% each args|argsInfo as arg %}
{% if arg.isCppClassStringOrArray %}
{% if arg.freeFunctionName %}
{{ arg.freeFunctionName }}(baton->{{ arg.name }});
{%else%}
{% else %}
free((void *)baton->{{ arg.name }});
{%endif%}
{%endif%}
{%endeach%}
{% endif %}
{% endif %}
{% endeach %}

delete baton;
}
100 changes: 51 additions & 49 deletions generate/partials/convert_from_v8.cc
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
{%if not isPayload %}
{% if not isPayload %}
{{ cType }} from_{{ name }};
{%if isOptional %}

if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) {
{%endif%}
{%if cppClassName == 'String'%}

String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
{%elsif cppClassName == 'Wrapper'%}

String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
{%elsif cppClassName == 'Array'%}

Array *tmp_{{ name }} = Array::Cast(*args[{{ jsArg }}]);
from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }}));
for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) {
{%--
// FIXME: should recursively call convertFromv8.
--%}
{% if isOptional %}
if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) {
{% endif %}

{% if cppClassName == 'String' %}

String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});

{% elsif cppClassName == 'Wrapper' %}

String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});

{% elsif cppClassName == 'Array' %}

Array *tmp_{{ name }} = Array::Cast(*args[{{ jsArg }}]);
from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }}));
for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) {

{%-- FIXME: should recursively call convertFromv8. --%}
from_{{ name }}[i] = ObjectWrap::Unwrap<{{ arrayElementCppClassName }}>(tmp_{{ name }}->Get(NanNew<Number>(static_cast<double>(i)))->ToObject())->GetValue();
}
{%elsif cppClassName == 'Function'%}
{%elsif cppClassName == 'Buffer'%}

from_{{ name }} = Buffer::Data(args[{{ jsArg }}]->ToObject());
{%elsif cppClassName|isV8Value %}

{%if cType|isPointer %}
*from_{{ name }} = ({{ cType|unPointer }}) {{ cast }} {%if isEnum %}(int){%endif%} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
{%else%}
from_{{ name }} = ({{ cType }}) {{ cast }} {%if isEnum %}(int){%endif%} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
{%endif%}
{%else%}
{%if cType|isDoublePointer %}
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetRefValue();
{%else%}
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetValue();
{%endif%}
{%endif%}

{%if isOptional %}
}
else {
from_{{ name }} = 0;
}

{%endif%}
{%endif%}
}
{% elsif cppClassName == 'Function' %}

{% elsif cppClassName == 'Buffer' %}

from_{{ name }} = Buffer::Data(args[{{ jsArg }}]->ToObject());

{% elsif cppClassName|isV8Value %}
{% if cType|isPointer %}
*from_{{ name }} = ({{ cType|unPointer }}) {{ cast }} {% if isEnum %}(int){% endif %} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
{% else %}
from_{{ name }} = ({{ cType }}) {{ cast }} {% if isEnum %}(int){% endif %} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
{% endif %}
{% else %}
{% if cType|isDoublePointer %}
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetRefValue();
{% else %}
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetValue();
{% endif %}
{% endif %}

{% if isOptional %}
}
else {
from_{{ name }} = 0;
}

{% endif %}
{% endif %}
Loading