Skip to content

Commit f5f4637

Browse files
committed
Format .c and .h files
1 parent cff9a88 commit f5f4637

28 files changed

+365
-203
lines changed

.clang-format

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Language: Cpp
2+
AccessModifierOffset: -4
3+
AlignAfterOpenBracket: true
4+
AlignConsecutiveAssignments: false
5+
AlignEscapedNewlinesLeft: false
6+
AlignOperands: true
7+
AlignTrailingComments: true
8+
AllowAllParametersOfDeclarationOnNextLine: true
9+
AllowShortBlocksOnASingleLine: false
10+
AllowShortCaseLabelsOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: Empty
12+
AllowShortIfStatementsOnASingleLine: false
13+
AllowShortLoopsOnASingleLine: false
14+
AlwaysBreakAfterDefinitionReturnType: None
15+
AlwaysBreakBeforeMultilineStrings: false
16+
AlwaysBreakTemplateDeclarations: true
17+
BinPackArguments: true
18+
BinPackParameters: true
19+
BreakBeforeBinaryOperators: All
20+
BreakBeforeBraces: Linux
21+
BreakBeforeTernaryOperators: true
22+
BreakConstructorInitializersBeforeComma: false
23+
ColumnLimit: 80
24+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
25+
ConstructorInitializerIndentWidth: 4
26+
ContinuationIndentWidth: 4
27+
Cpp11BracedListStyle: true
28+
DerivePointerAlignment: false
29+
DisableFormat: false
30+
ExperimentalAutoDetectBinPacking: false
31+
IndentCaseLabels: true
32+
IndentWidth: 4
33+
IndentWrappedFunctionNames: false
34+
KeepEmptyLinesAtTheStartOfBlocks: true
35+
MacroBlockBegin: ''
36+
MacroBlockEnd: ''
37+
MaxEmptyLinesToKeep: 1
38+
NamespaceIndentation: None
39+
ObjCBlockIndentWidth: 2
40+
ObjCSpaceAfterProperty: false
41+
ObjCSpaceBeforeProtocolList: true
42+
PenaltyBreakBeforeFirstCallParameter: 19
43+
PenaltyBreakComment: 22312
44+
PenaltyBreakFirstLessLess: 120
45+
PenaltyBreakString: 2123
46+
PenaltyExcessCharacter: 1000000
47+
PenaltyReturnTypeOnItsOwnLine: 60
48+
PointerAlignment: Right
49+
SpaceAfterCStyleCast: false
50+
SpaceBeforeAssignmentOperators: true
51+
SpaceBeforeParens: ControlStatements
52+
SpaceInEmptyParentheses: false
53+
SpacesBeforeTrailingComments: 1
54+
SpacesInAngles: false
55+
SpacesInContainerLiterals: false
56+
SpacesInCStyleCastParentheses: false
57+
SpacesInParentheses: false
58+
SpacesInSquareBrackets: false
59+
Standard: Cpp11
60+
TabWidth: 4
61+
UseTab: Never

bin/format.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
find ext/symengine/ -iname *.h -o -iname *.c | xargs clang-format-3.7 -style=file -i

ext/symengine/ruby_basic.c

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
#include "ruby_basic.h"
22

