Cleaned up code to convert to/from the string representation; improved
string representation sufficiently that it now represents cleanly everything that the DOH object representation can. Comparison on DOH type objects now tests only for complete equivalence of form, and should match string comparison of string representations. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@344 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7ecba53a9b
commit
cb6ea1b83d
3 changed files with 552 additions and 530 deletions
|
|
@ -42,20 +42,44 @@
|
|||
*
|
||||
* String Encoding C Example
|
||||
* --------------- ---------
|
||||
* *.*.int int **
|
||||
* [300].[400].int int [300][400]
|
||||
* *.+const.char char const *
|
||||
* *.*.i-32 int **
|
||||
* [300].[400].i-32 int [300][400]
|
||||
* *.+const.c-8 char const *
|
||||
*
|
||||
* '*' = Pointer
|
||||
* '[...]' = Array
|
||||
* '(...)' = Function
|
||||
* '{...}' = Structure
|
||||
* '&' = Reference
|
||||
* '+str' = Qualifier
|
||||
* '*' = Pointer
|
||||
* '&' = Reference
|
||||
* '[...]' = Array
|
||||
* '(..,..)' = Function
|
||||
* '{s/tag/..,..}' = Structure (/tag/ optional)
|
||||
* '{u/tag/..,..}' = Union (/tag/ optional)
|
||||
* '{c/tag/..,..}' = Class (/tag/ optional)
|
||||
* '</t/n=v,n=,..>' = Enum (/tag/ optional, n = name,
|
||||
* v = value (optional))
|
||||
* '+str' = Qualifier
|
||||
* 'i-w' = w-bit signed integer
|
||||
* 'u-w' = w-bit unsigned integer
|
||||
* 'c-w' = w-bit character
|
||||
*
|
||||
* for structures, unions, classes, and enums, a missing body (no curly braces)
|
||||
* is denoted by a backslash (\) where the body would appear. See examples.
|
||||
*
|
||||
* e.g. '*.+const.i-64' pointer to const 64-bit integer
|
||||
* '(si-32,*.i-32).c-8 function taking 32-bit integer and
|
||||
* pointer to 32-bit integer and
|
||||
* returning 8-bit character
|
||||
* '{s/Foo/i-32,*.c-8}' structure, tagged 'Foo', containing a
|
||||
* 32-bit integer and a pointer to
|
||||
* 8-bit character
|
||||
* '{si-32,*.c-8}' same structure, without tag
|
||||
* '{ui-32,*.c-8}' union with same members, without tag
|
||||
* '&</Nums/one=1,two,three>' reference to enumeration, tagged
|
||||
* 'Nums', mapping 'one' to 1, as well as
|
||||
* 'two' and 'three'.
|
||||
* '&</Nums/\>' same enum, without its body
|
||||
*
|
||||
* The encoding follows the order that you might describe a type in words.
|
||||
* For example "*.[200].int" is "A pointer to array of integers" and "*.+const.char"
|
||||
* is "a pointer to a const char".
|
||||
* For example "*.[200].int" is "A pointer to array of int's" and
|
||||
* "*.+const.char" is "a pointer to a const char".
|
||||
*
|
||||
* This representation is particularly convenient because string operations
|
||||
* can be used to combine and manipulate types. For example, a type could be
|
||||
|
|
@ -324,6 +348,76 @@ DOH *StringType_split_parms(DOH *p) {
|
|||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* StringType_get_tag()
|
||||
*
|
||||
* Returns the tag for a struct/enum/whatnot
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *StringType_get_tag(DOH *s) {
|
||||
char *c = Char(s);
|
||||
|
||||
if (*c == '{')
|
||||
c += 2;
|
||||
else if (*c == '<')
|
||||
c++;
|
||||
else
|
||||
assert(0);
|
||||
|
||||
if (*c == '/') {
|
||||
char *rv, *p;
|
||||
c++;
|
||||
p = strchr(c, (int)'/');
|
||||
if (!p) return NULL;
|
||||
rv = DohMalloc(p - c + 1);
|
||||
memmove(rv, c, p - c);
|
||||
rv[p - c] = 0;
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* StringType_split_enum()
|
||||
*
|
||||
* Splits a comma separated list of enum elements
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *StringType_split_enum(DOH *s) {
|
||||
DOH *list;
|
||||
DOH *item;
|
||||
char *c = Char(s);
|
||||
|
||||
assert(*c == '<');
|
||||
c++;
|
||||
if (*c == '/') {
|
||||
c++;
|
||||
while (*c)
|
||||
if (*(c++) == '/') break;
|
||||
}
|
||||
if (*c == '\\')
|
||||
return NULL; /* no body at all */
|
||||
|
||||
list = NewList();
|
||||
item = NewString("");
|
||||
while (*c)
|
||||
{
|
||||
if (*c == ',') {
|
||||
Append(list, item);
|
||||
Delete(item);
|
||||
item = NewString("");
|
||||
} else if (*c == '>')
|
||||
break;
|
||||
else
|
||||
Putc(*c, item);
|
||||
c++;
|
||||
}
|
||||
Append(list, item);
|
||||
Delete(item);
|
||||
return list;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* StringType_split_struct()
|
||||
*
|
||||
|
|
@ -337,6 +431,15 @@ DOH *StringType_split_struct(DOH *p) {
|
|||
c = Char(p);
|
||||
assert(*c == '{');
|
||||
c++;
|
||||
assert(*c == 's' || *c == 'c' || *c == 'u');
|
||||
c++;
|
||||
if (*c == '/') {
|
||||
c++;
|
||||
while (*c)
|
||||
if (*(c++) == '/') break;
|
||||
}
|
||||
if (*c == '\\')
|
||||
return NULL; /* no body at all */
|
||||
list = NewList();
|
||||
item = NewString("");
|
||||
while (*c) {
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@ extern DOH *StringType_pop(DOH *t);
|
|||
extern void StringType_push(DOH *t, DOH *s);
|
||||
extern DOH *StringType_split_parms(DOH *p);
|
||||
extern DOH *StringType_split_struct(DOH *s);
|
||||
extern DOH *StringType_split_enum(DOH *s);
|
||||
extern DOH *StringType_get_tag(DOH *s);
|
||||
extern DOH *StringType_cstr(DOH *s, DOH *id);
|
||||
extern int StringType_ispointer(DOH *t);
|
||||
extern int StringType_isreference(DOH *t);
|
||||
|
|
@ -144,56 +146,49 @@ extern DOH *StringType_base(DOH *t);
|
|||
|
||||
/* constructors */
|
||||
DOH *SwigType_fromstring(DOH *string);
|
||||
DOH *SwigType_newint(int width, int is_const, int is_volatile,
|
||||
int is_signed, int is_unsigned);
|
||||
DOH *SwigType_newfloat(int width, int is_const,
|
||||
int is_volatile);
|
||||
DOH *SwigType_newvoid();
|
||||
DOH *SwigType_newchar(int width, int is_const, int is_volatile);
|
||||
DOH *SwigType_newname(DOH *name, int is_const, int is_volatile);
|
||||
DOH *SwigType_newenum(DOH *name, DOH *body,
|
||||
int is_const, int is_volatile);
|
||||
DOH *SwigType_newstruct(DOH *name, DOH *body,
|
||||
int is_const, int is_volatile);
|
||||
DOH *SwigType_newunion(DOH *name, DOH *body,
|
||||
int is_const, int is_volatile);
|
||||
DOH *SwigType_newarray(DOH *size, DOH *parent);
|
||||
DOH *SwigType_newfunction(DOH *parameters, DOH *parent);
|
||||
DOH *SwigType_newpointer(int is_const, int is_volatile, DOH *parent);
|
||||
DOH *SwigType_new(int type, DOH *tag, DOH *contents, DOH *parent, int width);
|
||||
|
||||
/* use the sequence methods on a type to step linearly down through
|
||||
the sequence of constructors. That is, Getitem(t, 2) is t
|
||||
without its outermost two constructors:
|
||||
DOH *SwigType_integer(int width);
|
||||
DOH *SwigType_unsigned(int width);
|
||||
DOH *SwigType_character(int width);
|
||||
DOH *SwigType_float(int width);
|
||||
DOH *SwigType_void();
|
||||
DOH *SwigType_name(DOH *tag);
|
||||
DOH *SwigType_enum(DOH *tag, DOH *contents);
|
||||
DOH *SwigType_struct(DOH *tag, DOH *contents);
|
||||
DOH *SwigType_union(DOH *tag, DOH *contents);
|
||||
|
||||
t = Pointer(Pointer(Array(Int())))
|
||||
Getitem(t,2) = Array(Int()) */
|
||||
DOH *SwigType_array(DOH *size, DOH *parent);
|
||||
DOH *SwigType_function(DOH *parameters, DOH *parent);
|
||||
DOH *SwigType_pointer(DOH *parent);
|
||||
DOH *SwigType_qualifier(DOH *tag, DOH *parent);
|
||||
|
||||
/* accessors -- return information about the outermost
|
||||
constructor. */
|
||||
int SwigType_gettype(DOH *t);
|
||||
DOH *SwigType_getname(DOH *t);
|
||||
DOH *SwigType_getattributes(DOH *t);
|
||||
int SwigType_getwidth(DOH *t);
|
||||
int SwigType_getconst(DOH *t);
|
||||
int SwigType_getvolatile(DOH *t);
|
||||
int SwigType_getsigned(DOH *t);
|
||||
int SwigType_getunsigned(DOH *t);
|
||||
int SwigType_get_type(DOH *t);
|
||||
int SwigType_get_width(DOH *t);
|
||||
DOH *SwigType_get_tag(DOH *t);
|
||||
DOH *SwigType_get_contents(DOH *t);
|
||||
|
||||
/* Type constants (returned from SwigType_gettype) */
|
||||
|
||||
#define SWIGTYPE_INT 0
|
||||
#define SWIGTYPE_FLOAT 1
|
||||
#define SWIGTYPE_VOID 2
|
||||
#define SWIGTYPE_CHAR 3
|
||||
#define SWIGTYPE_NAME 4
|
||||
#define SWIGTYPE_ENUM 5
|
||||
#define SWIGTYPE_STRUCT 6
|
||||
#define SWIGTYPE_UNION 7
|
||||
#define SWIGTYPE_ARRAY 8
|
||||
#define SWIGTYPE_FUNCTION 9
|
||||
#define SWIGTYPE_POINTER 10
|
||||
#define SWIGTYPE_INTEGER 0
|
||||
#define SWIGTYPE_UNSIGNED 1
|
||||
#define SWIGTYPE_CHARACTER 2
|
||||
#define SWIGTYPE_FLOAT 3
|
||||
#define SWIGTYPE_VOID 4
|
||||
#define SWIGTYPE_NAME 5
|
||||
#define SWIGTYPE_ENUM 6
|
||||
#define SWIGTYPE_STRUCT 7
|
||||
#define SWIGTYPE_UNION 8
|
||||
#define SWIGTYPE_CLASS 9
|
||||
#define SWIGTYPE_ARRAY 10
|
||||
#define SWIGTYPE_FUNCTION 11
|
||||
#define SWIGTYPE_POINTER 12
|
||||
#define SWIGTYPE_REFERENCE 13
|
||||
#define SWIGTYPE_QUALIFIER 14
|
||||
|
||||
/* Parse tree support */
|
||||
/* --- Parse tree support --- */
|
||||
|
||||
extern void Swig_dump_tags(DOH *obj, DOH *root);
|
||||
extern void Swig_emit_rules(DOH *ruleset, DOH *context, DOH *node,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue