+ D->Ident[0] = '\0';
+ D->Type[0].C = T_END;
+ D->Index = 0;
+ D->Attributes = 0;
+}
+
+
+
+static void NeedTypeSpace (Declaration* D, unsigned Count)
+/* Check if there is enough space for Count type specifiers within D */
+{
+ if (D->Index + Count >= MAXTYPELEN) {
+ /* We must call Fatal() here, since calling Error() will try to
+ * continue, and the declaration type is not correctly terminated
+ * in case we come here.
+ */
+ Fatal ("Too many type specifiers");
+ }
+}
+
+
+
+static void AddTypeToDeclaration (Declaration* D, TypeCode T)
+/* Add a type specifier to the type of a declaration */
+{
+ NeedTypeSpace (D, 1);
+ D->Type[D->Index++].C = T;
+}
+
+
+
+static void FixQualifiers (Type* DataType)
+/* Apply several fixes to qualifiers */
+{
+ Type* T;
+ TypeCode Q;
+
+ /* Using typedefs, it is possible to generate declarations that have
+ * type qualifiers attached to an array, not the element type. Go and
+ * fix these here.
+ */
+ T = DataType;
+ Q = T_QUAL_NONE;
+ while (T->C != T_END) {
+ if (IsTypeArray (T)) {
+ /* Extract any type qualifiers */
+ Q |= GetQualifier (T);
+ T->C = UnqualifiedType (T->C);
+ } else {
+ /* Add extracted type qualifiers here */
+ T->C |= Q;
+ Q = T_QUAL_NONE;
+ }
+ ++T;
+ }
+ /* Q must be empty now */
+ CHECK (Q == T_QUAL_NONE);
+
+ /* Do some fixes on pointers and functions. */
+ T = DataType;
+ while (T->C != T_END) {
+ if (IsTypePtr (T)) {
+
+ /* Fastcall qualifier on the pointer? */
+ if (IsQualFastcall (T)) {
+ /* Pointer to function which is not fastcall? */
+ if (IsTypeFunc (T+1) && !IsQualFastcall (T+1)) {
+ /* Move the fastcall qualifier from the pointer to
+ * the function.
+ */
+ T[0].C &= ~T_QUAL_FASTCALL;
+ T[1].C |= T_QUAL_FASTCALL;
+ } else {
+ Error ("Invalid `_fastcall__' qualifier for pointer");
+ }
+ }
+
+ /* Apply the default far and near qualifiers if none are given */
+ Q = (T[0].C & T_QUAL_ADDRSIZE);
+ if (Q == T_QUAL_NONE) {
+ /* No address size qualifiers specified */
+ if (IsTypeFunc (T+1)) {
+ /* Pointer to function. Use the qualifier from the function
+ * or the default if the function don't has one.
+ */
+ Q = (T[1].C & T_QUAL_ADDRSIZE);
+ if (Q == T_QUAL_NONE) {
+ Q = CodeAddrSizeQualifier ();
+ }
+ } else {
+ Q = DataAddrSizeQualifier ();
+ }
+ T[0].C |= Q;
+ } else {
+ /* We have address size qualifiers. If followed by a function,
+ * apply these also to the function.
+ */
+ if (IsTypeFunc (T+1)) {
+ TypeCode FQ = (T[1].C & T_QUAL_ADDRSIZE);
+ if (FQ == T_QUAL_NONE) {
+ T[1].C |= Q;
+ } else if (FQ != Q) {
+ Error ("Address size qualifier mismatch");
+ T[1].C = (T[1].C & ~T_QUAL_ADDRSIZE) | Q;
+ }
+ }
+ }
+
+ } else if (IsTypeFunc (T)) {
+
+ /* Apply the default far and near qualifiers if none are given */
+ if ((T[0].C & T_QUAL_ADDRSIZE) == 0) {
+ T[0].C |= CodeAddrSizeQualifier ();
+ }
+
+ }
+ ++T;
+ }