3-
void cbasic_free(void *ptr){
3+
void cbasic_free(void *ptr)
4+
{
45
basic_struct *basic_ptr = ptr;
56
basic_free_stack(basic_ptr);
67
}
78

8-
void cbasic_free_heap(void *ptr) {
9+
void cbasic_free_heap(void *ptr)
10+
{
911
basic_struct *basic_ptr = ptr;
1012
basic_free_heap(basic_ptr);
1113
}
1214

13-
VALUE cbasic_alloc(VALUE klass){
15+
VALUE cbasic_alloc(VALUE klass)
16+
{
1417
basic_struct *struct_ptr = basic_new_heap();
1518
return Data_Wrap_Struct(klass, NULL, cbasic_free_heap, struct_ptr);
1619
}
1720

18-
VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*)){
21+
VALUE cbasic_binary_op(VALUE self, VALUE operand2,
22+
void (*cwfunc_ptr)(basic_struct *, const basic_struct *,
23+
const basic_struct *))
24+
{
1925
basic_struct *this, *cresult;
2026
VALUE result;
2127

@@ -27,46 +33,56 @@ VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_stru
2733

2834
cresult = basic_new_heap();
2935
cwfunc_ptr(cresult, this, cbasic_operand2);
30-
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
36+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap,
37+
cresult);
3138
basic_free_stack(cbasic_operand2);
3239

3340
return result;
3441
}
3542

36-
VALUE cbasic_unary_op(VALUE self, void (*cwfunc_ptr)(basic_struct*, const basic_struct*)){
43+
VALUE cbasic_unary_op(VALUE self,
44+
void (*cwfunc_ptr)(basic_struct *, const basic_struct *))
45+
{
3746
basic_struct *this, *cresult;
3847
VALUE result;
3948

4049
Data_Get_Struct(self, basic_struct, this);
4150

4251
cresult = basic_new_heap();
4352
cwfunc_ptr(cresult, this);
44-
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
53+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap,
54+
cresult);
4555

4656
return result;
4757
}
4858

49-
VALUE cbasic_add(VALUE self, VALUE operand2){
59+
VALUE cbasic_add(VALUE self, VALUE operand2)
60+
{
5061
return cbasic_binary_op(self, operand2, basic_add);
5162
}
5263

53-
VALUE cbasic_sub(VALUE self, VALUE operand2){
64+
VALUE cbasic_sub(VALUE self, VALUE operand2)
65+
{
5466
return cbasic_binary_op(self, operand2, basic_sub);
5567
}
5668

57-
VALUE cbasic_mul(VALUE self, VALUE operand2){
69+
VALUE cbasic_mul(VALUE self, VALUE operand2)
70+
{
5871
return cbasic_binary_op(self, operand2, basic_mul);
5972
}
6073

61-
VALUE cbasic_div(VALUE self, VALUE operand2){
74+
VALUE cbasic_div(VALUE self, VALUE operand2)
75+
{
6276
return cbasic_binary_op(self, operand2, basic_div);
6377
}
6478

65-
VALUE cbasic_pow(VALUE self, VALUE operand2){
79+
VALUE cbasic_pow(VALUE self, VALUE operand2)
80+
{
6681
return cbasic_binary_op(self, operand2, basic_pow);
6782
}
6883

69-
VALUE cbasic_diff(VALUE self, VALUE operand2) {
84+
VALUE cbasic_diff(VALUE self, VALUE operand2)
85+
{
7086
basic_struct *this, *cresult;
7187
VALUE result;
7288

@@ -83,13 +99,15 @@ VALUE cbasic_diff(VALUE self, VALUE operand2) {
8399
basic_free_heap(cresult);
84100
return Qnil;
85101
}
86-
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
102+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap,
103+
cresult);
87104
basic_free_stack(cbasic_operand2);
88105

89106
return result;
90107
}
91108

92-
VALUE cbasic_eq(VALUE self, VALUE operand2) {
109+
VALUE cbasic_eq(VALUE self, VALUE operand2)
110+
{
93111

94112
basic_struct *this;
95113

@@ -98,35 +116,40 @@ VALUE cbasic_eq(VALUE self, VALUE operand2) {
98116
Data_Get_Struct(self, basic_struct, this);
99117

100118
VALUE ret = check_sympify(operand2, cbasic_operand2);
101-
if (ret == Qfalse) return Qfalse;
119+
if (ret == Qfalse)
120+
return Qfalse;
102121

103122
VALUE ret_val = basic_eq(this, cbasic_operand2) ? Qtrue : Qfalse;
104123
basic_free_stack(cbasic_operand2);
105124

106125
return ret_val;
107126
}
108127

109-
VALUE cbasic_neq(VALUE self, VALUE operand2) {
128+
VALUE cbasic_neq(VALUE self, VALUE operand2)
129+
{
110130
basic_struct *this;
111131

112132
basic cbasic_operand2;
113133
basic_new_stack(cbasic_operand2);
114134
Data_Get_Struct(self, basic_struct, this);
115135

116136
VALUE ret = check_sympify(operand2, cbasic_operand2);
117-
if (ret == Qfalse) return Qtrue;
137+
if (ret == Qfalse)
138+
return Qtrue;
118139

119-
VALUE ret_val = basic_neq(this, cbasic_operand2) ? Qtrue : Qfalse;
140+
VALUE ret_val = basic_neq(this, cbasic_operand2) ? Qtrue : Qfalse;
120141
basic_free_stack(cbasic_operand2);
121142

122143
return ret_val;
123144
}
124145

125-
VALUE cbasic_neg(VALUE self){
146+
VALUE cbasic_neg(VALUE self)
147+
{
126148
return cbasic_unary_op(self, basic_neg);
127149
}
128150

129-
VALUE cbasic_get_args(VALUE self) {
151+
VALUE cbasic_get_args(VALUE self)
152+
{
130153
basic_struct *this;
131154
CVecBasic *args = vecbasic_new();
132155
int size = 0;
@@ -138,17 +161,19 @@ VALUE cbasic_get_args(VALUE self) {
138161
VALUE ruby_array = rb_ary_new2(size);
139162
int i = 0;
140163
VALUE temp;
141-
for(i = 0; i < size; i++) {
164+
for (i = 0; i < size; i++) {
142165
basic_struct *temp_basic = basic_new_heap();
143166
vecbasic_get(args, i, temp_basic);
144-
temp = Data_Wrap_Struct(rb_obj_class(self), NULL , cbasic_free_heap, temp_basic);
167+
temp = Data_Wrap_Struct(rb_obj_class(self), NULL, cbasic_free_heap,
168+
temp_basic);
145169
rb_ary_push(ruby_array, temp);
146170
}
147171
vecbasic_free(args);
148172
return ruby_array;
149173
}
150174

151-
VALUE cbasic_free_symbols(VALUE self) {
175+
VALUE cbasic_free_symbols(VALUE self)
176+
{
152177
basic_struct *this;
153178
CSetBasic *symbols = setbasic_new();
154179
int size = 0;
@@ -160,17 +185,19 @@ VALUE cbasic_free_symbols(VALUE self) {
160185
VALUE ruby_array = rb_ary_new2(size);
161186
int i = 0;
162187
VALUE temp;
163-
for(i = 0; i < size; i++) {
188+
for (i = 0; i < size; i++) {
164189
basic_struct *temp_basic = basic_new_heap();
165190
setbasic_get(symbols, i, temp_basic);
166-
temp = Data_Wrap_Struct(rb_obj_class(self), NULL , cbasic_free_heap, temp_basic);
191+
temp = Data_Wrap_Struct(rb_obj_class(self), NULL, cbasic_free_heap,
192+
temp_basic);
167193
rb_ary_push(ruby_array, temp);
168194
}
169195
setbasic_free(symbols);
170196
return ruby_array;
171197
}
172198

173-
VALUE cbasic_to_str(VALUE self){
199+
VALUE cbasic_to_str(VALUE self)
200+
{
174201
basic_struct *this;
175202
char *str_ptr;
176203
VALUE result;
@@ -184,11 +211,13 @@ VALUE cbasic_to_str(VALUE self){
184211
return result;
185212
}
186213

187-
VALUE cbasic_expand(VALUE self){
214+
VALUE cbasic_expand(VALUE self)
215+
{
188216
return cbasic_unary_op(self, basic_expand);
189217
}
190218

191-
VALUE cbasic_hash(VALUE self){
219+
VALUE cbasic_hash(VALUE self)
220+
{
192221
basic_struct *this;
193222
Data_Get_Struct(self, basic_struct, this);
194223
// All ruby objects return FIXNUM when `hash` method is called.
@@ -203,7 +232,8 @@ VALUE cbasic_hash(VALUE self){
203232
return SIZET2NUM(basic_hash(this));
204233
}
205234

206-
int insert_entries(VALUE key, VALUE val, VALUE input) {
235+
int insert_entries(VALUE key, VALUE val, VALUE input)
236+
{
207237
CMapBasicBasic *cmapbb;
208238
Data_Get_Struct(input, CMapBasicBasic, cmapbb);
209239

@@ -220,18 +250,21 @@ int insert_entries(VALUE key, VALUE val, VALUE input) {
220250
return ST_CONTINUE;
221251
}
222252

223-
VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) {
253+
VALUE cbasic_subs(int argc, VALUE *argv, VALUE self)
254+
{
224255
basic_struct *this, *cresult;
225256
cresult = basic_new_heap();
226257

227258
VALUE val_a, val_b;
228259
Data_Get_Struct(self, basic_struct, this);
229260

230-
rb_scan_args(argc, argv, "11", &val_a, &val_b); // 1 mandatory and 1 optional parameter
261+
rb_scan_args(argc, argv, "11", &val_a,
262+
&val_b); // 1 mandatory and 1 optional parameter
231263
if (argc == 1) {
232264
Check_Type(val_a, T_HASH);
233265
CMapBasicBasic *cmapbb = mapbasicbasic_new();
234-
VALUE mapbb = Data_Wrap_Struct(rb_cObject, NULL, mapbasicbasic_free, cmapbb);
266+
VALUE mapbb
267+
= Data_Wrap_Struct(rb_cObject, NULL, mapbasicbasic_free, cmapbb);
235268

236269
rb_hash_foreach(val_a, insert_entries, mapbb);
237270
basic_subs(cresult, this, cmapbb);
@@ -248,13 +281,16 @@ VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) {
248281
basic_free_stack(b);
249282
}
250283

251-
return Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, cresult);
284+
return Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap,
285+
cresult);
252286
}
253287

254-
VALUE cbasic_coerce(VALUE self, VALUE other){
288+
VALUE cbasic_coerce(VALUE self, VALUE other)
289+
{
255290
basic_struct *cbasic_operand2;
256291
cbasic_operand2 = basic_new_heap();
257292
sympify(other, cbasic_operand2);
258-
VALUE new_other = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand2), NULL , cbasic_free_heap, cbasic_operand2);
293+
VALUE new_other = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand2), NULL,
294+
cbasic_free_heap, cbasic_operand2);
259295
return rb_assoc_new(new_other, self);
260296
}

ext/symengine/ruby_basic.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ void cbasic_free_heap(void *ptr);
1212

1313
VALUE cbasic_alloc(VALUE klass);
1414

15-
VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*));
15+
VALUE cbasic_binary_op(VALUE self, VALUE operand2,
16+
void (*cwfunc_ptr)(basic_struct *, const basic_struct *,
17+
const basic_struct *));
1618

17-
VALUE cbasic_unary_op(VALUE self, void (*cwfunc_ptr)(basic_struct*, const basic_struct*));
19+
VALUE cbasic_unary_op(VALUE self,
20+
void (*cwfunc_ptr)(basic_struct *, const basic_struct *));
1821

1922
VALUE cbasic_add(VALUE self, VALUE operand2);
2023

@@ -50,4 +53,4 @@ VALUE cbasic_subs(int argc, VALUE *argv, VALUE self);
5053

5154
VALUE cbasic_coerce(VALUE self, VALUE other);
5255

53-
#endif //RUBY_BASIC_H_
56+
#endif // RUBY_BASIC_H_

ext/symengine/ruby_complex.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "ruby_complex.h"
22

3-
VALUE ccomplex_real_part(VALUE self) {
3+
VALUE ccomplex_real_part(VALUE self)
4+
{
45
return function_onearg(complex_real_part, self);
56
}
67

7-
VALUE ccomplex_imaginary_part(VALUE self) {
8+
VALUE ccomplex_imaginary_part(VALUE self)
9+
{
810
return function_onearg(complex_imaginary_part, self);
911
}

ext/symengine/ruby_complex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
VALUE ccomplex_real_part(VALUE self);
1111
VALUE ccomplex_imaginary_part(VALUE self);
1212

13-
#endif //RUBY_COMPLEX_H_
13+
#endif // RUBY_COMPLEX_H_

0 commit comments

Comments
 (0)