- WIP populated cfile structure with variables, functions and according element type
- cleaned unused variable and function definitions - cleaned debug output calls - todo: create and include "user defined" header for including missing headers to stub.c (will not be overwritten if exists) - todo: include "includes" in cfile structure
This commit is contained in:
@@ -59,7 +59,7 @@ int8_t cfile_freeVariables(cfile_variableList_t *aVariable)
|
|||||||
while (work)
|
while (work)
|
||||||
{
|
{
|
||||||
next = work->next;
|
next = work->next;
|
||||||
free(work->type);
|
free(work->dataType);
|
||||||
free(work->name);
|
free(work->name);
|
||||||
free(work);
|
free(work);
|
||||||
work = next;
|
work = next;
|
||||||
@@ -77,3 +77,23 @@ void cfile_free(cfile_t *aCfile)
|
|||||||
cfile_freeVariables(&aCfile->variables);
|
cfile_freeVariables(&aCfile->variables);
|
||||||
cfunction_freeList(&aCfile->functions);
|
cfunction_freeList(&aCfile->functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cfile_print(cfile_t *aCfile)
|
||||||
|
{
|
||||||
|
cfile_variable_t *work = NULL;
|
||||||
|
|
||||||
|
if (NULL == aCfile)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
work = aCfile->variables.head;
|
||||||
|
|
||||||
|
while (work)
|
||||||
|
{
|
||||||
|
printf("[ cva]%d:<%s> (%s) %s\n", work->type, work->prefix, work->dataType, work->name);
|
||||||
|
work = work->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfunction_printList(&aCfile->functions);
|
||||||
|
}
|
||||||
|
@@ -16,11 +16,22 @@
|
|||||||
|
|
||||||
#include "cfunction_if.h"
|
#include "cfunction_if.h"
|
||||||
|
|
||||||
|
/*! @brief Type of function definition */
|
||||||
|
typedef enum _CFILE_VARIABLE_TYPE_T
|
||||||
|
{
|
||||||
|
CVARIABLE_TYPE_UNDEF = 0, /*!< @brief undefined */
|
||||||
|
CVARIABLE_TYPE_REGULAR = 1, /*!< @brief Regular C function definition */
|
||||||
|
CVARIABLE_TYPE_STATIC = 2, /*!< @brief Static C function definition */
|
||||||
|
CVARIABLE_TYPE_EXTERN = 4, /*!< @brief External C function definition */
|
||||||
|
CVARIABLE_TYPE_LAST_ENUM
|
||||||
|
} cfile_variable_type_t;
|
||||||
|
|
||||||
/*! @brief Parameter list node */
|
/*! @brief Parameter list node */
|
||||||
typedef struct _CFILE_VARIABLE_T
|
typedef struct _CFILE_VARIABLE_T
|
||||||
{
|
{
|
||||||
|
cfile_variable_type_t type;
|
||||||
char* prefix; /*!< @brief variable prefix (e.g. static) */
|
char* prefix; /*!< @brief variable prefix (e.g. static) */
|
||||||
char* type; /*!< @brief data type */
|
char* dataType; /*!< @brief data type */
|
||||||
char* name; /*!< @brief name */
|
char* name; /*!< @brief name */
|
||||||
struct _CFILE_VARIABLE_T *next;
|
struct _CFILE_VARIABLE_T *next;
|
||||||
} cfile_variable_t;
|
} cfile_variable_t;
|
||||||
@@ -49,5 +60,6 @@ typedef struct _CFILE_T
|
|||||||
cfile_variable_t* cfile_newVariable(cfile_variableList_t *aList);
|
cfile_variable_t* cfile_newVariable(cfile_variableList_t *aList);
|
||||||
int8_t cfile_freeVariables(cfile_variableList_t *aVariable);
|
int8_t cfile_freeVariables(cfile_variableList_t *aVariable);
|
||||||
void cfile_free(cfile_t *aCfile);
|
void cfile_free(cfile_t *aCfile);
|
||||||
|
void cfile_print(cfile_t *aCfile);
|
||||||
|
|
||||||
#endif /* STUBSER_CFILE_IF_H_ */
|
#endif /* STUBSER_CFILE_IF_H_ */
|
||||||
|
@@ -32,15 +32,7 @@ typedef enum _CFILE_BLOCK_RETURN_T
|
|||||||
} cfile_block_return_t;
|
} cfile_block_return_t;
|
||||||
|
|
||||||
STATIC bool cfile_parser_initialized = false;
|
STATIC bool cfile_parser_initialized = false;
|
||||||
STATIC uint8_t cfile_parser_functionLine = 0;
|
STATIC regex_t regXfunction;
|
||||||
STATIC cfunction_t *cfile_parser_function = NULL;
|
|
||||||
STATIC regex_t regX;
|
|
||||||
STATIC regex_t regXsl;
|
|
||||||
STATIC regex_t regXmlStart;
|
|
||||||
STATIC regex_t regXmlPar;
|
|
||||||
STATIC regex_t regXmlEnd;
|
|
||||||
STATIC regex_t regXmlProto;
|
|
||||||
STATIC regex_t regXproto;
|
|
||||||
STATIC regex_t regXprefix;
|
STATIC regex_t regXprefix;
|
||||||
STATIC regex_t regXparameter;
|
STATIC regex_t regXparameter;
|
||||||
STATIC regex_t regXvariable;
|
STATIC regex_t regXvariable;
|
||||||
@@ -65,37 +57,7 @@ int8_t cfile_parser_init()
|
|||||||
perror("Error regex\n");
|
perror("Error regex\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (0 > regcomp(®X, FUNCTION_BASE, (REG_EXTENDED | REG_NEWLINE)))
|
if (0 > regcomp(®Xfunction, CPARS_REGEX_FUNCTION, (REG_EXTENDED | REG_NEWLINE)))
|
||||||
{
|
|
||||||
perror("Error regex\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (0 > regcomp(®Xsl, FUNCTION_SL, (REG_EXTENDED | REG_NEWLINE)))
|
|
||||||
{
|
|
||||||
perror("Error regex\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (0 > regcomp(®XmlStart, FUNCTION_ML_SOF, (REG_EXTENDED | REG_NEWLINE)))
|
|
||||||
{
|
|
||||||
perror("Error regex\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (0 > regcomp(®XmlPar, FUNCTION_ML_PAR, (REG_EXTENDED | REG_NEWLINE)))
|
|
||||||
{
|
|
||||||
perror("Error regex\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (0 > regcomp(®XmlEnd, FUNCTION_ML_END, (REG_EXTENDED | REG_NEWLINE)))
|
|
||||||
{
|
|
||||||
perror("Error regex\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (0 > regcomp(®XmlProto, FUNCTION_ML_PROTO, (REG_EXTENDED | REG_NEWLINE)))
|
|
||||||
{
|
|
||||||
perror("Error regex\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (0 > regcomp(®Xproto, FUNCTION_PROTO, (REG_EXTENDED | REG_NEWLINE)))
|
|
||||||
{
|
{
|
||||||
perror("Error regex\n");
|
perror("Error regex\n");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -120,7 +82,7 @@ int8_t cfile_parser_init()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if(0)
|
#if isDebugLevel(1)
|
||||||
STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup)
|
STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup)
|
||||||
{
|
{
|
||||||
char match[1024] =
|
char match[1024] =
|
||||||
@@ -131,47 +93,91 @@ STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup)
|
|||||||
{
|
{
|
||||||
if (aMatchGroup[i].rm_so < aMatchGroup[i].rm_eo)
|
if (aMatchGroup[i].rm_so < aMatchGroup[i].rm_eo)
|
||||||
{
|
{
|
||||||
DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]:", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo, (int) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so));
|
DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]:", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo,
|
||||||
|
(int ) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so));
|
||||||
strlcpy(match, &aString[aMatchGroup[i].rm_so], (size_t) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so + 1));
|
strlcpy(match, &aString[aMatchGroup[i].rm_so], (size_t) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so + 1));
|
||||||
DEBUG_LOG_APPEND(1, "%s", match);
|
DEBUG_LOG_APPEND(1, "%s", match);
|
||||||
DEBUG_LOG_APPEND(1, "\n");
|
DEBUG_LOG_APPEND(1, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define printMatchGroup(aString, aMatchgroup) do { /*nothing*/ } while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC void checkFunctionType(cfunction_t *aFunction)
|
STATIC void checkFunctionType(cfunction_t *aFunction, char *aExpression)
|
||||||
{
|
{
|
||||||
|
char *tempChar = NULL;
|
||||||
|
|
||||||
|
if (NULL == aFunction || NULL == aExpression)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
aFunction->type = CFUNCTION_TYPE_REGULAR;
|
||||||
|
|
||||||
|
tempChar = strrchr(aExpression, CPARS_PROTOTYPE_END_C);
|
||||||
|
if (tempChar)
|
||||||
|
{
|
||||||
|
aFunction->type = CFUNCTION_TYPE_PROTO;
|
||||||
|
}
|
||||||
|
|
||||||
if (NULL == aFunction->prefix)
|
if (NULL == aFunction->prefix)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((NULL != strstr(aFunction->prefix, "static") || NULL != strstr(aFunction->prefix, "STATIC")) //
|
if (NULL != strstr(aFunction->prefix, CPARS_PREFIX_EXTERN_S))
|
||||||
&& CFUNCTION_TYPE_PROTO != aFunction->type)
|
{
|
||||||
|
aFunction->type = CFUNCTION_TYPE_EXTERN;
|
||||||
|
}
|
||||||
|
else if (NULL != strstr(aFunction->prefix, CPARS_PREFIX_STATIC_S) && CFUNCTION_TYPE_PROTO != aFunction->type)
|
||||||
{
|
{
|
||||||
aFunction->type = CFUNCTION_TYPE_STATIC;
|
aFunction->type = CFUNCTION_TYPE_STATIC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Extract function prefix and data type and removing trailing blanks
|
* @brief Extract C expression prefix and data type and removing trailing blanks
|
||||||
* @param [out] *aFunction Pointer to function structure
|
* @param [out] *aElement Pointer to C element structure
|
||||||
|
* @param [in] aElementType C element type (CELEMENT_TYPE_VARIABLE, CELEMENT_TYPE_FUNCTION supported)
|
||||||
* @param [in] *aString Pointer to a substring containing data type and/or prefix
|
* @param [in] *aString Pointer to a substring containing data type and/or prefix
|
||||||
* @param [in] aSize Length of string
|
* @param [in] aSize Length of string
|
||||||
* @retval 0 processing successful
|
* @retval 0 processing successful
|
||||||
* @retval -1 processing failed
|
* @retval -1 processing failed
|
||||||
*/
|
*/
|
||||||
STATIC int8_t matchFunctionStart(cfunction_t *aFunction, char *aString, size_t aSize)
|
STATIC int8_t matchPrefix(void *aElement, celement_type_t aElementType, char *aString, size_t aSize)
|
||||||
{
|
{
|
||||||
regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS];
|
regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS];
|
||||||
char *temp = NULL;
|
char *temp = NULL;
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
|
char **prefix = NULL;
|
||||||
|
char **type = NULL;
|
||||||
|
|
||||||
if (NULL == aFunction || NULL == aString || 0 == aSize)
|
if (NULL == aElement || NULL == aString || 0 == aSize)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (aElementType)
|
||||||
|
{
|
||||||
|
case CELEMENT_TYPE_VARIABLE:
|
||||||
|
{
|
||||||
|
prefix = &((cfile_variable_t*) aElement)->prefix;
|
||||||
|
type = &((cfile_variable_t*) aElement)->dataType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CELEMENT_TYPE_FUNCTION:
|
||||||
|
{
|
||||||
|
prefix = &((cfunction_t*) aElement)->prefix;
|
||||||
|
type = &((cfunction_t*) aElement)->dataType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
temp = (char*) xmalloc(aSize + 1);
|
temp = (char*) xmalloc(aSize + 1);
|
||||||
if (NULL == temp)
|
if (NULL == temp)
|
||||||
{
|
{
|
||||||
@@ -187,21 +193,36 @@ STATIC int8_t matchFunctionStart(cfunction_t *aFunction, char *aString, size_t a
|
|||||||
}
|
}
|
||||||
*(end + 1) = '\0';
|
*(end + 1) = '\0';
|
||||||
|
|
||||||
|
if (CELEMENT_TYPE_VARIABLE == aElementType)
|
||||||
|
{
|
||||||
|
((cfunction_t*) aElement)->type = CFUNCTION_TYPE_REGULAR;
|
||||||
|
}
|
||||||
|
|
||||||
if (0 == regexec(®Xprefix, temp, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, 0))
|
if (0 == regexec(®Xprefix, temp, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, 0))
|
||||||
{
|
{
|
||||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
||||||
{
|
{
|
||||||
xmallocStrlcpy(&aFunction->prefix, &temp[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
xmallocStrlcpy(prefix, &temp[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||||
checkFunctionType(aFunction);
|
if (CELEMENT_TYPE_VARIABLE == aElementType)
|
||||||
|
{
|
||||||
|
if (*prefix && NULL != strstr(*prefix, CPARS_PREFIX_EXTERN_S))
|
||||||
|
{
|
||||||
|
((cfunction_t*) aElement)->type = CFUNCTION_TYPE_EXTERN;
|
||||||
|
}
|
||||||
|
else if (*prefix && NULL != strstr(*prefix, CPARS_PREFIX_STATIC_S))
|
||||||
|
{
|
||||||
|
((cfunction_t*) aElement)->type = CFUNCTION_TYPE_STATIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 2))
|
if (XREGEX_IS_MATCHGROUP(matchGroup, 2))
|
||||||
{
|
{
|
||||||
xmallocStrlcpy(&aFunction->dataType, &temp[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
xmallocStrlcpy(type, &temp[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xmallocStrlcpy(&aFunction->dataType, temp, strlen(temp));
|
xmallocStrlcpy(type, temp, strlen(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(temp);
|
free(temp);
|
||||||
@@ -489,160 +510,50 @@ STATIC int8_t evaluateParameter(char *aParameter, cfunction_t *aFunction)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if(0)
|
STATIC int8_t cfile_parser_evaluateExpression(char *aExpression, cfile_t *aCfile)
|
||||||
/*!
|
|
||||||
* @brief Process a string (e.g. from getline()) if it is a single or multiple line function definition
|
|
||||||
* @todo closing parenthesis within parameter list will break the detection
|
|
||||||
* @retval -1 Invalid regular expressions
|
|
||||||
* @retval -2 Given String not a function
|
|
||||||
* @retval 0 function evaluated
|
|
||||||
*/
|
|
||||||
STATIC cfunction_t* cfile_parser_evaluateLine1(char *aLine)
|
|
||||||
{
|
{
|
||||||
const size_t maxGroup = CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS;
|
char *tempChar = NULL;
|
||||||
regmatch_t matchGroup[maxGroup];
|
cfile_variable_t *variable = NULL;
|
||||||
bool functionEnd = false;
|
cfunction_t *function = NULL;
|
||||||
cfunction_type_t tempFunctionType = CFUNCTION_TYPE_UNDEF;
|
regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS];
|
||||||
|
|
||||||
if (0 != removeCcomments(aLine))
|
if (NULL == aExpression || NULL == aCfile)
|
||||||
{
|
{
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
|
||||||
if (0 != cBlockRemoval(aLine, "{", "}", &cfile_parser_removeBraceHelper, false, false))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfile_parser_functionLine)
|
if (0 == regexec(®Xfunction, aExpression, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup,
|
||||||
|
REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
|
||||||
{
|
{
|
||||||
if (0 == regexec(®XmlEnd, aLine, maxGroup, matchGroup, REG_NOTEOL))
|
printMatchGroup(aExpression, matchGroup);
|
||||||
|
function = cfunction_addNewFunction(&aCfile->functions);
|
||||||
|
(void) matchPrefix(function, CELEMENT_TYPE_FUNCTION, &aExpression[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||||
|
checkFunctionType(function, aExpression);
|
||||||
|
xmallocStrlcpy(&function->name, &aExpression[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||||
|
if (XREGEX_IS_MATCHGROUP(matchGroup, 3))
|
||||||
{
|
{
|
||||||
tempFunctionType = CFUNCTION_TYPE_REGULAR;
|
xmallocStrlcat(&tempChar, &aExpression[matchGroup[3].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 3));
|
||||||
DEBUG_LOG_APPEND(1, "[ mle]");
|
if (NULL != tempChar)
|
||||||
functionEnd = true;
|
|
||||||
}
|
|
||||||
else if (0 == regexec(®XmlProto, aLine, maxGroup, matchGroup, REG_NOTEOL))
|
|
||||||
{
|
|
||||||
tempFunctionType = CFUNCTION_TYPE_PROTO;
|
|
||||||
DEBUG_LOG_APPEND(1, "[ mlp]");
|
|
||||||
functionEnd = true;
|
|
||||||
}
|
|
||||||
else if (0 == regexec(®XmlPar, aLine, maxGroup, matchGroup, REG_NOTEOL))
|
|
||||||
{
|
|
||||||
DEBUG_LOG_APPEND(1, "[ ml+]");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUG_LOG_APPEND(1, "[ na ]");
|
|
||||||
tempFunctionType = CFUNCTION_TYPE_UNDEF;
|
|
||||||
functionEnd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
++cfile_parser_functionLine;
|
|
||||||
}
|
|
||||||
else if (0 == regexec(®Xsl, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
|
|
||||||
{
|
|
||||||
tempFunctionType = CFUNCTION_TYPE_REGULAR;
|
|
||||||
DEBUG_LOG_APPEND(1, "[ sl ]");
|
|
||||||
}
|
|
||||||
else if (0 == regexec(®XmlStart, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
|
|
||||||
{
|
|
||||||
tempFunctionType = CFUNCTION_TYPE_REGULAR;
|
|
||||||
DEBUG_LOG_APPEND(1, "[ mls]");
|
|
||||||
++cfile_parser_functionLine;
|
|
||||||
}
|
|
||||||
else if (0 == regexec(®Xproto, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
|
|
||||||
{
|
|
||||||
tempFunctionType = CFUNCTION_TYPE_PROTO;
|
|
||||||
DEBUG_LOG_APPEND(1, "[prot]");
|
|
||||||
}
|
|
||||||
else if (0 == regexec(®X, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
|
|
||||||
{
|
|
||||||
tempFunctionType = CFUNCTION_TYPE_UNDEF;
|
|
||||||
DEBUG_LOG_APPEND(1, "[ fuX]");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#if (0)
|
|
||||||
{
|
|
||||||
uint8_t i = 0;
|
|
||||||
char match[1024] =
|
|
||||||
{ 0};
|
|
||||||
|
|
||||||
for (i = 0; i < maxGroup && 0 <= matchGroup[i].rm_so; ++i)
|
|
||||||
{
|
|
||||||
if (matchGroup[i].rm_so < matchGroup[i].rm_eo)
|
|
||||||
{
|
{
|
||||||
if (0 < i)
|
evaluateParameter(tempChar, function);
|
||||||
DEBUG_LOG_APPEND(1, " ");
|
|
||||||
DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]: ", i, matchGroup[i].rm_so, matchGroup[i].rm_eo, (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so));
|
|
||||||
strlcpy(match, &aLine[matchGroup[i].rm_so], (size_t) (matchGroup[i].rm_eo - matchGroup[i].rm_so + 1));
|
|
||||||
DEBUG_LOG_APPEND(1, "%s", match);
|
|
||||||
DEBUG_LOG_APPEND(1, "\n");
|
|
||||||
}
|
}
|
||||||
}
|
xfree((void**) &tempChar);
|
||||||
if (functionEnd)
|
|
||||||
{
|
|
||||||
cfile_parser_functionLine = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
else if (0 == regexec(®Xvariable, aExpression, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup,
|
||||||
switch (cfile_parser_functionLine)
|
REG_NOTEOL) && XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
||||||
{
|
{
|
||||||
case 0: // single line function definition
|
printMatchGroup(aExpression, matchGroup);
|
||||||
case 1:// first line of multi line function definition
|
variable = cfile_newVariable(&aCfile->variables);
|
||||||
|
if (variable)
|
||||||
{
|
{
|
||||||
// TODO multiple functions in one line
|
(void) matchPrefix(variable, CELEMENT_TYPE_VARIABLE, &aExpression[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||||
cfile_parser_function = cfunction_newFunction();
|
xmallocStrlcpy(&variable->name, &aExpression[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||||
cfile_parser_function->type = tempFunctionType;
|
|
||||||
matchFunctionStart(cfile_parser_function, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
|
||||||
xmallocStrlcpy(&cfile_parser_function->name, &aLine[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
|
||||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 3))
|
|
||||||
{
|
|
||||||
xmallocStrlcat(&cfile_parser_parameterStorage, &aLine[matchGroup[3].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 3));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: // further lines
|
|
||||||
{
|
|
||||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
|
||||||
{
|
|
||||||
xmallocStrlcat(&cfile_parser_parameterStorage, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
|
||||||
}
|
|
||||||
if (functionEnd)
|
|
||||||
{
|
|
||||||
if (CFUNCTION_TYPE_UNDEF == tempFunctionType)
|
|
||||||
{
|
|
||||||
cfunction_freeFunction(&cfile_parser_function);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cfile_parser_function->type = tempFunctionType;
|
|
||||||
checkFunctionType(cfile_parser_function);
|
|
||||||
}
|
|
||||||
cfile_parser_functionLine = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return evaluated function
|
return 0;
|
||||||
if (0 == cfile_parser_functionLine)
|
|
||||||
{
|
|
||||||
evaluateParameter(cfile_parser_parameterStorage, cfile_parser_function);
|
|
||||||
free(cfile_parser_parameterStorage);
|
|
||||||
cfile_parser_parameterStorage = NULL;
|
|
||||||
cfunction_t *funTemp = cfile_parser_function;
|
|
||||||
cfile_parser_function = NULL;
|
|
||||||
return funTemp;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
STATIC int8_t cfile_parser_evaluateLine(uint32_t aNumber, char *aLine, cfile_t *aCfile)
|
STATIC int8_t cfile_parser_evaluateLine(uint32_t aNumber, char *aLine, cfile_t *aCfile)
|
||||||
{
|
{
|
||||||
@@ -650,16 +561,26 @@ STATIC int8_t cfile_parser_evaluateLine(uint32_t aNumber, char *aLine, cfile_t *
|
|||||||
int8_t result = 0;
|
int8_t result = 0;
|
||||||
static char *match = NULL;
|
static char *match = NULL;
|
||||||
static uint8_t depth = 0;
|
static uint8_t depth = 0;
|
||||||
|
char *tempMatch = NULL;
|
||||||
|
|
||||||
regex_t *matchStart = ®XExpressionStart;
|
regex_t *matchStart = ®XExpressionStart;
|
||||||
regex_t *matchEnd = ®XExpressionEnd;
|
regex_t *matchEnd = ®XExpressionEnd;
|
||||||
|
|
||||||
while (position)
|
while (position)
|
||||||
{
|
{
|
||||||
|
if (NULL != (tempMatch = strstr(position, "#include")))
|
||||||
|
{
|
||||||
|
// TODO save include information
|
||||||
|
DEBUG_LOG_APPEND(1, "[ Re %04u] Works %zu %s\n", aNumber, strlen(tempMatch), tempMatch);
|
||||||
|
position = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
result = regExWorker(&match, &position, matchStart, matchEnd, &depth, false);
|
result = regExWorker(&match, &position, matchStart, matchEnd, &depth, false);
|
||||||
if (match && 0 == result && 0 == depth)
|
if (match && 0 == result && 0 == depth)
|
||||||
{
|
{
|
||||||
DEBUG_LOG_APPEND(1, "[ Re %04u] Works %zu %s\n", aNumber, strlen(match), match);
|
DEBUG_LOG_APPEND(1, "[ Re %04u] Works %zu %s\n", aNumber, strlen(match), match);
|
||||||
|
// Evaluate C expression
|
||||||
|
(void) cfile_parser_evaluateExpression(match, aCfile);
|
||||||
xfree((void**) &match);
|
xfree((void**) &match);
|
||||||
}
|
}
|
||||||
if (0 > result)
|
if (0 > result)
|
||||||
|
@@ -21,20 +21,20 @@
|
|||||||
#define CPARS_COMMENT_BLOCK_START "/*"
|
#define CPARS_COMMENT_BLOCK_START "/*"
|
||||||
#define CPARS_COMMENT_BLOCK_END "*/"
|
#define CPARS_COMMENT_BLOCK_END "*/"
|
||||||
|
|
||||||
#define FUNCTION_BASE "^[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]*)[[:blank:]]*\\([[:blank:]]*([^\r\\)]*)"
|
#define CPARS_PROTOTYPE_END_C ';'
|
||||||
#define FUNCTION_SL FUNCTION_BASE "\\)[^;]*$"
|
#define CPARS_PREFIX_STATIC_S "static"
|
||||||
#define FUNCTION_ML_SOF FUNCTION_BASE "[\r]*$"
|
#define CPARS_PREFIX_EXTERN_S "extern"
|
||||||
#define FUNCTION_ML_PAR "^[[:blank:]]*([^\r]*)"
|
|
||||||
#define FUNCTION_ML_END FUNCTION_ML_PAR "\\)[^;]*$"
|
|
||||||
#define FUNCTION_ML_PROTO FUNCTION_ML_PAR "\\).*[[:blank:]]*;"
|
|
||||||
#define FUNCTION_PROTO FUNCTION_BASE "\\).*[[:blank:]]*;"
|
|
||||||
|
|
||||||
#define CPARS_REGEX_VARIABLE "^[[:blank:]]*([ _\\*[:alnum:]]*)[[:blank:]]*[;=]"
|
#define CPARS_EXPRESSION_BASE "^[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]+)"
|
||||||
|
|
||||||
|
#define FUNCTION_BASE CPARS_EXPRESSION_BASE "[[:blank:]]*\\([[:blank:]]*"
|
||||||
|
#define CPARS_REGEX_FUNCTION FUNCTION_BASE "(.*)\\)[[:blank:]\\{\\};]+[[:blank:]]*"
|
||||||
|
#define CPARS_REGEX_VARIABLE CPARS_EXPRESSION_BASE "[[:blank:]]*[;=]"
|
||||||
#define CPARS_REGEX_PARAMETER "[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]*)[[:blank:]]*"
|
#define CPARS_REGEX_PARAMETER "[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]*)[[:blank:]]*"
|
||||||
#define CPARS_REGEX_PREFIX "(extern|EXTERN|static|STATIC|volatile|near|far)[[:blank:]]+([^\\*]*\\**)"
|
#define CPARS_REGEX_PREFIX "("CPARS_PREFIX_EXTERN_S"|EXTERN|"CPARS_PREFIX_STATIC_S"|STATIC|volatile|near|far)[[:blank:]]*(.*)"
|
||||||
|
|
||||||
#define CPARS_EXPRESSION_START "^[[:blank:]]*([A-Za-z\\_][\\_\\*[:alnum:]]*)"
|
#define CPARS_EXPRESSION_START "^[[:blank:]]*([A-Za-z\\_][\\_\\*[:alnum:]]*)"
|
||||||
#define CPARS_EXPRESSION_END "[[:blank:]]*([\\};]+)"
|
#define CPARS_EXPRESSION_END "[[:blank:]]*([\\};]+)"
|
||||||
|
|
||||||
#define CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup) (XREGEX_IS_MATCHGROUP(matchGroup, 1) && XREGEX_IS_MATCHGROUP(matchGroup, 2))
|
#define CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup) (XREGEX_IS_MATCHGROUP(matchGroup, 1) && XREGEX_IS_MATCHGROUP(matchGroup, 2))
|
||||||
|
|
||||||
|
@@ -16,39 +16,35 @@
|
|||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "cfunction_if.h"
|
#include "cfunction_if.h"
|
||||||
|
|
||||||
cfunction_t* cfunction_newFunction()
|
cfunction_t* cfunction_addNewFunction(cfunction_list_t *aList)
|
||||||
{
|
{
|
||||||
cfunction_t *new = NULL;
|
cfunction_t *new = NULL;
|
||||||
|
|
||||||
|
if (NULL == aList)
|
||||||
|
{
|
||||||
|
perror("Null pointer");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
new = (cfunction_t*) xmalloc(sizeof(cfunction_t));
|
new = (cfunction_t*) xmalloc(sizeof(cfunction_t));
|
||||||
memset(new, 0, sizeof(cfunction_t));
|
memset(new, 0, sizeof(cfunction_t));
|
||||||
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t cfunction_addFunction(cfunction_list_t *aList, cfunction_t *aNew)
|
|
||||||
{
|
|
||||||
if (NULL == aList || NULL == aNew)
|
|
||||||
{
|
|
||||||
perror("Null pointer");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL == aList->head)
|
if (NULL == aList->head)
|
||||||
{
|
{
|
||||||
aList->head = aNew;
|
aList->amount = 0;
|
||||||
aList->current = aNew;
|
aList->head = new;
|
||||||
|
aList->current = new;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aList->current->next = aNew;
|
aList->current->next = new;
|
||||||
aList->current = aNew;
|
aList->current = new;
|
||||||
}
|
}
|
||||||
|
++aList->amount;
|
||||||
return 0;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfunction_parameter_t* cfunction_newParameter(struct _CFUNCTION_PARAMETER_LIST_T *aList)
|
cfunction_parameter_t* cfunction_newParameter(cfunction_parameterList_t *aList)
|
||||||
{
|
{
|
||||||
cfunction_parameter_t *new = NULL;
|
cfunction_parameter_t *new = NULL;
|
||||||
|
|
||||||
@@ -63,6 +59,7 @@ cfunction_parameter_t* cfunction_newParameter(struct _CFUNCTION_PARAMETER_LIST_T
|
|||||||
|
|
||||||
if (NULL == aList->head)
|
if (NULL == aList->head)
|
||||||
{
|
{
|
||||||
|
aList->amount = 0;
|
||||||
aList->head = new;
|
aList->head = new;
|
||||||
aList->current = new;
|
aList->current = new;
|
||||||
}
|
}
|
||||||
@@ -162,7 +159,7 @@ void cfunction_printList(cfunction_list_t *aList)
|
|||||||
while (work)
|
while (work)
|
||||||
{
|
{
|
||||||
param = work->parameter.head;
|
param = work->parameter.head;
|
||||||
printf("[ cfu]%d:%s %s %s [%d] ", work->type, work->prefix, work->dataType, work->name, work->parameter.amount);
|
printf("[ cfu]%d:<%s> (%s) %s [%d] ", work->type, work->prefix, work->dataType, work->name, work->parameter.amount);
|
||||||
while (param)
|
while (param)
|
||||||
{
|
{
|
||||||
printf("%s|%s,", param->type, param->name);
|
printf("%s|%s,", param->type, param->name);
|
||||||
@@ -170,6 +167,6 @@ void cfunction_printList(cfunction_list_t *aList)
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
work = work->next;
|
work = work->next;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
printf(" %d Functions\n", aList->amount);
|
||||||
}
|
}
|
||||||
|
@@ -18,9 +18,10 @@
|
|||||||
typedef enum _CFUNCTION_TYPE_T
|
typedef enum _CFUNCTION_TYPE_T
|
||||||
{
|
{
|
||||||
CFUNCTION_TYPE_UNDEF = 0, /*!< @brief undefined */
|
CFUNCTION_TYPE_UNDEF = 0, /*!< @brief undefined */
|
||||||
CFUNCTION_TYPE_REGULAR = 1, /*!< @brief Regular c function definition */
|
CFUNCTION_TYPE_REGULAR = 1, /*!< @brief Regular C function definition */
|
||||||
CFUNCTION_TYPE_STATIC = 2, /*!< @brief Static c function definition */
|
CFUNCTION_TYPE_STATIC = 2, /*!< @brief Static C function definition */
|
||||||
CFUNCTION_TYPE_PROTO = 3, /*!< @brief Prototype c function definition */
|
CFUNCTION_TYPE_PROTO = 3, /*!< @brief Prototype C function definition */
|
||||||
|
CFUNCTION_TYPE_EXTERN = 4, /*!< @brief External C function definition */
|
||||||
CFUNCTION_TYPE_LAST_ENUM
|
CFUNCTION_TYPE_LAST_ENUM
|
||||||
} cfunction_type_t;
|
} cfunction_type_t;
|
||||||
|
|
||||||
@@ -54,17 +55,18 @@ typedef struct _CFUNCTION_T
|
|||||||
/*! @brief Dynamic function list */
|
/*! @brief Dynamic function list */
|
||||||
typedef struct _CFUNCTION_LIST_T
|
typedef struct _CFUNCTION_LIST_T
|
||||||
{
|
{
|
||||||
|
uint16_t amount;
|
||||||
cfunction_t *head;
|
cfunction_t *head;
|
||||||
cfunction_t *current;
|
cfunction_t *current;
|
||||||
} cfunction_list_t;
|
} cfunction_list_t;
|
||||||
|
|
||||||
#define CFUNCTION_LIST_DEFAULT {\
|
#define CFUNCTION_LIST_DEFAULT {\
|
||||||
|
.amount = 0, \
|
||||||
.head = NULL, \
|
.head = NULL, \
|
||||||
.current = NULL }
|
.current = NULL }
|
||||||
|
|
||||||
cfunction_t* cfunction_newFunction();
|
cfunction_t* cfunction_addNewFunction(cfunction_list_t *aList);
|
||||||
int8_t cfunction_addFunction(cfunction_list_t *aList, cfunction_t *aNew);
|
cfunction_parameter_t* cfunction_newParameter(cfunction_parameterList_t *aList);
|
||||||
cfunction_parameter_t* cfunction_newParameter(struct _CFUNCTION_PARAMETER_LIST_T *aList);
|
|
||||||
int8_t cfunction_freeFunction(cfunction_t **aFunction);
|
int8_t cfunction_freeFunction(cfunction_t **aFunction);
|
||||||
int8_t cfunction_freeList(cfunction_list_t *aList);
|
int8_t cfunction_freeList(cfunction_list_t *aList);
|
||||||
void cfunction_printList(cfunction_list_t *aList);
|
void cfunction_printList(cfunction_list_t *aList);
|
||||||
|
@@ -311,6 +311,10 @@ int stubser_createStub(char *path, char* aNoSuffix, char *aOutput)
|
|||||||
}
|
}
|
||||||
printf(STUB_CONSOLE_CREATE_OK_S1, fileName);
|
printf(STUB_CONSOLE_CREATE_OK_S1, fileName);
|
||||||
|
|
||||||
|
#if isDebugLevel(1)
|
||||||
|
cfile_print(&cFile);
|
||||||
|
#endif
|
||||||
|
|
||||||
end_stubser_createStub: // function end target
|
end_stubser_createStub: // function end target
|
||||||
|
|
||||||
cfile_free(&cFile);
|
cfile_free(&cFile);
|
||||||
|
Reference in New Issue
Block a user