88 lines
1.8 KiB
C
88 lines
1.8 KiB
C
|
|
|
||
|
|
#include "argument.h"
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
int argument_determineDatatypeOfArgument( char * argumentDeclaration, struct array * variables ) {
|
||
|
|
|
||
|
|
|
||
|
|
// int
|
||
|
|
if( text_isValidNumber( argumentDeclaration ) == 1 ) {
|
||
|
|
|
||
|
|
return -1;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// single quote
|
||
|
|
if( strchr( argumentDeclaration, 39) != NULL ) {
|
||
|
|
|
||
|
|
return -2;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// text
|
||
|
|
if( strchr( argumentDeclaration, '"') != NULL ) {
|
||
|
|
|
||
|
|
return -2;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
struct variable * variableInstance = variable_getByName( variables, argumentDeclaration );
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
if( strcmp( variableInstance->datatype, "this_variable_is_missing" ) == 0 ) {
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
if( strcmp( variableInstance->datatype, "int" ) == 0 ) {
|
||
|
|
|
||
|
|
return -1;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if( (strcmp(variableInstance->datatype, "char" ) == 0) && variableInstance->isPointer == 1 ) {
|
||
|
|
|
||
|
|
return -2;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
//printf(" -----------check if this is an variable: %s %s\n\n", argumentDeclaration, variableInstance->datatype);
|
||
|
|
|
||
|
|
struct class * classInstance = application_getClassByClassName( allClasses, variableInstance->datatype );
|
||
|
|
|
||
|
|
if( classInstance == NULL ) {
|
||
|
|
|
||
|
|
printf(ANSI_COLOR_RED "\n\n\n\n ERROR class '%s' does not exist!!, The file containing the class '%s' is not included.\n\n\n\n" ANSI_COLOR_RESET, variableInstance->datatype, variableInstance->datatype );
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
return ( int ) classInstance->classIndex;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
struct array * argument_getArgumentDatatypes( struct array * arguments, struct array * variables ) {
|
||
|
|
|
||
|
|
int argumentCount = array_length( arguments );
|
||
|
|
|
||
|
|
struct array * argumentDatatypes = array_new();
|
||
|
|
|
||
|
|
for (int i = 0; i < argumentCount; ++i)
|
||
|
|
{
|
||
|
|
|
||
|
|
char * currentArgument = text_removeWhiteSpaces( array_get( arguments, i ) );
|
||
|
|
|
||
|
|
uintptr_t datatype = argument_determineDatatypeOfArgument( currentArgument, variables );
|
||
|
|
|
||
|
|
|
||
|
|
array_add( argumentDatatypes, (void *) datatype );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
return argumentDatatypes;
|
||
|
|
|
||
|
|
}
|