FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #295 from nodegit/astyle · javascript-forks/nodegit.nodegit@483151c · GitHub

Repository navigation

Commit 483151c

Browse files
committed
Merge pull request nodegit#295 from nodegit/astyle
Styling
2 parents fb52c7e + 3166ea9 commit 483151c

18 files changed

Lines changed: 828 additions & 761 deletions

‎.astylerc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--style=linux
2+
--indent=spaces=2
3+
--attach-namespaces
4+
--attach-classes
5+
--attach-inlines
6+
--attach-extern-c

‎generate/index.js‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ const file = require("./util/file");
44
const idefs = require("./idefs");
55
const promisify = require("promisify-node");
66
const fse = promisify(require("fs-extra"));
7+
const js_beautify = require('js-beautify').js_beautify;
8+
const beautify = function (input) {
9+
return js_beautify(input, {
10+
"brace_style": "end-expand",
11+
"max_preserve_newlines": 2,
12+
"preserve_newlines": true,
13+
"indent_size": 2,
14+
"indent_char": " "
15+
});
16+
}
17+
18+
19+
var exec = promisify(function(command, opts, callback) {
20+
return require("child_process").exec(command, opts, callback);
21+
});
722

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

89104

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

109-
file.write("../lib/enums.js", templates.enums.render(enabled));
124+
125+
file.write("../lib/enums.js", beautify(templates.enums.render(enabled)));
126+
}).then(function() {
127+
return exec('command -v astyle').then(function(astyle) {
128+
if (astyle) {
129+
return exec(
130+
'astyle --options=\".astylerc\" '
131+
+ path.resolve(__dirname, "../src") + "/*.cc "
132+
+ path.resolve(__dirname, "../include") + "/*.h"
133+
).then(function() {
134+
return exec(
135+
'rm '
136+
+ path.resolve(__dirname, "../src") + "/*.cc.orig "
137+
+ path.resolve(__dirname, "../include") + "/*.h.orig "
138+
);
139+
});
140+
}
141+
})
110142
});
Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2-
{%partial doc .%}
2+
{% partial doc . %}
33
NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
44
NanScope();
5-
{%partial guardArguments .%}
5+
{% partial guardArguments . %}
6+
67
if (args.Length() == {{args|jsArgsCount}} || !args[{{args|jsArgsCount}}]->IsFunction()) {
78
return NanThrowError("Callback is required and must be a Function.");
89
}
@@ -12,87 +13,85 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
1213
baton->error_code = GIT_OK;
1314
baton->error = NULL;
1415

15-
{%each args|argsInfo as arg %}
16-
{%if not arg.isReturn %}
17-
{%if arg.isSelf %}
18-
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
19-
{%elsif arg.name %}
20-
{%partial convertFromV8 arg%}
21-
{%if not arg.isPayload %}
22-
baton->{{ arg.name }} = from_{{ arg.name }};
23-
{%endif%}
24-
{%endif%}
25-
{%elsif arg.shouldAlloc %}
26-
baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }}));
27-
{%endif%}
28-
{%endeach%}
16+
{% each args|argsInfo as arg %}
17+
{% if not arg.isReturn %}
18+
{% if arg.isSelf %}
19+
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
20+
{% elsif arg.name %}
21+
{% partial convertFromV8 arg %}
22+
{% if not arg.isPayload %}
23+
baton->{{ arg.name }} = from_{{ arg.name }};
24+
{% endif %}
25+
{% endif %}
26+
{% elsif arg.shouldAlloc %}
27+
baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }}));
28+
{% endif %}
29+
{% endeach %}
2930

3031
NanCallback *callback = new NanCallback(Local<Function>::Cast(args[{{args|jsArgsCount}}]));
3132
{{ cppFunctionName }}Worker *worker = new {{ cppFunctionName }}Worker(baton, callback);
32-
{%each args|argsInfo as arg %}
33-
{%if not arg.isReturn %}
34-
{%if arg.isSelf %}
33+
{% each args|argsInfo as arg %}
34+
{% if not arg.isReturn %}
35+
{% if arg.isSelf %}
3536
worker->SaveToPersistent("{{ arg.name }}", args.This());
36-
{%else%}
37+
{% else %}
3738
if (!args[{{ arg.jsArg }}]->IsUndefined() && !args[{{ arg.jsArg }}]->IsNull())
3839
worker->SaveToPersistent("{{ arg.name }}", args[{{ arg.jsArg }}]->ToObject());
39-
{%endif%}
40-
{%endif%}
41-
{%endeach%}
40+
{% endif %}
41+
{% endif %}
42+
{% endeach %}
4243

