Skip to content

Commit

Permalink
Format using clang-format-3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf-bot committed Aug 8, 2019
1 parent 2f4cc79 commit ebd35d0
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 239 deletions.
6 changes: 3 additions & 3 deletions symengine/cwrapper.cpp
Expand Up @@ -503,17 +503,17 @@ CWRAPPER_OUTPUT_TYPE basic_assign(basic a, const basic b)
CWRAPPER_OUTPUT_TYPE basic_parse(basic b, const char *str)
{
CWRAPPER_BEGIN
//b->m = SymEngine::parse(str);
// b->m = SymEngine::parse(str);
CWRAPPER_END
}

CWRAPPER_OUTPUT_TYPE basic_parse2(basic b, const char *str, int convert_xor)
{
CWRAPPER_BEGIN
if (convert_xor > 0) {
//b->m = SymEngine::parse(str);
// b->m = SymEngine::parse(str);
} else {
//b->m = SymEngine::parse(str, false);
// b->m = SymEngine::parse(str, false);
}
CWRAPPER_END
}
Expand Down
2 changes: 1 addition & 1 deletion symengine/expression.cpp
Expand Up @@ -18,7 +18,7 @@ std::string poly_print(const Expression &x)

Expression::Expression(const std::string &s)
{
//m_basic = parse(s);
// m_basic = parse(s);
}

} // SymEngine
22 changes: 14 additions & 8 deletions symengine/parser/alloc.h
Expand Up @@ -3,17 +3,20 @@

#define ALIGNMENT 8

