# Class: com.pnfsoftware.jeb.core.units.code.asm.type.TypeStringParser

A parser for C declarations, types, prototypes and routine signatures. 

 Examples: 

```

 ITypeManager typeman = ...;
 IStructureType tHouse = typeman.createStructure("House");
 typeman.addStructureField(tHouse, "field0", typeman.getType("int"));

 TypeStringParser parser = new TypeStringParser(typeman);
 parser.parseType("int a;");         // name is optional; semicolon is also optional
 parser.parseType("int");            // name optional; semicolon optional
 parser.parseType("House*");
 parser.parseType("void (*f)()");    // for function pointers, a name (which will be discarded) is mandatory; semicolon is optional
 parser.parseType("char* __cdecl f(int, double);");

 // the format for anonymous prototypes is the following (no name; again, final semi-colon optional)
 // anonymous prototypes follow a JEB-custom format: their calling convention precedes the return type, and is stored in angled brackets
 // prototype attributes are not supported
 parser.parsePrototype("void()");
 parser.parsePrototype("int();");
 parser.parsePrototype("int(void)");
 parser.parsePrototype("<__cdecl\> int(int)");
 parser.parsePrototype("<__cdecl\> int(int, int)");
 parser.parsePrototype("<__cdecl\> int(int, char*, ...)");

 // signatures: standard C signatures with support for MSVC- and GCC-style attributes
 parser.parseSignature("void __cdecl f()");
 parser.parseSignature("void f(void)");
 parser.parseSignature("void f(int a)");
 parser.parseSignature("void f(unsigned, unsigned int *)");
 parser.parseSignature("void f(int a, void __cdecl (*pf[4])(int a))");
 parser.parseSignature("void f(int a, ...)");
 parser.parseSignature("void f(int a[3])");
 parser.parseSignature("void __attribute__((noreturn)) exit(int code)");  //GCC no-return attribute
 parser.parseSignature("void __cdecl __declspec(noreturn) exit(int)");  //MSVC no-return attribute

 
```

## Constructor: TypeStringParser
- parameter: `typeman`, type: `com.pnfsoftware.jeb.core.units.code.asm.type.ITypeManager`

Description: Create a type parser.
parameter: typeman: the type manager to be used as a source of existing types and recipient of            newly\-parsed types

## Static Field: DECL
Type: `int`

Constant value: `3`
Description: Verification mode for declaration strings.

## Static Field: PROTO
Type: `int`

Constant value: `1`
Description: Verification mode for anonymous prototype strings.

## Static Field: SIG
Type: `int`

Constant value: `2`
Description: Verification mode for function signature strings.

## Static Field: TYPE
Type: `int`

Constant value: `0`
Description: Verification mode for type strings.

## Method: parseDeclaration
- parameter: `s`, type: `java.lang.String`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.TypeStringParser.Decl`

Description: Parse a C declaration. 

 A declaration specifies a type and a name. If you need to parse a pure type, see [#parseType(String)](#parseType(String)).
parameter: s: declaration, e.g `unsigned int a` or `char* array[3]` or            `void __cdecl (*pf)(int)` \(a function pointer named pf\)
return: a declaration object \(type, name\)
throws: if parsing fails

## Method: parseDeclaration
- parameter: `s`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.TypeStringParser.Decl`

