Esempio n. 1
0
void ParseSpecifier(TABLE *table)
{
	SYM *sp;

	isUnsigned = FALSE;
	for (;;) {
		switch (lastst) {
			case kw_signed:	// Ignore 'signed'
				NextToken();
				break;
			case kw_typedef:
				isTypedef = TRUE;
				NextToken();
				break;
			case kw_nocall:
				isNocall = TRUE;
				head = tail = maketype(bt_oscall,8);
				NextToken();
				goto lxit;
			case kw_oscall:
				isOscall = TRUE;
				head = tail = maketype(bt_oscall,8);
				NextToken();
				goto lxit;
			case kw_interrupt:
				isInterrupt = TRUE;
				head = tail = maketype(bt_interrupt,8);
				NextToken();
				goto lxit;
			case kw_pascal:
				isPascal = TRUE;
				head = tail = maketype(bt_pascal,8);
				NextToken();
				break;
			case kw_byte:
				head = tail = maketype(bt_byte,1);
				NextToken();
				head->isUnsigned = isUnsigned;
				bit_max = 8;
				goto lxit;
			case kw_char:
				head = tail = maketype(bt_char,2);
				NextToken();
				head->isUnsigned = isUnsigned;
				bit_max = 16;
				goto lxit;
			case kw_short:
				head = tail = maketype(bt_short,4);
				bit_max = 32;
				NextToken();
				if( lastst == kw_int )
					NextToken();
				head->isUnsigned = isUnsigned;
				head->isShort = TRUE;
				goto lxit;
				break;
			case kw_long:	// long, long int
				if (lastst==kw_int) {
					NextToken();
				}
				if (lastst==kw_float)
					head = tail = maketype(bt_double,8);
				else
					head = tail = maketype(bt_long,8);
				NextToken();
				if (lastst==kw_oscall) {
					isOscall = TRUE;
					NextToken();
				}
				if (lastst==kw_nocall) {
					isNocall = TRUE;
					NextToken();
				}
				head->isUnsigned = isUnsigned;
				bit_max = 64;
				goto lxit;
				break;
			case kw_int:
				head = tail = maketype(bt_long,8);
				head->isUnsigned = isUnsigned;
				NextToken();
				if (lastst==kw_oscall) {
					isOscall = TRUE;
					NextToken();
				}
				if (lastst==kw_nocall) {
					isNocall = TRUE;
					NextToken();
				}
				bit_max = 64;
				goto lxit;
				break;
			case kw_unsigned:
				NextToken();
				isUnsigned = TRUE;
				break;
			case id:                /* no type ParseSpecifierarator */
				sp = search(lastid,&gsyms[0]);
				if (sp) {
					if (sp->storage_class==sc_typedef) {
						NextToken();
						head = tail = sp->tp;
					}
					else
						head = tail = sp->tp;
//					head = tail = maketype(bt_long,4);
				}
				else {
					head = tail = maketype(bt_long,8);
					bit_max = 64;
				}
				goto lxit;
				break;
			case kw_float:
				head = tail = maketype(bt_float,4);
				NextToken();
				bit_max = 32;
				goto lxit;
			case kw_double:
				head = tail = maketype(bt_double,8);
				NextToken();
				bit_max = 64;
				goto lxit;
			case kw_void:
				head = tail = maketype(bt_void,0);
				NextToken();
				if (lastst==kw_interrupt) {
					isInterrupt = TRUE;
					NextToken();
				}
				if (lastst==kw_nocall) {
					isNocall = TRUE;
					NextToken();
				}
				bit_max = 0;
				goto lxit;
			case kw_enum:
				NextToken();
				ParseEnumDeclaration(table);
				bit_max = 16;
				goto lxit;
			case kw_struct:
				NextToken();
				ParseStructDeclaration(bt_struct);
				goto lxit;
			case kw_union:
				NextToken();
				ParseStructDeclaration(bt_union);
				goto lxit;
			default:
				goto lxit;
			}
	}
lxit:;
}
Esempio n. 2
0
// Parse a specifier. This is the first part of a declaration.
// Returns:
// 0 usually, 1 if only a specifier is present
//
int ParseSpecifier(TABLE *table)
{
	SYM *sp;

	isUnsigned = FALSE;
	isSigned = FALSE;
	isVolatile = FALSE;
	isConst = FALSE;
	for (;;) {
		switch (lastst) {
			case kw_const:	// Ignore 'const'
				isConst = TRUE;
				NextToken();
				break;

			case kw_typedef:
				isTypedef = TRUE;
				NextToken();
				break;

			case kw_nocall:
			case kw_naked:
				isNocall = TRUE;
				head = tail = maketype(bt_oscall,8);
				NextToken();
				break;

			case kw_oscall:
				isOscall = TRUE;
				head = tail = maketype(bt_oscall,8);
				NextToken();
				goto lxit;

			case kw_interrupt:
				isInterrupt = TRUE;
				head = tail = maketype(bt_interrupt,8);
				NextToken();
				if (lastst==openpa) {
                    NextToken();
                    if (lastst!=id) 
                       error(ERR_IDEXPECT);
                    needpunc(closepa);
                    stkname = litlate(lastid);
                }
				goto lxit;

			case kw_pascal:
				isPascal = TRUE;
				head = tail = maketype(bt_pascal,8);
				NextToken();
				break;

			// byte and char default to unsigned unless overridden using
			// the 'signed' keyword
			//
			case kw_byte:
				if (isUnsigned)
					head = tail = maketype(bt_ubyte,1);
				else
					head = tail = maketype(bt_byte,1);
				NextToken();
				head->isUnsigned = !isSigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				bit_max = 8;
				goto lxit;
			
			case kw_char:
				if (isUnsigned)
					head = tail = maketype(bt_uchar,2);
				else
					head = tail = maketype(bt_char,2);
				NextToken();
				head->isUnsigned = !isSigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				bit_max = 16;
				goto lxit;

			case kw_int16:
				if (isUnsigned)
					head = tail = maketype(bt_uchar,2);
				else
					head = tail = maketype(bt_char,2);
				NextToken();
				head->isUnsigned = isUnsigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				bit_max = 16;
				goto lxit;

			case kw_int32:
			case kw_short:
				if (isUnsigned)
					head = tail = maketype(bt_ushort,4);
				else
					head = tail = maketype(bt_short,4);
				bit_max = 32;
				NextToken();
				if( lastst == kw_int )
					NextToken();
				head->isUnsigned = isUnsigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				head->isShort = TRUE;
				goto lxit;
				break;

			case kw_long:	// long, long int
				NextToken();
				if (lastst==kw_int) {
					NextToken();
				}
				else if (lastst==kw_float) {
					head = tail = maketype(bt_double,8);
					NextToken();
				}
				else {
					if (isUnsigned)
						head = tail = maketype(bt_ulong,8);
					else
						head = tail = maketype(bt_long,8);
				}
				//NextToken();
				if (lastst==kw_task) {
				    isTask = TRUE;
				    NextToken();
                }
				if (lastst==kw_oscall) {
					isOscall = TRUE;
					NextToken();
				}
				else if (lastst==kw_nocall || lastst==kw_naked) {
					isNocall = TRUE;
					NextToken();
				}
				head->isUnsigned = isUnsigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				bit_max = 64;
				goto lxit;
				break;

			case kw_int64:
			case kw_int:
				if (isUnsigned)
					head = tail = maketype(bt_ulong,8);
				else
					head = tail = maketype(bt_long,8);
				head->isUnsigned = isUnsigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				if (lastst==kw_task) {
				    isTask = TRUE;
				    NextToken();
                }
				if (lastst==kw_oscall) {
					isOscall = TRUE;
					NextToken();
				}
				else if (lastst==kw_nocall || lastst==kw_naked) {
					isNocall = TRUE;
					NextToken();
				}
				bit_max = 64;
				goto lxit;
				break;

            case kw_task:
                isTask = TRUE;
                NextToken();
				break;

			case kw_int8:
				if (isUnsigned)
					head = tail = maketype(bt_ubyte,1);
				else
					head = tail = maketype(bt_byte,1);
				head->isUnsigned = isUnsigned;
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				if (lastst==kw_oscall) {
					isOscall = TRUE;
					NextToken();
				}
				if (lastst==kw_nocall || lastst==kw_naked) {
					isNocall = TRUE;
					NextToken();
				}
				bit_max = 8;
				goto lxit;
				break;

			case kw_signed:
				isSigned = TRUE;
				NextToken();
				break;

			case kw_unsigned:
				NextToken();
				isUnsigned = TRUE;
				break;

			case kw_volatile:
				NextToken();
				isVolatile = TRUE;
				break;

			case ellipsis:
			case id:                /* no type ParseSpecifierarator */
				sp = search(lastid,&gsyms[0]);
				if (sp) {
					if (sp->storage_class==sc_typedef) {
						NextToken();
						head = tail = sp->tp;
					}
					else
						head = tail = sp->tp;
//					head = tail = maketype(bt_long,4);
				}
				else {
					head = tail = maketype(bt_long,8);
					bit_max = 64;
				}
				goto lxit;
				break;

			case kw_float:
				head = tail = maketype(bt_float,4);
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				bit_max = 32;
				goto lxit;

			case kw_double:
				head = tail = maketype(bt_double,8);
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				bit_max = 64;
				goto lxit;

			case kw_triple:
				head = tail = maketype(bt_triple,12);
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				bit_max = 96;
				goto lxit;

			case kw_void:
				head = tail = maketype(bt_void,0);
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				if (lastst==kw_interrupt) {
					isInterrupt = TRUE;
					NextToken();
				}
				if (lastst==kw_nocall || lastst==kw_naked) {
					isNocall = TRUE;
					NextToken();
				}
				bit_max = 0;
				goto lxit;

			case kw_enum:
				NextToken();
				ParseEnumDeclaration(table);
				bit_max = 16;
				goto lxit;

			case kw_struct:
				NextToken();
				if (ParseStructDeclaration(bt_struct))
					return 1;
				goto lxit;

			case kw_union:
				NextToken();
				if (ParseStructDeclaration(bt_union))
					return 1;
				goto lxit;

            case kw_exception:
				head = tail = maketype(bt_exception,8);
				head->isVolatile = isVolatile;
				head->isConst = isConst;
				NextToken();
				bit_max = 64;
				goto lxit;
				
            case kw_inline:
                NextToken();
                break;

			default:
				goto lxit;
			}
	}
lxit:;
	return 0;
}