Merge pull request #104 from alliedmodders/fix-structs

Clean up the struct syntax and force it to use newdecls.
This commit is contained in:
David Anderson 2014-07-20 21:19:15 -07:00
commit 88c614c1ba
5 changed files with 53 additions and 69 deletions

View File

@ -42,10 +42,10 @@
struct PlVers struct PlVers
{ {
version, public int version;
String:filevers[], public const char[] filevers;
String:date[], public const char[] date;
String:time[] public const char[] time;
}; };
/** /**
@ -111,10 +111,10 @@ enum PluginInfo
*/ */
struct Extension struct Extension
{ {
const String:name[], /**< Short name */ public const char[] name; /**< Short name */
const String:file[], /**< Default file name */ public const char[] file; /**< Default file name */
bool:autoload, /**< Whether or not to auto-load */ public bool autoload; /**< Whether or not to auto-load */
bool:required, /**< Whether or not to require */ public bool required; /**< Whether or not to require */
}; };
/** /**
@ -122,9 +122,9 @@ struct Extension
*/ */
struct SharedPlugin struct SharedPlugin
{ {
const String:name[], /**< Short name */ public const char[] name; /**< Short name */
const String:file[], /**< File name */ public const char[] file; /**< File name */
bool:required, /**< Whether or not to require */ public bool required; /**< Whether or not to require */
}; };
public Float:NULL_VECTOR[3]; /**< Pass this into certain functions to act as a C++ NULL */ public Float:NULL_VECTOR[3]; /**< Pass this into certain functions to act as a C++ NULL */

View File

@ -40,11 +40,11 @@
*/ */
struct Plugin struct Plugin
{ {
const String:name[], /**< Plugin Name */ public const char[] name; /**< Plugin Name */
const String:description[], /**< Plugin Description */ public const char[] description; /**< Plugin Description */
const String:author[], /**< Plugin Author */ public const char[] author; /**< Plugin Author */
const String:version[], /**< Plugin Version */ public const char[] version; /**< Plugin Version */
const String:url[], /**< Plugin URL */ public const char[] url; /**< Plugin URL */
}; };
#include <core> #include <core>

View File