Description: Parse a C declaration. 

 A declaration specifies a type and a name. If you need to parse a pure type, see [#parseType(String)](#parseType(String)).
parameter: s: declaration, e.g `unsigned int a` or `char* array[3]` or            `void __cdecl (*pf)(int)` \(a function pointer named pf\)
parameter: discardCppTemplates: true to remove C\+\+ template arguments before parsing
return: a declaration \(type, name\)
throws: if parsing fails

## Method: parsePrototype
- parameter: `s`, type: `java.lang.String`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.IPrototypeItem`

Description: Parse an anonymous prototype written using the following style: 

```

 <calling-convention> returnType(paramType1 _)
 <calling-convention> returnType(paramType1, paramType2)
 <calling-convention> returnType(paramType1, paramType2, ...)
 
```
deprecated: It is recommended to use [#parseSignature(String)](#parseSignature(String)) instead.
parameter: s: a JEB\-style prototype string
return: a prototype object
throws: if parsing fails

## Method: parseSignature
- parameter: `s`, type: `java.lang.String`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.IPrototypeItem`

Description: Parse a C function signature.
parameter: s: a signature, e.g. `int __cdecl foo(int a, unsigned char * b)`
return: a prototype item also holding the routine name and parameter names
throws: if parsing fails

## Method: parseSignature
- parameter: `s`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.IPrototypeItem`

Description: Parse a C function signature.
parameter: s: a signature, e.g. `int __cdecl foo(int a, unsigned char * b)`
parameter: discardCppTemplates: if true, templated types `<...>` will be erased, thereby making            the type potentially parsable as a C type
return: a prototype item also holding the routine name and parameter names
throws: if parsing fails

## Method: parseType
- parameter: `s`, type: `java.lang.String`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.INativeType`

Description: Parse a non\-complex C type. It is recommended to use [#parseDeclaration(String)](#parseDeclaration(String)) instead when possible.
parameter: s: a type string, e.g `unsigned int` or `char`.
return: never null
throws: if parsing fails

## Method: parseTypesRaw
- parameter: `s`, type: `java.lang.String`
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.asm.type.INativeType>`

Description: Parse any C type or types.
parameter: s: a string buffer defining types
return: the list of parsed types
throws: if parsing fails

## Static Method: massageForDeclaration
- parameter: `s`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Normalize a declaration string by appending a semicolon if necessary.
parameter: s: declaration string
return: normalized declaration string

## Static Method: massageForType
- parameter: `s`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Normalize a type string so it can be parsed as a declaration.
parameter: s: type string
return: normalized declaration string

## Static Method: massageSingleDeclaration
- parameter: `declstring`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`
- return type: `java.lang.String`

Description: Normalize a single declaration and optionally remove C\+\+ template arguments.
parameter: declstring: declaration string
parameter: discardCppTemplates: true to remove C\+\+ template arguments before parsing
return: normalized declaration string
throws: if template delimiters are invalid

## Static Method: removeCppTemplates
- parameter: `s`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Remove C\+\+ template arguments from a declaration or type string.
parameter: s: a C or C\+\+ declaration or type, possibly with templates
return: the same C or C\+\+ declaration or type, without templates information

## Static Method: verify
- parameter: `what`, type: `int`
- parameter: `cstr`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`

Description: This static method can be used to verify that the provided argument looks like a valid C declaration.
parameter: what: [#TYPE](#TYPE) or [#SIG](#SIG)
parameter: cstr: a C declaration or type
parameter: discardCppTemplates: if true, templated types `<...>` will be erased, thereby making            the type potentially parsable as a C type
throws: a parsing error occurred

## Static Method: verifyDeclaration
- parameter: `declstr`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`

Description: Basic verification to ensure that the provided string looks like a declaration string.
parameter: declstr: declaration string to verify
parameter: discardCppTemplates: true to remove C\+\+ template arguments before verification
throws: if verification fails

## Static Method: verifySignature
- parameter: `sigstr`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`

Description: Basic verification to ensure that the provided string looks like a signature string.
parameter: sigstr: function signature string to verify
parameter: discardCppTemplates: true to remove C\+\+ template arguments before verification
throws: if verification fails

## Static Method: verifyType
- parameter: `typestr`, type: `java.lang.String`
- parameter: `discardCppTemplates`, type: `boolean`

Description: Basic verification to ensure that the provided string looks like a type string.
parameter: typestr: type string to verify
parameter: discardCppTemplates: true to remove C\+\+ template arguments before verification
throws: if verification fails