4344
NanAsyncQueueWorker(worker);
4445
NanReturnUndefined();
4546
}
4647

48+
// startexecute {{ cppFunctionName }}
4749
void {{ cppClassName }}::{{ cppFunctionName }}Worker::Execute() {
48-
{%if .|hasReturnType %}
49-
{{ return.cType }} result = {{ cFunctionName }}(
50-
{%else%}
51-
{{ cFunctionName }}(
52-
{%endif%}
53-
{%-- Insert Function Arguments --%}
54-
{%each args|argsInfo as arg %}
55-
{%-- turn the pointer into a ref --%}
56-
{%if arg.isReturn|and arg.cType|isDoublePointer %}&{%endif%}baton->{{ arg.name }}{%if not arg.lastArg %},{%endif%}
57-
58-
{%endeach%}
59-
);
60-
61-
{%if return.isErrorCode %}
62-
baton->error_code = result;
63-
64-
if (result != GIT_OK && giterr_last() != NULL) {
65-
baton->error = git_error_dup(giterr_last());
66-
}
67-
68-
{%elsif not return.cType == 'void' %}
69-
70-
baton->result = result;
71-
72-
{%endif%}
50+
{% if .|hasReturnType %}
51+
{{ return.cType }} result = {{ cFunctionName }}
52+
{% else %}
53+
{{ cFunctionName }}
54+
{% endif %}
55+
(
56+
57+
{% each .args|argsInfo as arg %}
58+
{% if arg.isReturn|and arg.cType|isDoublePointer %}&{% endif %}baton->{{ arg.name }}{% if not arg.lastArg %},{% endif %}
59+
{% endeach %}
60+
);
61+
62+
{% if return.isErrorCode %}
63+
baton->error_code = result;
64+
65+
if (result != GIT_OK && giterr_last() != NULL) {
66+
baton->error = git_error_dup(giterr_last());
67+
}
68+
{% elsif not return.cType == 'void' %}
69+
baton->result = result;
70+
{% endif %}
7371
}
72+
// done
7473

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

7877
if (baton->error_code == GIT_OK) {
79-
{%if not .|returnsCount %}
78+
{% if not .|returnsCount %}
8079
Handle<Value> result = NanUndefined();
81-
{%else%}
80+
{% else %}
8281
Handle<Value> to;
83-
{%if .|returnsCount > 1 %}
82+
{% if .|returnsCount > 1 %}
8483
Handle<Object> result = NanNew<Object>();
85-
{%endif%}
86-
{%each .|returnsInfo 0 1 as _return %}
87-
{%partial convertToV8 _return %}
88-
{%if .|returnsCount > 1 %}
84+
{% endif %}
85+
{% each .|returnsInfo 0 1 as _return %}
86+
{% partial convertToV8 _return %}
87+
{% if .|returnsCount > 1 %}
8988
result->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
90-
{%endif%}
91-
{%endeach%}
92-
{%if .|returnsCount == 1 %}
89+
{% endif %}
90+
{% endeach %}
91+
{% if .|returnsCount == 1 %}
9392
Handle<Value> result = to;
94-
{%endif%}
95-
{%endif%}
93+
{% endif %}
94+
{% endif %}
9695
Handle<Value> argv[2] = {
9796
NanNull(),
9897
result
@@ -111,26 +110,26 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
111110
callback->Call(0, NULL);
112111
}
113112

114-
{%each args as arg %}
115-
{%if arg.shouldAlloc %}
113+
{% each args as arg %}
114+
{% if arg.shouldAlloc %}
116115
free((void*)baton->{{ arg.name }});
117-
{%endif%}
118-
{%endeach%}
116+
{% endif %}
117+
{% endeach %}
119118
}
120119

121120
if (try_catch.HasCaught()) {
122121
node::FatalException(try_catch);
123122
}
124123

125-
{%each args|argsInfo as arg %}
126-
{%if arg.isCppClassStringOrArray %}
127-
{%if arg.freeFunctionName %}
124+
{% each args|argsInfo as arg %}
125+
{% if arg.isCppClassStringOrArray %}
126+
{% if arg.freeFunctionName %}
128127
{{ arg.freeFunctionName }}(baton->{{ arg.name }});
129-
{%else%}
128+
{% else %}
130129
free((void *)baton->{{ arg.name }});
131-
{%endif%}
132-
{%endif%}
133-
{%endeach%}
130+
{% endif %}
131+
{% endif %}
132+
{% endeach %}
134133

135134
delete baton;
136135
}
Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
1-
{%if not isPayload %}
1+
{% if not isPayload %}
22
{{ cType }} from_{{ name }};
3-
{%if isOptional %}
4-
5-
if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) {
6-
{%endif%}
7-
{%if cppClassName == 'String'%}
8-
9-
String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
10-
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
11-
{%elsif cppClassName == 'Wrapper'%}
12-
13-
String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
14-
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
15-
{%elsif cppClassName == 'Array'%}
16-
17-
Array *tmp_{{ name }} = Array::Cast(*args[{{ jsArg }}]);
18-
from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }}));
19-
for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) {
20-
{%--
21-
// FIXME: should recursively call convertFromv8.
22-
--%}
3+
{% if isOptional %}
4+
if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) {
5+
{% endif %}
6+
7+
{% if cppClassName == 'String' %}
8+
9+
String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
10+
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
11+
12+
{% elsif cppClassName == 'Wrapper' %}
13+
14+
String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
15+
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
16+
17+
{% elsif cppClassName == 'Array' %}
18+
19+
Array *tmp_{{ name }} = Array::Cast(*args[{{ jsArg }}]);
20+
from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }}));
21+
for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) {
22+
23+
{%-- FIXME: should recursively call convertFromv8. --%}
2324
from_{{ name }}[i] = ObjectWrap::Unwrap<{{ arrayElementCppClassName }}>(tmp_{{ name }}->Get(NanNew<Number>(static_cast<double>(i)))->ToObject())->GetValue();
24-
}
25-
{%elsif cppClassName == 'Function'%}
26-
{%elsif cppClassName == 'Buffer'%}
27-
28-
from_{{ name }} = Buffer::Data(args[{{ jsArg }}]->ToObject());
29-
{%elsif cppClassName|isV8Value %}
30-
31-
{%if cType|isPointer %}
32-
*from_{{ name }} = ({{ cType|unPointer }}) {{ cast }} {%if isEnum %}(int){%endif%} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
33-
{%else%}
34-
from_{{ name }} = ({{ cType }}) {{ cast }} {%if isEnum %}(int){%endif%} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
35-
{%endif%}
36-
{%else%}
37-
{%if cType|isDoublePointer %}
38-
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetRefValue();
39-
{%else%}
40-
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetValue();
41-
{%endif%}
42-
{%endif%}
43-
44-
{%if isOptional %}
45-
}
46-
else {
47-
from_{{ name }} = 0;
48-
}
49-
50-
{%endif%}
51-
{%endif%}
25+
}
26+
{% elsif cppClassName == 'Function' %}
27+
28+
{% elsif cppClassName == 'Buffer' %}
29+
30+
from_{{ name }} = Buffer::Data(args[{{ jsArg }}]->ToObject());
31+
32+
{% elsif cppClassName|isV8Value %}
33+
{% if cType|isPointer %}
34+
*from_{{ name }} = ({{ cType|unPointer }}) {{ cast }} {% if isEnum %}(int){% endif %} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
35+
{% else %}
36+
from_{{ name }} = ({{ cType }}) {{ cast }} {% if isEnum %}(int){% endif %} args[{{ jsArg }}]->To{{ cppClassName }}()->Value();
37+
{% endif %}
38+
{% else %}
39+
{% if cType|isDoublePointer %}
40+
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetRefValue();
41+
{% else %}
42+
from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetValue();
43+
{% endif %}
44+
{% endif %}
45+
46+
{% if isOptional %}
47+
}
48+
else {
49+
from_{{ name }} = 0;
50+
}
51+
52+
{% endif %}
53+
{% endif %}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL