Loading edify/Android.mk +6 −10 Original line number Diff line number Diff line Loading @@ -5,12 +5,7 @@ LOCAL_PATH := $(call my-dir) edify_src_files := \ lexer.l \ parser.y \ expr.c # "-x c" forces the lex/yacc files to be compiled as c the build system # otherwise forces them to be c++. Need to also add an explicit -std because the # build system will soon default C++ to -std=c++11. edify_cflags := -x c -std=gnu89 expr.cpp # # Build the host-side command line tool Loading @@ -19,12 +14,13 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ $(edify_src_files) \ main.c main.cpp LOCAL_CPPFLAGS := $(edify_cflags) -g -O0 LOCAL_CPPFLAGS := -g -O0 LOCAL_MODULE := edify LOCAL_YACCFLAGS := -v LOCAL_CPPFLAGS += -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_CLANG := true include $(BUILD_HOST_EXECUTABLE) Loading @@ -36,8 +32,8 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(edify_src_files) LOCAL_CPPFLAGS := $(edify_cflags) LOCAL_CPPFLAGS += -Wno-unused-parameter LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify LOCAL_CLANG := true Loading edify/expr.c→edify/expr.cpp +16 −14 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ Value* EvaluateValue(State* state, Expr* expr) { Value* StringValue(char* str) { if (str == NULL) return NULL; Value* v = malloc(sizeof(Value)); Value* v = reinterpret_cast<Value*>(malloc(sizeof(Value))); v->type = VAL_STRING; v->size = strlen(str); v->data = str; Loading @@ -68,7 +68,7 @@ Value* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc == 0) { return StringValue(strdup("")); } char** strings = malloc(argc * sizeof(char*)); char** strings = reinterpret_cast<char**>(malloc(argc * sizeof(char*))); int i; for (i = 0; i < argc; ++i) { strings[i] = NULL; Loading @@ -83,8 +83,9 @@ Value* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) { length += strlen(strings[i]); } result = malloc(length+1); int p = 0; result = reinterpret_cast<char*>(malloc(length+1)); int p; p = 0; for (i = 0; i < argc; ++i) { strcpy(result+p, strings[i]); p += strlen(strings[i]); Loading Loading @@ -149,7 +150,7 @@ Value* AssertFn(const char* name, State* state, int argc, Expr* argv[]) { if (!b) { int prefix_len; int len = argv[i]->end - argv[i]->start; char* err_src = malloc(len + 20); char* err_src = reinterpret_cast<char*>(malloc(len + 20)); strcpy(err_src, "assert failed: "); prefix_len = strlen(err_src); memcpy(err_src + prefix_len, state->script + argv[i]->start, len); Loading Loading @@ -290,7 +291,8 @@ Value* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) { goto done; } long r_int = strtol(right, &end, 10); long r_int; r_int = strtol(right, &end, 10); if (right[0] == '\0' || *end != '\0') { goto done; } Loading Loading @@ -325,11 +327,11 @@ Value* Literal(const char* name, State* state, int argc, Expr* argv[]) { Expr* Build(Function fn, YYLTYPE loc, int count, ...) { va_list v; va_start(v, count); Expr* e = malloc(sizeof(Expr)); Expr* e = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); e->fn = fn; e->name = "(operator)"; e->argc = count; e->argv = malloc(count * sizeof(Expr*)); e->argv = reinterpret_cast<Expr**>(malloc(count * sizeof(Expr*))); int i; for (i = 0; i < count; ++i) { e->argv[i] = va_arg(v, Expr*); Loading @@ -351,7 +353,7 @@ NamedFunction* fn_table = NULL; void RegisterFunction(const char* name, Function fn) { if (fn_entries >= fn_size) { fn_size = fn_size*2 + 1; fn_table = realloc(fn_table, fn_size * sizeof(NamedFunction)); fn_table = reinterpret_cast<NamedFunction*>(realloc(fn_table, fn_size * sizeof(NamedFunction))); } fn_table[fn_entries].name = name; fn_table[fn_entries].fn = fn; Loading @@ -371,8 +373,8 @@ void FinishRegistration() { Function FindFunction(const char* name) { NamedFunction key; key.name = name; NamedFunction* nf = bsearch(&key, fn_table, fn_entries, sizeof(NamedFunction), fn_entry_compare); NamedFunction* nf = reinterpret_cast<NamedFunction*>(bsearch(&key, fn_table, fn_entries, sizeof(NamedFunction), fn_entry_compare)); if (nf == NULL) { return NULL; } Loading Loading @@ -401,7 +403,7 @@ void RegisterBuiltins() { // zero or more char** to put them in). If any expression evaluates // to NULL, free the rest and return -1. Return 0 on success. int ReadArgs(State* state, Expr* argv[], int count, ...) { char** args = malloc(count * sizeof(char*)); char** args = reinterpret_cast<char**>(malloc(count * sizeof(char*))); va_list v; va_start(v, count); int i; Loading @@ -427,7 +429,7 @@ int ReadArgs(State* state, Expr* argv[], int count, ...) { // zero or more Value** to put them in). If any expression evaluates // to NULL, free the rest and return -1. Return 0 on success. int ReadValueArgs(State* state, Expr* argv[], int count, ...) { Value** args = malloc(count * sizeof(Value*)); Value** args = reinterpret_cast<Value**>(malloc(count * sizeof(Value*))); va_list v; va_start(v, count); int i; Loading Loading @@ -494,7 +496,7 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) { // Use printf-style arguments to compose an error message to put into // *state. Returns NULL. Value* ErrorAbort(State* state, const char* format, ...) { char* buffer = malloc(4096); char* buffer = reinterpret_cast<char*>(malloc(4096)); va_list v; va_start(v, format); vsnprintf(buffer, 4096, format, v); Loading edify/expr.h +1 −9 Original line number Diff line number Diff line Loading @@ -21,10 +21,6 @@ #include "yydefs.h" #ifdef __cplusplus extern "C" { #endif #define MAX_STRING_LEN 1024 typedef struct Expr Expr; Loading Loading @@ -59,7 +55,7 @@ typedef Value* (*Function)(const char* name, State* state, struct Expr { Function fn; char* name; const char* name; int argc; Expr** argv; int start, end; Loading Loading @@ -166,8 +162,4 @@ void FreeValue(Value* v); int parse_string(const char* str, Expr** root, int* error_count); #ifdef __cplusplus } // extern "C" #endif #endif // _EXPRESSION_H edify/main.c→edify/main.cpp +0 −0 File moved. View file edify/parser.y +4 −4 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ input: expr { *root = $1; } ; expr: STRING { $$ = malloc(sizeof(Expr)); $$ = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); $$->fn = Literal; $$->name = $1; $$->argc = 0; Loading @@ -91,7 +91,7 @@ expr: STRING { | IF expr THEN expr ENDIF { $$ = Build(IfElseFn, @$, 2, $2, $4); } | IF expr THEN expr ELSE expr ENDIF { $$ = Build(IfElseFn, @$, 3, $2, $4, $6); } | STRING '(' arglist ')' { $$ = malloc(sizeof(Expr)); $$ = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); $$->fn = FindFunction($1); if ($$->fn == NULL) { char buffer[256]; Loading @@ -113,12 +113,12 @@ arglist: /* empty */ { } | expr { $$.argc = 1; $$.argv = malloc(sizeof(Expr*)); $$.argv = reinterpret_cast<Expr**>(malloc(sizeof(Expr*))); $$.argv[0] = $1; } | arglist ',' expr { $$.argc = $1.argc + 1; $$.argv = realloc($$.argv, $$.argc * sizeof(Expr*)); $$.argv = reinterpret_cast<Expr**>(realloc($$.argv, $$.argc * sizeof(Expr*))); $$.argv[$$.argc-1] = $3; } ; Loading Loading
edify/Android.mk +6 −10 Original line number Diff line number Diff line Loading @@ -5,12 +5,7 @@ LOCAL_PATH := $(call my-dir) edify_src_files := \ lexer.l \ parser.y \ expr.c # "-x c" forces the lex/yacc files to be compiled as c the build system # otherwise forces them to be c++. Need to also add an explicit -std because the # build system will soon default C++ to -std=c++11. edify_cflags := -x c -std=gnu89 expr.cpp # # Build the host-side command line tool Loading @@ -19,12 +14,13 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ $(edify_src_files) \ main.c main.cpp LOCAL_CPPFLAGS := $(edify_cflags) -g -O0 LOCAL_CPPFLAGS := -g -O0 LOCAL_MODULE := edify LOCAL_YACCFLAGS := -v LOCAL_CPPFLAGS += -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_CLANG := true include $(BUILD_HOST_EXECUTABLE) Loading @@ -36,8 +32,8 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(edify_src_files) LOCAL_CPPFLAGS := $(edify_cflags) LOCAL_CPPFLAGS += -Wno-unused-parameter LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify LOCAL_CLANG := true Loading
edify/expr.c→edify/expr.cpp +16 −14 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ Value* EvaluateValue(State* state, Expr* expr) { Value* StringValue(char* str) { if (str == NULL) return NULL; Value* v = malloc(sizeof(Value)); Value* v = reinterpret_cast<Value*>(malloc(sizeof(Value))); v->type = VAL_STRING; v->size = strlen(str); v->data = str; Loading @@ -68,7 +68,7 @@ Value* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc == 0) { return StringValue(strdup("")); } char** strings = malloc(argc * sizeof(char*)); char** strings = reinterpret_cast<char**>(malloc(argc * sizeof(char*))); int i; for (i = 0; i < argc; ++i) { strings[i] = NULL; Loading @@ -83,8 +83,9 @@ Value* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) { length += strlen(strings[i]); } result = malloc(length+1); int p = 0; result = reinterpret_cast<char*>(malloc(length+1)); int p; p = 0; for (i = 0; i < argc; ++i) { strcpy(result+p, strings[i]); p += strlen(strings[i]); Loading Loading @@ -149,7 +150,7 @@ Value* AssertFn(const char* name, State* state, int argc, Expr* argv[]) { if (!b) { int prefix_len; int len = argv[i]->end - argv[i]->start; char* err_src = malloc(len + 20); char* err_src = reinterpret_cast<char*>(malloc(len + 20)); strcpy(err_src, "assert failed: "); prefix_len = strlen(err_src); memcpy(err_src + prefix_len, state->script + argv[i]->start, len); Loading Loading @@ -290,7 +291,8 @@ Value* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) { goto done; } long r_int = strtol(right, &end, 10); long r_int; r_int = strtol(right, &end, 10); if (right[0] == '\0' || *end != '\0') { goto done; } Loading Loading @@ -325,11 +327,11 @@ Value* Literal(const char* name, State* state, int argc, Expr* argv[]) { Expr* Build(Function fn, YYLTYPE loc, int count, ...) { va_list v; va_start(v, count); Expr* e = malloc(sizeof(Expr)); Expr* e = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); e->fn = fn; e->name = "(operator)"; e->argc = count; e->argv = malloc(count * sizeof(Expr*)); e->argv = reinterpret_cast<Expr**>(malloc(count * sizeof(Expr*))); int i; for (i = 0; i < count; ++i) { e->argv[i] = va_arg(v, Expr*); Loading @@ -351,7 +353,7 @@ NamedFunction* fn_table = NULL; void RegisterFunction(const char* name, Function fn) { if (fn_entries >= fn_size) { fn_size = fn_size*2 + 1; fn_table = realloc(fn_table, fn_size * sizeof(NamedFunction)); fn_table = reinterpret_cast<NamedFunction*>(realloc(fn_table, fn_size * sizeof(NamedFunction))); } fn_table[fn_entries].name = name; fn_table[fn_entries].fn = fn; Loading @@ -371,8 +373,8 @@ void FinishRegistration() { Function FindFunction(const char* name) { NamedFunction key; key.name = name; NamedFunction* nf = bsearch(&key, fn_table, fn_entries, sizeof(NamedFunction), fn_entry_compare); NamedFunction* nf = reinterpret_cast<NamedFunction*>(bsearch(&key, fn_table, fn_entries, sizeof(NamedFunction), fn_entry_compare)); if (nf == NULL) { return NULL; } Loading Loading @@ -401,7 +403,7 @@ void RegisterBuiltins() { // zero or more char** to put them in). If any expression evaluates // to NULL, free the rest and return -1. Return 0 on success. int ReadArgs(State* state, Expr* argv[], int count, ...) { char** args = malloc(count * sizeof(char*)); char** args = reinterpret_cast<char**>(malloc(count * sizeof(char*))); va_list v; va_start(v, count); int i; Loading @@ -427,7 +429,7 @@ int ReadArgs(State* state, Expr* argv[], int count, ...) { // zero or more Value** to put them in). If any expression evaluates // to NULL, free the rest and return -1. Return 0 on success. int ReadValueArgs(State* state, Expr* argv[], int count, ...) { Value** args = malloc(count * sizeof(Value*)); Value** args = reinterpret_cast<Value**>(malloc(count * sizeof(Value*))); va_list v; va_start(v, count); int i; Loading Loading @@ -494,7 +496,7 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) { // Use printf-style arguments to compose an error message to put into // *state. Returns NULL. Value* ErrorAbort(State* state, const char* format, ...) { char* buffer = malloc(4096); char* buffer = reinterpret_cast<char*>(malloc(4096)); va_list v; va_start(v, format); vsnprintf(buffer, 4096, format, v); Loading
edify/expr.h +1 −9 Original line number Diff line number Diff line Loading @@ -21,10 +21,6 @@ #include "yydefs.h" #ifdef __cplusplus extern "C" { #endif #define MAX_STRING_LEN 1024 typedef struct Expr Expr; Loading Loading @@ -59,7 +55,7 @@ typedef Value* (*Function)(const char* name, State* state, struct Expr { Function fn; char* name; const char* name; int argc; Expr** argv; int start, end; Loading Loading @@ -166,8 +162,4 @@ void FreeValue(Value* v); int parse_string(const char* str, Expr** root, int* error_count); #ifdef __cplusplus } // extern "C" #endif #endif // _EXPRESSION_H
edify/parser.y +4 −4 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ input: expr { *root = $1; } ; expr: STRING { $$ = malloc(sizeof(Expr)); $$ = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); $$->fn = Literal; $$->name = $1; $$->argc = 0; Loading @@ -91,7 +91,7 @@ expr: STRING { | IF expr THEN expr ENDIF { $$ = Build(IfElseFn, @$, 2, $2, $4); } | IF expr THEN expr ELSE expr ENDIF { $$ = Build(IfElseFn, @$, 3, $2, $4, $6); } | STRING '(' arglist ')' { $$ = malloc(sizeof(Expr)); $$ = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); $$->fn = FindFunction($1); if ($$->fn == NULL) { char buffer[256]; Loading @@ -113,12 +113,12 @@ arglist: /* empty */ { } | expr { $$.argc = 1; $$.argv = malloc(sizeof(Expr*)); $$.argv = reinterpret_cast<Expr**>(malloc(sizeof(Expr*))); $$.argv[0] = $1; } | arglist ',' expr { $$.argc = $1.argc + 1; $$.argv = realloc($$.argv, $$.argc * sizeof(Expr*)); $$.argv = reinterpret_cast<Expr**>(realloc($$.argv, $$.argc * sizeof(Expr*))); $$.argv[$$.argc-1] = $3; } ; Loading