@ -264,14 +264,14 @@ typedef struct svalue_s {
int lvalue; int lvalue;
} svalue; } svalue;
#define DECLFLAG_ONLY_NEW 0x01 // Only new-style types are allowed.
#define DECLFLAG_ARGUMENT 0x02 // The declaration is for an argument. #define DECLFLAG_ARGUMENT 0x02 // The declaration is for an argument.
#define DECLFLAG_VARIABLE 0x04 // The declaration is for a variable. #define DECLFLAG_VARIABLE 0x04 // The declaration is for a variable.
#define DECLFLAG_ENUMROOT 0x08 // Multi-dimensional arrays should have an enumroot. #define DECLFLAG_ENUMROOT 0x08 // Multi-dimensional arrays should have an enumroot.
#define DECLFLAG_MAYBE_FUNCTION 0x10 // Might be a named function. #define DECLFLAG_MAYBE_FUNCTION 0x10 // Might be a named function.
#define DECLFLAG_DYNAMIC_ARRAYS 0x20 // Dynamic arrays are allowed. #define DECLFLAG_DYNAMIC_ARRAYS 0x20 // Dynamic arrays are allowed.
#define DECLFLAG_OLD 0x40 // Known old-style declaration. #define DECLFLAG_OLD 0x40 // Known old-style declaration.
#define DECLMASK_NAMED_DECL (DECLFLAG_ARGUMENT | DECLFLAG_VARIABLE | DECLFLAG_MAYBE_FUNCTION) #define DECLFLAG_FIELD 0x80 // Struct field.
#define DECLMASK_NAMED_DECL (DECLFLAG_ARGUMENT | DECLFLAG_VARIABLE | DECLFLAG_MAYBE_FUNCTION | DECLFLAG_FIELD)
typedef struct { typedef struct {
// Array information. // Array information.

View File

@ -155,6 +155,7 @@ static void inst_datetime_defines(void);
static void inst_binary_name(char *binfname); static void inst_binary_name(char *binfname);
static int operatorname(char *name); static int operatorname(char *name);
static int parse_new_typename(const token_t *tok); static int parse_new_typename(const token_t *tok);
static int parse_new_decl(declinfo_t *decl, const token_t *first, int flags);
static int reparse_old_decl(declinfo_t *decl, int flags); static int reparse_old_decl(declinfo_t *decl, int flags);
static int reparse_new_decl(declinfo_t *decl, int flags); static int reparse_new_decl(declinfo_t *decl, int flags);
static void check_void_decl(const declinfo_t *decl, int variable); static void check_void_decl(const declinfo_t *decl, int variable);
@ -2906,6 +2907,8 @@ static void check_struct_name(const char *name)
LayoutSpec spec = deduce_layout_spec_by_name(name); LayoutSpec spec = deduce_layout_spec_by_name(name);
if (!can_redef_layout_spec(spec, Layout_PawnStruct)) if (!can_redef_layout_spec(spec, Layout_PawnStruct))
error(110, name, layout_spec_name(spec)); error(110, name, layout_spec_name(spec));
if (!isupper(*name))
error(109, "struct");
} }
/* /*
@ -2921,71 +2924,52 @@ static void declstruct(void)
/* get the explicit tag (required!) */ /* get the explicit tag (required!) */
tok = lex(&val,&str); tok = lex(&val,&str);
if (tok != tSYMBOL) if (tok != tSYMBOL) {
error(93); error(93);
} else {
check_struct_name(str); check_struct_name(str);
}
pstruct = pstructs_add(str); pstruct = pstructs_add(str);
int flags = STRUCTTAG; pc_addtag_flags(pstruct->name, STRUCTTAG|FIXEDTAG);
if (isupper(*pstruct->name))
flags |= FIXEDTAG;
pc_addtag_flags(pstruct->name, flags);
needtoken('{'); needtoken('{');
do { do {
structarg_t arg;
if (matchtoken('}')) { if (matchtoken('}')) {
/* Quick exit */ /* Quick exit */
lexpush(); lexpush();
break; break;
} }
memset(&arg, 0, sizeof(structarg_t));
tok = lex(&val,&str); declinfo_t decl;
if (tok == tCONST) { memset(&decl, 0, sizeof(decl));
arg.fconst = 1;
tok = lex(&val,&str); decl.type.ident = iVARIABLE;
} decl.type.size = 1;
arg.ident = 0; if (!needtoken(tPUBLIC) || !parse_new_decl(&decl, NULL, DECLFLAG_FIELD)) {
if (tok == '&') { // skip the rest of the line.
arg.ident = iREFERENCE; lexclr(TRUE);
tok = lex(&val,&str); break;
}
if (tok == tLABEL) {
arg.tag = pc_addtag(str);
tok = lex(&val,&str);
}
if (tok != tSYMBOL) {
error(1, "-identifier-", str);
continue;
}
strcpy(arg.name, str);
if (matchtoken('[')) {
if (arg.ident == iREFERENCE)
error(67, arg.name);
arg.ident = iARRAY;
do {
constvalue *enumroot;
int ignore_tag;
if (arg.dimcount == sDIMEN_MAX) {
error(53);
break;
}
size = needsub(&ignore_tag, &enumroot);
arg.dims[arg.dimcount++] = size;
} while (matchtoken('['));
/* Handle strings */
if (arg.tag == pc_tag_string && arg.dims[arg.dimcount-1])
arg.dims[arg.dimcount-1] = (size + sizeof(cell)-1) / sizeof(cell);
if (arg.dimcount == 1 && !arg.dims[arg.dimcount-1])
arg.ident = iREFARRAY;
} else if (!arg.ident) {
arg.ident = iVARIABLE;
} }
structarg_t arg;
memset(&arg, 0, sizeof(arg));
arg.tag = decl.type.tag;
arg.dimcount = decl.type.numdim;
memcpy(arg.dims, decl.type.dim, sizeof(int) * arg.dimcount);
strcpy(arg.name, decl.name);
arg.fconst = !!(decl.type.usage & uCONST);
arg.ident = decl.type.ident;
if (arg.ident == iARRAY)
arg.ident = iREFARRAY;
if (pstructs_addarg(pstruct, &arg) == NULL) if (pstructs_addarg(pstruct, &arg) == NULL)
error(103, arg.name, layout_spec_name(Layout_PawnStruct)); error(103, arg.name, layout_spec_name(Layout_PawnStruct));
} while (matchtoken(','));
require_newline(TRUE);
} while (!lexpeek('}'));
needtoken('}'); needtoken('}');
matchtoken(';'); /* eat up optional semicolon */ matchtoken(';'); /* eat up optional semicolon */
} }

View File

@ -51,7 +51,7 @@ typedef struct structarg_s
{ {
int tag; int tag;
int dimcount; int dimcount;
cell dims[sDIMEN_MAX]; int dims[sDIMEN_MAX];
char name[sNAMEMAX+1]; char name[sNAMEMAX+1];
int fconst; int fconst;
int ident; int ident;