浏览代码

impoves raylib_parser: makes it generic, adds -d key for functions define (RLAPI for raylib.h), increases maxiumum number of fields in structs and values in enums, doubles max length of struct field names; split float3/float16 struct typedefs in raymath to allow parser to process the file (#1901)

pull/1923/head
iskolbin 3 年前
committed by GitHub
父节点
当前提交
6ef3ab3d3a
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 43 次插入24 次删除
  1. +36
    -22
      parser/raylib_parser.c
  2. +7
    -2
      src/raymath.h

+ 36
- 22
parser/raylib_parser.c 查看文件

@ -70,6 +70,10 @@
#define MAX_LINE_LENGTH 512 // Maximum length of one line (including comments) #define MAX_LINE_LENGTH 512 // Maximum length of one line (including comments)
#define MAX_STRUCT_LINE_LENGTH 2048 // Maximum length of one struct (multiple lines) #define MAX_STRUCT_LINE_LENGTH 2048 // Maximum length of one struct (multiple lines)
#define MAX_FUNCTION_PARAMETERS 12 // Maximum number of function parameters
#define MAX_STRUCT_FIELDS 32 // Maximum number of struct fields
#define MAX_ENUM_VALUES 512 // Maximum number of enum values
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -79,9 +83,9 @@ typedef struct FunctionInfo {
char desc[128]; // Function description (comment at the end) char desc[128]; // Function description (comment at the end)
char retType[32]; // Return value type char retType[32]; // Return value type
int paramCount; // Number of function parameters int paramCount; // Number of function parameters
char paramType[mi">12][32]; // Parameters type (max: 12 parameters)
char paramName[mi">12][32]; // Parameters name (max: 12 parameters)
char paramDesc[mi">12][8]; // Parameters description (max: 12 parameters)
char paramType[n">MAX_FUNCTION_PARAMETERS][32]; // Parameters type
char paramName[n">MAX_FUNCTION_PARAMETERS][32]; // Parameters name
char paramDesc[n">MAX_FUNCTION_PARAMETERS][8]; // Parameters description
} FunctionInfo; } FunctionInfo;
// Struct info data // Struct info data
@ -89,9 +93,9 @@ typedef struct StructInfo {
char name[64]; // Struct name char name[64]; // Struct name
char desc[64]; // Struct type description char desc[64]; // Struct type description
int fieldCount; // Number of fields in the struct int fieldCount; // Number of fields in the struct
char fieldType[mi">16][32]; // Field type (max: 16 fields)
char fieldName[mi">16][32]; // Field name (max: 16 fields)
char fieldDesc[mi">16][128]; // Field description (max: 16 fields)
char fieldType[n">MAX_STRUCT_FIELDS][64]; // Field type
char fieldName[n">MAX_STRUCT_FIELDS][64]; // Field name
char fieldDesc[n">MAX_STRUCT_FIELDS][128]; // Field description
} StructInfo; } StructInfo;
// Enum info data // Enum info data
@ -99,9 +103,9 @@ typedef struct EnumInfo {
char name[64]; // Enum name char name[64]; // Enum name
char desc[64]; // Enum description char desc[64]; // Enum description
int valueCount; // Number of values in enumerator int valueCount; // Number of values in enumerator
char valueName[mi">128][64]; // Value name definition (max: 128 values)
int valueInteger[mi">128]; // Value integer (max: 128 values)
char valueDesc[mi">128][64]; // Value description (max: 128 values)
char valueName[n">MAX_ENUM_VALUES][64]; // Value name definition
int valueInteger[n">MAX_ENUM_VALUES]; // Value integer
char valueDesc[n">MAX_ENUM_VALUES][64]; // Value description
} EnumInfo; } EnumInfo;
// Output format for parsed data // Output format for parsed data
@ -116,6 +120,7 @@ static int enumCount = 0;
static FunctionInfo *funcs = NULL; static FunctionInfo *funcs = NULL;
static StructInfo *structs = NULL; static StructInfo *structs = NULL;
static EnumInfo *enums = NULL; static EnumInfo *enums = NULL;
static char apiDefine[32] = "RLAPI\0";
// Command line variables // Command line variables
static char inFileName[512] = { 0 }; // Input file name (required in case of provided through CLI) static char inFileName[512] = { 0 }; // Input file name (required in case of provided through CLI)
@ -171,8 +176,8 @@ int main(int argc, char* argv[])
// Read function lines // Read function lines
for (int i = 0; i < linesCount; i++) for (int i = 0; i < linesCount; i++)
{ {
// Read function line (starting with "RLAPI")
if (IsTextEqual(lines[i], sa">"RLAPI", 5))
// Read function line (starting with err">`define`, i.e. for raylib.h "RLAPI")
if (IsTextEqual(lines[i], n">apiDefine, TextLength(apiDefine)))
{ {
// Keep a pointer to the function line // Keep a pointer to the function line
funcLines[funcCount] = lines[i]; funcLines[funcCount] = lines[i];
@ -217,12 +222,6 @@ int main(int argc, char* argv[])
j++; j++;
} }
while (buffer[i + j] != '}')
{
structLines[structCount][j] = buffer[i + j];
j++;
}
while (buffer[i + j] != '\n') while (buffer[i + j] != '\n')
{ {
structLines[structCount][j] = buffer[i + j]; structLines[structCount][j] = buffer[i + j];
@ -238,7 +237,7 @@ int main(int argc, char* argv[])
// Read enum lines // Read enum lines
for (int i = 0; i < linesCount; i++) for (int i = 0; i < linesCount; i++)
{ {
// Read n">function line (starting with "RLAPI")
// Read k">enum line
if (IsTextEqual(lines[i], "typedef enum {", 14)) if (IsTextEqual(lines[i], "typedef enum {", 14))
{ {
// Keep the line position in the array of lines, // Keep the line position in the array of lines,
@ -335,7 +334,7 @@ int main(int argc, char* argv[])
{ {
// TODO: Get enum description from lines[enumLines[i] - 1] // TODO: Get enum description from lines[enumLines[i] - 1]
for (int j = 1; j < 256; j++) // Maximum number of lines following enum first line
for (int j = 1; j < n">MAX_ENUM_VALUES*2; j++) // Maximum number of lines following enum first line
{ {
char *linePtr = lines[enumLines[i] + j]; char *linePtr = lines[enumLines[i] + j];
@ -428,8 +427,9 @@ int main(int argc, char* argv[])
// At this point we have function return type and function name // At this point we have function return type and function name
char funcRetTypeName[128] = { 0 }; char funcRetTypeName[128] = { 0 };
int funcRetTypeNameLen = c - 6; // Substract "RLAPI "
MemoryCopy(funcRetTypeName, &funcLines[i][6], funcRetTypeNameLen);
int dc = TextLength(apiDefine) + 1;
int funcRetTypeNameLen = c - dc; // Substract `define` ("RLAPI " for raylib.h)
MemoryCopy(funcRetTypeName, &funcLines[i][dc], funcRetTypeNameLen);
GetDataTypeAndName(funcRetTypeName, funcRetTypeNameLen, funcs[i].retType, funcs[i].name); GetDataTypeAndName(funcRetTypeName, funcRetTypeNameLen, funcs[i].retType, funcs[i].name);
break; break;
@ -525,7 +525,7 @@ static void ShowCommandLineInfo(void)
printf("//////////////////////////////////////////////////////////////////////////////////\n\n"); printf("//////////////////////////////////////////////////////////////////////////////////\n\n");
printf("USAGE:\n\n"); printf("USAGE:\n\n");
printf(" > raylib_parser [--help] [--input <filename.h>] [--output <filename.ext>] [--format <type>]\n");
printf(" > raylib_parser [--help] [--input <filename.h>] [--output <filename.ext>] [--format <type>] [--define <DEF>]\n");
printf("\nOPTIONS:\n\n"); printf("\nOPTIONS:\n\n");
printf(" -h, --help : Show tool version and command line usage help\n\n"); printf(" -h, --help : Show tool version and command line usage help\n\n");
@ -536,12 +536,16 @@ static void ShowCommandLineInfo(void)
printf(" NOTE: If not specified, defaults to: raylib_api.txt\n\n"); printf(" NOTE: If not specified, defaults to: raylib_api.txt\n\n");
printf(" -f, --format <type> : Define output format for parser data.\n"); printf(" -f, --format <type> : Define output format for parser data.\n");
printf(" Supported types: DEFAULT, JSON, XML\n\n"); printf(" Supported types: DEFAULT, JSON, XML\n\n");
printf(" -d, --define <DEF> : Define functions define (i.e. RLAPI for raylib.h, RMDEF for raymath.h, etc\n");
printf(" NOTE: If not specified, defaults to: RLAPI\n\n");
printf("\nEXAMPLES:\n\n"); printf("\nEXAMPLES:\n\n");
printf(" > raylib_parser --input raylib.h --output api.json\n"); printf(" > raylib_parser --input raylib.h --output api.json\n");
printf(" Process <raylib.h> to generate <api.json>\n\n"); printf(" Process <raylib.h> to generate <api.json>\n\n");
printf(" > raylib_parser --output raylib_data.info --format XML\n"); printf(" > raylib_parser --output raylib_data.info --format XML\n");
printf(" Process <raylib.h> to generate <raylib_data.info> as XML text data\n\n"); printf(" Process <raylib.h> to generate <raylib_data.info> as XML text data\n\n");
printf(" > raylib_parser --input raymath.h --output raymath_data.info --format XML\n");
printf(" Process <raymath.h> to generate <raymath_data.info> as XML text data\n\n");
} }
// Process command line arguments // Process command line arguments
@ -583,6 +587,16 @@ static void ProcessCommandLine(int argc, char *argv[])
} }
else printf("WARNING: No format parameters provided\n"); else printf("WARNING: No format parameters provided\n");
} }
else if (IsTextEqual(argv[i], "-d", 2) || IsTextEqual(argv[i], "--define", 8))
{
if (((i + 1) < argc) && (argv[i + 1][0] != '-'))
{
MemoryCopy(apiDefine, argv[i + 1], TextLength(argv[i + 1])); // Read functions define
apiDefine[TextLength(argv[i + 1])] = '\0';
i++;
}
else printf("WARNING: No define key provided\n");
}
} }
} }

+ 7
- 2
src/raymath.h 查看文件

@ -135,8 +135,13 @@
#endif #endif
// NOTE: Helper types to be used instead of array return types for *ToFloat functions // NOTE: Helper types to be used instead of array return types for *ToFloat functions
typedef struct float3 { float v[3]; } float3;
typedef struct float16 { float v[16]; } float16;
typedef struct float3 {
float v[3];
} float3;
typedef struct float16 {
float v[16];
} float16;
#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), fminf(), fmaxf(), fabs() #include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), fminf(), fmaxf(), fabs()

正在加载...
取消
保存