/* common */
#include "attrib.h"
#include "inline.h"
+#include "mmodel.h"
/* cc65 */
#include "funcdesc.h"
unsigned TypeLen (const Type* T);
/* Return the length of the type string */
-Type* TypeCpy (Type* Dest, const Type* Src);
+Type* TypeCopy (Type* Dest, const Type* Src);
/* Copy a type string */
Type* TypeDup (const Type* T);
* return T.
*/
-TypeCode CodeAddrSizeQualifier (void);
+TypeCode AddrSizeQualifier (unsigned AddrSize);
+/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
+
+#if defined(HAVE_INLINE)
+INLINE TypeCode CodeAddrSizeQualifier (void)
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the code address size */
+{
+ return AddrSizeQualifier (CodeAddrSize);
+}
+#else
+# define CodeAddrSizeQualifier() (AddrSizeQualifier (CodeAddrSize))
+#endif
-TypeCode DataAddrSizeQualifier (void);
+#if defined(HAVE_INLINE)
+INLINE TypeCode DataAddrSizeQualifier (void)
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the data address size */
+{
+ return AddrSizeQualifier (DataAddrSize);
+}
+#else
+# define DataAddrSizeQualifier() (AddrSizeQualifier (DataAddrSize))
+#endif
-static TypeCode OptionalQualifiers (TypeCode Q, TypeCode Allowed)
-/* Read type qualifiers if we have any */
+static TypeCode OptionalQualifiers (TypeCode Allowed)
+/* Read type qualifiers if we have any. Allowed specifies the allowed
+ * qualifiers.
+ */
{
+ /* We start without any qualifiers */
+ TypeCode Q = T_QUAL_NONE;
+
+ /* Check for more qualifiers */
while (1) {
switch (CurTok.Tok) {
}
Done:
+ /* We cannot have more than one address size far qualifier */
+ switch (Q & T_QUAL_ADDRSIZE) {
+
+ case T_QUAL_NONE:
+ case T_QUAL_NEAR:
+ case T_QUAL_FAR:
+ break;
+
+ default:
+ Error ("Cannot specify more than one address size qualifier");
+ Q &= ~T_QUAL_ADDRSIZE;
+ }
+
/* Return the qualifiers read */
return Q;
}
D->Flags &= ~DS_DEF_TYPE;
/* Read type qualifiers if we have any */
- Qualifiers = OptionalQualifiers (Qualifiers, T_QUAL_CONST | T_QUAL_VOLATILE);
+ Qualifiers |= OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE);
/* Look at the data type */
switch (CurTok.Tok) {
if (Entry && SymIsTypeDef (Entry)) {
/* It's a typedef */
NextToken ();
- TypeCpy (D->Type, Entry->Type);
+ TypeCopy (D->Type, Entry->Type);
break;
}
/* FALL THROUGH */
}
/* There may also be qualifiers *after* the initial type */
- D->Type[0].C |= OptionalQualifiers (Qualifiers, T_QUAL_CONST | T_QUAL_VOLATILE);
+ D->Type[0].C |= (Qualifiers | OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE));
}
-static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
+static void Declarator (const DeclSpec* Spec, Declaration* D, unsigned Mode)
/* Recursively process declarators. Build a type array in reverse order. */
{
/* Read optional function or pointer qualifiers. These modify the
* qualifier will later be transfered to the function itself. If it's a
* pointer to something else, it will be flagged as an error.
*/
- TypeCode Qualifiers =
- OptionalQualifiers (T_QUAL_NONE, T_QUAL_ADDRSIZE | T_QUAL_FASTCALL);
-
- /* We cannot have more than one address size far qualifier */
- switch (Qualifiers & T_QUAL_ADDRSIZE) {
-
- case T_QUAL_NONE:
- case T_QUAL_NEAR:
- case T_QUAL_FAR:
- break;
-
- default:
- Error ("Cannot specify more than one address size qualifier");
- Qualifiers &= ~T_QUAL_ADDRSIZE;
- }
+ TypeCode Qualifiers = OptionalQualifiers (T_QUAL_ADDRSIZE | T_QUAL_FASTCALL);
/* Pointer to something */
if (CurTok.Tok == TOK_STAR) {
/* Skip the star */
NextToken ();
- /* Allow optional pointer qualifiers */
- Qualifiers = OptionalQualifiers (Qualifiers, T_QUAL_CONST | T_QUAL_VOLATILE);
+ /* Allow const, restrict and volatile qualifiers */
+ Qualifiers |= OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE | T_QUAL_RESTRICT);
/* Parse the type, the pointer points to */
- Decl (Spec, D, Mode);
+ Declarator (Spec, D, Mode);
/* Add the type */
AddTypeToDeclaration (D, T_PTR | Qualifiers);
if (CurTok.Tok == TOK_LPAREN) {
NextToken ();
- Decl (Spec, D, Mode);
+ Declarator (Spec, D, Mode);
ConsumeRParen ();
} else {
/* Things depend on Mode now:
ParseDecl (&Spec, &Decl, DM_NO_IDENT);
/* Copy the type to the target buffer */
- TypeCpy (T, Decl.Type);
+ TypeCopy (T, Decl.Type);
/* Return a pointer to the target buffer */
return T;
InitDeclaration (D);
/* Get additional declarators and the identifier */
- Decl (Spec, D, Mode);
+ Declarator (Spec, D, Mode);
/* Add the base type. */
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
- TypeCpy (D->Type + D->Index, Spec->Type);
+ TypeCopy (D->Type + D->Index, Spec->Type);
/* Use the storage class from the declspec */
D->StorageClass = Spec->StorageClass;
InitDeclSpec (D);
/* There may be qualifiers *before* the storage class specifier */
- Qualifiers = OptionalQualifiers (T_QUAL_NONE, T_QUAL_CONST | T_QUAL_VOLATILE);
+ Qualifiers = OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE);
/* Now get the storage class specifier for this declaration */
ParseStorageClass (D, DefStorage);