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

View File

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

View File

@ -264,14 +264,14 @@ typedef struct svalue_s {
int lvalue;
} svalue;
#define DECLFLAG_ONLY_NEW 0x01 // Only new-style types are allowed.
#define DECLFLAG_ARGUMENT 0x02 // The declaration is for an argument.
#define DECLFLAG_VARIABLE 0x04 // The declaration is for a variable.
#define DECLFLAG_ENUMROOT 0x08 // Multi-dimensional arrays should have an enumroot.
#define DECLFLAG_MAYBE_FUNCTION 0x10 // Might be a named function.
#define DECLFLAG_DYNAMIC_ARRAYS 0x20 // Dynamic arrays are allowed.
#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 {
// Array information.

View File

@ -155,6 +155,7 @@ static void inst_datetime_defines(void);
static void inst_binary_name(char *binfname);
static int operatorname(char *name);
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_new_decl(declinfo_t *decl, int flags);
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);
if (!can_redef_layout_spec(spec, Layout_PawnStruct))
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!) */
tok = lex(&val,&str);
if (tok != tSYMBOL)
if (tok != tSYMBOL) {
error(93);
check_struct_name(str);
} else {
check_struct_name(str);
}
pstruct = pstructs_add(str);
int flags = STRUCTTAG;
if (isupper(*pstruct->name))
flags |= FIXEDTAG;
pc_addtag_flags(pstruct->name, flags);
pc_addtag_flags(pstruct->name, STRUCTTAG|FIXEDTAG);
needtoken('{');
do {
structarg_t arg;
if (matchtoken('}')) {
/* Quick exit */
lexpush();
break;
}
memset(&arg, 0, sizeof(structarg_t));
tok = lex(&val,&str);
if (tok == tCONST) {
arg.fconst = 1;
tok = lex(&val,&str);
}
arg.ident = 0;
if (tok == '&') {
arg.ident = iREFERENCE;
tok = lex(&val,&str);
}
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;
declinfo_t decl;
memset(&decl, 0, sizeof(decl));
decl.type.ident = iVARIABLE;
decl.type.size = 1;
if (!needtoken(tPUBLIC) || !parse_new_decl(&decl, NULL, DECLFLAG_FIELD)) {
// skip the rest of the line.
lexclr(TRUE);
break;
}
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)
error(103, arg.name, layout_spec_name(Layout_PawnStruct));
} while (matchtoken(','));
require_newline(TRUE);
} while (!lexpeek('}'));
needtoken('}');
matchtoken(';'); /* eat up optional semicolon */
}

View File

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