- processing of function parameter added (first tests successful)
- next stage -> constructing stub files (.c and .h)
This commit is contained in:
@@ -42,6 +42,7 @@ STATIC regex_t regXmlEnd;
|
||||
STATIC regex_t regXmlProto;
|
||||
STATIC regex_t regXproto;
|
||||
STATIC regex_t regXprefix;
|
||||
STATIC regex_t regXparameter;
|
||||
|
||||
int8_t cfile_parser_init()
|
||||
{
|
||||
@@ -85,6 +86,11 @@ int8_t cfile_parser_init()
|
||||
perror("Error regex\n");
|
||||
return -1;
|
||||
}
|
||||
if (0 > regcomp(®Xparameter, CPARS_REGEX_PARAMETER, (REG_EXTENDED)))
|
||||
{
|
||||
perror("Error regex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfile_parser_initialized = true;
|
||||
return 0;
|
||||
@@ -101,7 +107,7 @@ STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup)
|
||||
{
|
||||
if (aMatchGroup[i].rm_so < aMatchGroup[i].rm_eo)
|
||||
{
|
||||
printf("[%02d](%.3ld - %.3ld)[%03d]: ", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo, (int) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so));
|
||||
printf("[%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));
|
||||
printf("%s", match);
|
||||
printf("\n");
|
||||
@@ -161,17 +167,17 @@ STATIC int8_t matchFunctionStart(cfunction_t *aFunction, char *aString, size_t a
|
||||
{
|
||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
||||
{
|
||||
cfunction_newDetail(&aFunction->prefix, &temp[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
xmallocStrlcpy(&aFunction->prefix, &temp[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
checkFunctionType(aFunction);
|
||||
}
|
||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 2))
|
||||
{
|
||||
cfunction_newDetail(&aFunction->dataType, &temp[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||
xmallocStrlcpy(&aFunction->dataType, &temp[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cfunction_newDetail(&aFunction->dataType, temp, strlen(temp));
|
||||
xmallocStrlcpy(&aFunction->dataType, temp, strlen(temp));
|
||||
}
|
||||
|
||||
free(temp);
|
||||
@@ -411,6 +417,48 @@ STATIC int8_t removeCcomments(char *aLine)
|
||||
return cBlockRemoval(aLine, CPARS_COMMENT_BLOCK_START, CPARS_COMMENT_BLOCK_END, &helper, true);
|
||||
}
|
||||
|
||||
STATIC int8_t evaluateParameter(char **aParameter, cfunction_t *aFunction)
|
||||
{
|
||||
char *token = NULL;
|
||||
regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS];
|
||||
cfunction_parameter_t *tempParameter = NULL;
|
||||
|
||||
if (NULL == aParameter || NULL == *aParameter || NULL == aFunction)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
token = strtok(*aParameter, ",");
|
||||
while (token)
|
||||
{
|
||||
if (0 == regexec(®Xparameter, token, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, 0))
|
||||
{
|
||||
tempParameter = cfunction_newParameter(&aFunction->parameter);
|
||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
||||
{
|
||||
xmallocStrlcpy(&tempParameter->type, &token[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
if (NULL != tempParameter->type)
|
||||
{
|
||||
xStringTrim(tempParameter->type, XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
}
|
||||
}
|
||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 2))
|
||||
{
|
||||
xmallocStrlcpy(&tempParameter->name, &token[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||
if (NULL != tempParameter->name)
|
||||
{
|
||||
xStringTrim(tempParameter->name, XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
token = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
free(*aParameter);
|
||||
*aParameter = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @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
|
||||
@@ -420,12 +468,12 @@ STATIC int8_t removeCcomments(char *aLine)
|
||||
*/
|
||||
STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
|
||||
{
|
||||
static char *parameterStorage = NULL;
|
||||
static uint32_t braceHelper = 0;
|
||||
const size_t maxGroup = CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS;
|
||||
regmatch_t matchGroup[maxGroup];
|
||||
bool functionEnd = false;
|
||||
cfunction_type_t tempFunctionType = CFUNCTION_TYPE_UNDEF;
|
||||
cfunction_parameter_t *tempParameter = NULL;
|
||||
|
||||
if (0 != removeCcomments(aLine))
|
||||
{
|
||||
@@ -516,24 +564,22 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
|
||||
case 0: // single line function definition
|
||||
case 1: // first line of multi line function definition
|
||||
{
|
||||
// TODO multiple functions in one line
|
||||
cfile_parser_function = cfunction_newFunction();
|
||||
cfile_parser_function->type = tempFunctionType;
|
||||
matchFunctionStart(cfile_parser_function, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
cfunction_newDetail(&cfile_parser_function->name, &aLine[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||
xmallocStrlcpy(&cfile_parser_function->name, &aLine[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2));
|
||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 3))
|
||||
{
|
||||
tempParameter = cfunction_newParameter(&cfile_parser_function->parameter);
|
||||
cfunction_newDetail(&tempParameter->type, &aLine[matchGroup[3].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 3));
|
||||
xmallocStrlcat(¶meterStorage, &aLine[matchGroup[3].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 3));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: // further lines
|
||||
{
|
||||
// TODO process parameter
|
||||
if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
|
||||
{
|
||||
tempParameter = cfunction_newParameter(&cfile_parser_function->parameter);
|
||||
cfunction_newDetail(&tempParameter->type, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
xmallocStrlcat(¶meterStorage, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
|
||||
}
|
||||
if (functionEnd)
|
||||
{
|
||||
@@ -555,6 +601,7 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
|
||||
// return evaluated function
|
||||
if (0 == cfile_parser_functionLine)
|
||||
{
|
||||
evaluateParameter(¶meterStorage, cfile_parser_function);
|
||||
cfunction_t *funTemp = cfile_parser_function;
|
||||
cfile_parser_function = NULL;
|
||||
return funTemp;
|
||||
|
Reference in New Issue
Block a user