Skip to content

Commit

Permalink
Copying error message to main function
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutierrez committed Apr 21, 2016
1 parent 3bc7895 commit ba06161
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
48 changes: 24 additions & 24 deletions parser/parser/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ static void xx_parse_with_token(void* xx_parser, int opcode, int parsercode, xx_
/**
* Creates an error message when it's triggered by the scanner
*/
static void xx_scanner_error_msg(xx_parser_status *parser_status){
/*static void xx_scanner_error_msg(xx_parser_status *parser_status){
/*char *error, *error_part;
char *error, *error_part;
XX_scanner_state *state = parser_status->scanner_state;
ALLOC_INIT_ZVAL(*error_msg);
Expand All @@ -94,8 +94,8 @@ static void xx_scanner_error_msg(xx_parser_status *parser_status){
sprintf(error, "Parsing error near to EOF in %s", Z_STRVAL_P(state->active_file));
ZVAL_STRING(*error_msg, error, 1);
}
efree(error);*/
}
efree(error);
}*/

void parser_track_variable(zval **var)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ void parser_free_memory()
/**
* Parses a comment returning an intermediate array representation
*/
zval *xx_parse_program(char *program, size_t program_length, char *file_path) {
zval *xx_parse_program(char *program, size_t program_length, char *file_path, zval **error_msg) {

char *error;
xx_scanner_state *state;
Expand Down Expand Up @@ -574,14 +574,13 @@ zval *xx_parse_program(char *program, size_t program_length, char *file_path) {

default:
parser_status->status = XX_PARSING_FAILED;
fprintf(stderr, "Scanner: unknown opcode %d\n", token.opcode);
/*if (!*error_msg) {
error = emalloc(sizeof(char) * (48 + Z_STRLEN_P(state->active_file)));
sprintf(error, "Scanner: unknown opcode %d on in %s line %d", token.opcode, Z_STRVAL_P(state->active_file), state->active_line);
ALLOC_INIT_ZVAL(*error_msg);
ZVAL_STRING(*error_msg, error, 1);
if (!*error_msg) {
int length = (48 + strlen(file_path));
error = emalloc(sizeof(char) * length);
snprintf(error, length, "Scanner: unknown opcode %d on in %s line %d", token.opcode, file_path, state->active_line);
//ZVAL_STRING(*error_msg, error, 1);
efree(error);
}*/
}
break;
}

Expand All @@ -598,14 +597,15 @@ zval *xx_parse_program(char *program, size_t program_length, char *file_path) {
case XX_SCANNER_RETCODE_ERR:
case XX_SCANNER_RETCODE_IMPOSSIBLE:
{
char *x = emalloc(sizeof(char) * 1024);
error = emalloc(sizeof(char) * 1024);
if (state->start) {
sprintf(x, "Scanner error: %d %s", scanner_status, state->start);
snprintf(error, 1024, "Scanner error: %d %s", scanner_status, state->start);
} else {
sprintf(x, "Scanner error: %d", scanner_status);
snprintf(error, 1024, "Scanner error: %d", scanner_status);
}
fprintf(stderr, "%s\n", x);
efree(x);
//ALLOC_INIT_ZVAL(*error_msg);
//ZVAL_STRING(*error_msg, error, 1);
efree(error);
status = FAILURE;
}
break;
Expand All @@ -619,14 +619,13 @@ zval *xx_parse_program(char *program, size_t program_length, char *file_path) {

if (parser_status->status != XX_PARSING_OK) {
status = FAILURE;
/*if (parser_status->syntax_error) {
if (parser_status->syntax_error) {
if (!*error_msg) {
ALLOC_INIT_ZVAL(*error_msg);
ZVAL_STRING(*error_msg, parser_status->syntax_error, 1);
//ALLOC_INIT_ZVAL(*error_msg);
//ZVAL_STRING(*error_msg, parser_status->syntax_error, 1);
}
efree(parser_status->syntax_error);
}*/
//fprintf(stderr, "error!\n");
}
}

if (status != FAILURE) {
Expand All @@ -647,8 +646,9 @@ zval *xx_parse_program(char *program, size_t program_length, char *file_path) {
#if PHP_VERSION_ID < 70000
zval *ret_ptr = parser_status->ret;
#else
zval *ret_ptr = emalloc(sizeof(zval *));
ZVAL_DUP(ret_ptr, parser_status->ret);
//zval *ret_ptr = emalloc(sizeof(zval *));
//ZVAL_DUP(ret_ptr, parser_status->ret);
zval *ret_ptr = parser_status->ret;

parser_free_memory();
#endif
Expand Down
5 changes: 3 additions & 2 deletions parser/zephir_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "ext/standard/info.h"
#include "php_zephir_parser.h"

extern zval *xx_parse_program(char *program, size_t program_length, char *file_path);
extern zval *xx_parse_program(char *program, size_t program_length, char *file_path, zval **error_msg);

/* {{{ proto string zephir_parse_file(string arg)
Return a string to confirm that the module is compiled in */
Expand All @@ -41,11 +41,12 @@ PHP_FUNCTION(zephir_parse_file)
#if PHP_VERSION_ID >= 70000
zend_array *arr = NULL;
#endif
zval **error_msg = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &content, &content_len, &filepath, &filepath_len) == FAILURE) {
return;
}
ret = xx_parse_program(content, content_len, filepath);
ret = xx_parse_program(content, content_len, filepath, error_msg);

#if PHP_VERSION_ID >= 70000
arr = Z_ARRVAL_P(ret);
Expand Down

0 comments on commit ba06161

Please sign in to comment.