|
@@ -1,49 +1,45 @@
|
|
|
|
+#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
#include "DataType.h"
|
|
#include "DataType.h"
|
|
|
|
|
|
-#define ARRAY_NAME 20
|
|
|
|
-#define ARRAY_FACTOR 10
|
|
|
|
|
|
+#define ARRAY_NAME 30
|
|
|
|
|
|
-static char arrayName[ARRAY_NAME];
|
|
|
|
|
|
+static int typeNameIndex = 0;
|
|
|
|
+static int typeNameSwap = 0;
|
|
|
|
+static char typeName[2][ARRAY_NAME];
|
|
|
|
|
|
-static const char* dtGetBaseName(unsigned int type) {
|
|
|
|
- switch(type) {
|
|
|
|
- case DT_INT: return "int";
|
|
|
|
- case DT_FLOAT: return "float";
|
|
|
|
- case DT_BOOL: return "bool";
|
|
|
|
- default: return "";
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static const char* dtGetArrayName(DataType dt) {
|
|
|
|
- int dimension = dt.pointers;
|
|
|
|
- const char* name = dtGetBaseName(dt.type);
|
|
|
|
- if(name[0] == '\0' || dimension <= 0 || dimension > dtMaxDimensions()) {
|
|
|
|
- return "unknown";
|
|
|
|
- }
|
|
|
|
|
|
+static void dtAppend(const char* s) {
|
|
int index = 0;
|
|
int index = 0;
|
|
- while(index < (ARRAY_NAME - 1) && name[index] != '\0') {
|
|
|
|
- arrayName[index] = name[index];
|
|
|
|
|
|
+ while(typeNameIndex < (ARRAY_NAME - 1) && s[index] != '\0') {
|
|
|
|
+ typeName[typeNameSwap][typeNameIndex] = s[index];
|
|
index++;
|
|
index++;
|
|
|
|
+ typeNameIndex++;
|
|
}
|
|
}
|
|
- while(index < (ARRAY_NAME - 1) && dimension > 0) {
|
|
|
|
- arrayName[index] = '*';
|
|
|
|
- index++;
|
|
|
|
- dimension--;
|
|
|
|
- }
|
|
|
|
- arrayName[index] = '\0';
|
|
|
|
- return arrayName;
|
|
|
|
|
|
+ typeName[typeNameSwap][typeNameIndex] = '\0';
|
|
}
|
|
}
|
|
|
|
|
|
const char* dtGetName(Structs* sts, DataType dt) {
|
|
const char* dtGetName(Structs* sts, DataType dt) {
|
|
|
|
+ typeNameSwap = !typeNameSwap;
|
|
|
|
+ typeNameIndex = 0;
|
|
if(dt.structId > 0) {
|
|
if(dt.structId > 0) {
|
|
- return sts->data[dt.structId - 1].name;
|
|
|
|
- } else if(dt.pointers > 0) {
|
|
|
|
- return dtGetArrayName(dt);
|
|
|
|
|
|
+ dtAppend(sts->data[dt.structId - 1].name);
|
|
|
|
+ } else {
|
|
|
|
+ switch(dt.type) {
|
|
|
|
+ case DT_INT: dtAppend("int"); break;
|
|
|
|
+ case DT_FLOAT: dtAppend("float"); break;
|
|
|
|
+ case DT_BOOL: dtAppend("bool"); break;
|
|
|
|
+ default: dtAppend("unknown");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for(unsigned int i = 0; i < dt.pointers; i++) {
|
|
|
|
+ dtAppend("*");
|
|
|
|
+ }
|
|
|
|
+ if(dt.reference) {
|
|
|
|
+ dtAppend("&");
|
|
}
|
|
}
|
|
- return dtGetBaseName(dt.type);
|
|
|
|
|
|
+ return typeName[typeNameSwap];
|
|
}
|
|
}
|
|
|
|
|
|
int dtGetSize(DataType dt) {
|
|
int dtGetSize(DataType dt) {
|