inline size_t align(size_t n) {
return (n + ALIGNMENT - 1) & ~(ALIGNMENT - 1);
inline size_t align(size_t n)
{
return (n + ALIGNMENT - 1) & ~(ALIGNMENT - 1);
}

class Allocator
{
void *start;
size_t current_pos;
size_t size;

public:
Allocator(size_t s) {
Allocator(size_t s)
{
start = malloc(s);
if (start == nullptr) {
throw std::runtime_error("malloc failed.");
Expand All @@ -23,7 +26,8 @@ class Allocator
size = s;
}

void *allocate(size_t s) {
void *allocate(size_t s)
{
if (start == nullptr) {
throw std::runtime_error("malloc failed 2.");
}
Expand All @@ -39,13 +43,15 @@ class Allocator
if (current_pos - (size_t)start > size) {
throw std::runtime_error("Linear allocator too small.");
}
return (void*)addr;
return (void *)addr;
}

template <typename T, typename... Args> T* make_new(Args &&... args) {
return new(allocate(sizeof(T))) T(std::forward<Args>(args)...);
template <typename T, typename... Args>
T *make_new(Args &&... args)
{
return new (allocate(sizeof(T))) T(std::forward<Args>(args)...);
// To test the default "new", comment the above and uncomment this:
//return new T(std::forward<Args>(args)...);
// return new T(std::forward<Args>(args)...);
}
};

Expand Down
4 changes: 0 additions & 4 deletions symengine/parser/parser_stype.h
Expand Up @@ -9,8 +9,6 @@
#include "sem6.h"
//#include "sem7.h"



namespace SymEngine
{

Expand All @@ -31,6 +29,4 @@ struct YYSTYPE {

} // namespace SymEngine



#endif
1 change: 0 additions & 1 deletion symengine/parser/sem1.h
Expand Up @@ -27,5 +27,4 @@ using SymEngine::integer;
#define INTEGER(x) integer(x)
#define PRINT(x) std::cout << *x << std::endl


#endif
11 changes: 5 additions & 6 deletions symengine/parser/sem2.h
Expand Up @@ -5,14 +5,13 @@
// Computer 2: 8ms 39ms

#define TYPE int
#define ADD(x, y) x+y
#define SUB(x, y) x-y
#define MUL(x, y) x*y
#define DIV(x, y) x/y
#define POW(x, y) std::pow(x,y)
#define ADD(x, y) x + y
#define SUB(x, y) x - y
#define MUL(x, y) x *y
#define DIV(x, y) x / y
#define POW(x, y) std::pow(x, y)
#define SYMBOL(x) 1
#define INTEGER(x) std::stoi(x)
#define PRINT(x) std::cout << x << std::endl


#endif
11 changes: 4 additions & 7 deletions symengine/parser/sem3.h
Expand Up @@ -8,23 +8,21 @@

static Allocator al(1000000000);

enum NodeType
{
Add, Sub, Mul, Div, Pow, Symbol, Integer
};
enum NodeType { Add, Sub, Mul, Div, Pow, Symbol, Integer };

struct Node {
NodeType type;
};

static struct Node* make_node(NodeType type) {
static struct Node *make_node(NodeType type)
{
struct Node *n;
n = al.make_new<Node>();
n->type = type;
return n;
}

#define TYPE struct Node*
#define TYPE struct Node *
#define ADD(x, y) make_node(NodeType::Add)
#define SUB(x, y) make_node(NodeType::Sub)
#define MUL(x, y) make_node(NodeType::Mul)
Expand All @@ -34,5 +32,4 @@ static struct Node* make_node(NodeType type) {
#define INTEGER(x) make_node(NodeType::Integer)
#define PRINT(x) std::cout << x->type << std::endl


#endif
63 changes: 39 additions & 24 deletions symengine/parser/sem4.h
Expand Up @@ -7,23 +7,31 @@ static Allocator al(1000000000);

// Computer 1: 12ms 128ms
// Computer 2: 13ms 74ms 83ms
enum NodeType
{
Add, Sub, Mul, Div, Pow, Symbol, Integer
};
enum NodeType { Add, Sub, Mul, Div, Pow, Symbol, Integer };

typedef struct Node *PNode;
struct Node {
NodeType type;
union {
struct { PNode left; PNode right; } binop;
struct { PNode base; PNode exp; } pow;
struct { char *name; } symbol;
struct { char *i; } integer;
struct {
PNode left;
PNode right;
} binop;
struct {
PNode base;
PNode exp;
} pow;
struct {
char *name;
} symbol;
struct {
char *i;
} integer;
} d;
};

static struct Node* make_binop(NodeType type, PNode x, PNode y) {
static struct Node *make_binop(NodeType type, PNode x, PNode y)
{
PNode n;
n = al.make_new<Node>();
n->type = type;
Expand All @@ -32,7 +40,8 @@ static struct Node* make_binop(NodeType type, PNode x, PNode y) {
return n;
}

static struct Node* make_pow(PNode x, PNode y) {
static struct Node *make_pow(PNode x, PNode y)
{
PNode n;
n = al.make_new<Node>();
n->type = NodeType::Pow;
Expand All @@ -41,39 +50,46 @@ static struct Node* make_pow(PNode x, PNode y) {
return n;
}

static struct Node* make_symbol(std::string s) {
static struct Node *make_symbol(std::string s)
{
PNode n;
n = al.make_new<Node>();
n->type = NodeType::Symbol;
n->d.symbol.name = &s[0];
return n;
}

static struct Node* make_integer(std::string s) {
static struct Node *make_integer(std::string s)
{
PNode n;
n = al.make_new<Node>();
n->type = NodeType::Integer;
n->d.integer.i = &s[0];
return n;
}

static int count(const Node &x) {
static int count(const Node &x)
{
switch (x.type) {
case Add:
case Sub:
case Mul:
case Div: {
int c = 0;
c += count(*x.d.binop.left);
c += count(*x.d.binop.right);
return c; }
int c = 0;
c += count(*x.d.binop.left);
c += count(*x.d.binop.right);
return c;
}
case Pow: {
int c = 0;
c += count(*x.d.pow.base);
c += count(*x.d.pow.exp);
return c; }
case Symbol: return 1;
case Integer: return 0;
int c = 0;
c += count(*x.d.pow.base);
c += count(*x.d.pow.exp);
return c;
}
case Symbol:
return 1;
case Integer:
return 0;
}
}

Expand All @@ -88,5 +104,4 @@ static int count(const Node &x) {
//#define PRINT(x) std::cout << x->d.binop.right->type << std::endl
#define PRINT(x) std::cout << count(*x) << std::endl;


#endif
46 changes: 28 additions & 18 deletions symengine/parser/sem5.h
Expand Up @@ -6,53 +6,63 @@
Computer 2: 5ms 72ms
*/

enum BinOpType
{
Add, Sub, Mul, Div
};
enum BinOpType { Add, Sub, Mul, Div };

class Base {
class Base
{
};

class BinOp : public Base {
class BinOp : public Base
{
const BinOpType type;
const Base *left, *right;

public:
BinOp(BinOpType type, const Base *x, const Base *y)
: type{type}, left{x}, right{y} {
: type{type}, left{x}, right{y}
{
}
};

class Pow : public Base {
class Pow : public Base
{
const Base *base, *exp;

public:
Pow(const Base *x, const Base *y)
: base{x}, exp{y} {
Pow(const Base *x, const Base *y) : base{x}, exp{y}
{
}
};

class Symbol : public Base {
class Symbol : public Base
{
const char *name;

public:
Symbol(const std::string s) : name{s.c_str()} { }
Symbol(const std::string s) : name{s.c_str()}
{
}
};

class Integer : public Base {
class Integer : public Base
{
const char *i;

public:
Integer(const std::string s) : i{s.c_str()} { }
Integer(const std::string s) : i{s.c_str()}
{
}
};


#define TYPE Base*
#define TYPE Base *
#define ADD(x, y) new BinOp(BinOpType::Add, x, y)
#define SUB(x, y) new BinOp(BinOpType::Sub, x, y)
#define MUL(x, y) new BinOp(BinOpType::Mul, x, y)
#define DIV(x, y) new BinOp(BinOpType::Div, x, y)
#define POW(x, y) new Pow(x, y)
#define SYMBOL(x) new Symbol(x)
#define INTEGER(x) new Integer(x)
#define PRINT(x) std::cout << "OK" << std::endl; //x->d.binop.right->type << std::endl

#define PRINT(x) \
std::cout << "OK" << std::endl; // x->d.binop.right->type << std::endl

#endif

0 comments on commit ebd35d0

Please sign in to comment.