//struct snode    *interrupt_stmt()
//{       struct snode    *snp; 
//        SYM             *sp; 
//	       TYP     *temp1;
//
//	   NextToken(); 
//		if( lastst != id ) { 
//			error(ERR_IDEXPECT); 
//			return 0; 
//        } 
//        sp = allocSYM(); 
//        sp->name = litlate(lastid); 
//        sp->value.i = nextlabel++; 
//        sp->storage_class = sc_global;
//        sp->tp = temp1; 
//        temp1 = maketype(bt_long,0);
//        temp1->val_flag = 1;
//        insert(sp,&lsyms); 
//        NextToken();       /* get past label name */ 
//        needpunc( colon );
//		snp = (struct snode *)xalloc(sizeof(struct snode)); 
//        snp->stype = st_interrupt; 
//        snp->label = sp->name;
//        snp->next = 0; 
//		snp->s1 = statement(); 
//        return snp; 
//} 
//  
struct snode    *vortex_stmt()
{       struct snode    *snp; 
        SYM             *sp; 
	       TYP     *temp1;

	   NextToken(); 
		if( lastst != id ) { 
			error(ERR_IDEXPECT); 
			return 0; 
        } 
        temp1 = maketype(bt_long,0);
        temp1->val_flag = 1;
        sp = allocSYM(); 
        sp->name = litlate(lastid); 
        sp->value.i = nextlabel++; 
        sp->storage_class = sc_global;
        sp->tp = temp1; 
        insert(sp,&lsyms); 
        NextToken();       /* get past label name */ 
        needpunc( colon );
		snp = (struct snode *)xalloc(sizeof(struct snode)); 
        snp->stype = st_vortex; 
        snp->label = sp->name;
        snp->next = 0; 
		snp->s1 = ParseStatement(); 
        return snp; 
} 
void ParseDeclarationPrefix(char isUnion)
{   
	TYP *temp1, *temp2, *temp3, *temp4;
    
	switch (lastst) {
        case id:
                declid = litlate(lastid);
				if (funcdecl==1)
					names[nparms++] = declid;
                NextToken();
				if (lastst == colon) {
					NextToken();
					bit_width = GetIntegerExpression();
					if (isUnion)
						bit_offset = 0;
					else
						bit_offset = bit_next;
					if (bit_width < 0 || bit_width > bit_max) {
						error(ERR_BITFIELD_WIDTH);
						bit_width = 1;
					}
					if (bit_width == 0 || bit_offset + bit_width > bit_max)
						bit_offset = 0;
					bit_next = bit_offset + bit_width;
					break;	// no ParseDeclarationSuffix()
				}
				ParseDeclarationSuffix();
                break;
        case star:
                temp1 = maketype(bt_pointer,8);
                temp1->btp = head;
                head = temp1;
                if(tail == NULL)
                        tail = head;
                NextToken();
                ParseDeclarationPrefix(isUnion);
                break;
        case openpa:
                NextToken();
                temp1 = head;
                temp2 = tail;
                head = tail = NULL;
                ParseDeclarationPrefix(isUnion);
                needpunc(closepa);
                temp3 = head;
                temp4 = tail;
                head = temp1;
                tail = temp2;
                ParseDeclarationSuffix();
                temp4->btp = head;
                if(temp4->type == bt_pointer && temp4->val_flag != 0 && head != NULL)
                    temp4->size *= head->size;
                head = temp3;
                break;
        default:
                ParseDeclarationSuffix();
                break;
        }
}
// Take care of the () or [] trailing part of a ParseSpecifieraration
//
void ParseDeclarationSuffix()
{
	TYP     *temp1;
    switch (lastst) {
    case openbr:
        NextToken();
        temp1 = maketype(bt_pointer,0);
        temp1->val_flag = 1;
        temp1->btp = head;
        if(lastst == closebr) {
                temp1->size = 0;
                NextToken();
                }
        else if(head != NULL) {
                temp1->size = GetIntegerExpression() * head->size;
                needpunc(closebr);
                }
        else {
                temp1->size = GetIntegerExpression();
                needpunc(closebr);
                }
        head = temp1;
        if( tail == NULL)
                tail = head;
        ParseDeclarationSuffix();
        break;
    case openpa:
        NextToken();
        temp1 = maketype(bt_func,0);
        temp1->val_flag = 1;
        temp1->btp = head;
        head = temp1;
        if( lastst == closepa) {
            NextToken();
            temp1->type = bt_ifunc;			// this line wasn't present
            if(lastst == begin)
                temp1->type = bt_ifunc;
        }
        else
            temp1->type = bt_ifunc;
        break;
    }
}
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:;
}
Exemple #5
0
// Take care of the () or [] trailing part of a declaration
//
void ParseDeclarationSuffix()
{
	TYP     *temp1;
	int fd, npf;
	char *odecl;
	TYP *tempHead, *tempTail;

    switch (lastst) {
    case openbr:
        NextToken();
        temp1 = maketype(bt_pointer,0);
        temp1->val_flag = 1;
        temp1->isArray = TRUE;
        temp1->btp = head;
        if(lastst == closebr) {
			temp1->size = 0;
			NextToken();
        }
        else if(head != NULL) {
			temp1->size = GetIntegerExpression((ENODE **)NULL) * head->size;
			temp1->alignment = head->alignment;
			needpunc(closebr);
		}
        else {
			temp1->size = GetIntegerExpression((ENODE **)NULL);
			needpunc(closebr);
		}
        head = temp1;
        if( tail == NULL)
                tail = head;
        ParseDeclarationSuffix();
        break;
    case openpa:
        NextToken();
        temp1 = maketype(bt_func,0);
        temp1->val_flag = 1;
        temp1->btp = head;
        head = temp1;
		needParseFunction = TRUE;
		if (tail==NULL) {
			if (temp1->btp)
				tail = temp1->btp;
			else
				tail = temp1;
		}
        if( lastst == closepa) {
            NextToken();
//            temp1->type = bt_ifunc;			// this line wasn't present
			if(lastst == begin) {
                temp1->type = bt_ifunc;
			}
			else
				needParseFunction = FALSE;
        }
		else {
            temp1->type = bt_ifunc;
			// Parse the parameter list for a function pointer passed as a
			// parameter.
			// Parse parameter list for a function pointer defined within
			// a structure.
			if (parsingParameterList || isStructDecl) {
				fd = funcdecl;
				needParseFunction = FALSE;
				odecl = declid;
				tempHead = head;
				tempTail = tail;
				ParseParameterDeclarations(10);	// parse and discard
				head = tempHead;
				tail = tempTail;
				declid = odecl;
				funcdecl = fd;
				needpunc(closepa);
				if (lastst != begin)
					temp1->type = bt_func;
			}
		}
        break;
    }
}
Exemple #6
0
int ParseDeclarationPrefix(char isUnion)
{   
	TYP *temp1, *temp2, *temp3, *temp4;
	SYM *sp;
	int nn;
	char buf[200];
j2:
	switch (lastst) {
		case kw_const:
			isConst = TRUE;
			NextToken();
			goto j2;

		case ellipsis:
        case id:
j1:
                declid = litlate(lastid);
				if (funcdecl==1)
					names[nparms++] = declid;
                NextToken();
				if (lastst == colon) {
					NextToken();
					bit_width = GetIntegerExpression((ENODE **)NULL);
					if (isUnion)
						bit_offset = 0;
					else
						bit_offset = bit_next;
					if (bit_width < 0 || bit_width > bit_max) {
						error(ERR_BITFIELD_WIDTH);
						bit_width = 1;
					}
					if (bit_width == 0 || bit_offset + bit_width > bit_max)
						bit_offset = 0;
					bit_next = bit_offset + bit_width;
					break;	// no ParseDeclarationSuffix()
				}
				//if (lastst==closepa) {
				//	return 1;
				//}
	//			if (lastst==closepa) {
	//				sp = search(lastid,&gsyms[0]);
	//				if (strcmp(lastid,"getchar")==0)
	//					printf("found");
	//				if (sp) {
	//					if (sp->storage_class==sc_typedef)
	//						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;
	//				}
	//				break;
	//			}
				ParseDeclarationSuffix();
                break;
        case star:
                temp1 = maketype(bt_pointer,8);
                temp1->btp = head;
                head = temp1;
                if(tail == NULL)
                        tail = head;
                NextToken();
				//if (lastst==closepa) {	// (*)
				//	sprintf(buf,"_unnamed%d", unnamedCnt);
				//	unnamedCnt++;
				//	declid = litlate(buf);
				//	NextToken();
				//	ParseDeclarationSuffix();
				//	return 2;
				//}
				// Loop back to process additional prefix info.
				goto j2;
                //return ParseDeclarationPrefix(isUnion);
                break;
        case openpa:
                NextToken();
                temp1 = head;
                temp2 = tail;
                head = tail = (TYP *)NULL;	// It might be a typecast following.
				// Do we have (getchar)()
				nn = ParseDeclarationPrefix(isUnion); 
				/*if (nn==1) {
					head = temp1;
					tail = temp2;
					goto j1;
				}*/
				//else if (nn == 2) {
				//	head = temp1;
				//	tail = temp2;
				//	NextToken();
				//	ParseDeclarationSuffix();
				//	break;
				//}
                needpunc(closepa);
                temp3 = head;
                temp4 = tail;
                head = temp1;
                tail = temp2;
                ParseDeclarationSuffix();
				// (getchar)() returns temp4 = NULL
				if (temp4!=NULL) {
					temp4->btp = head;
					if(temp4->type == bt_pointer && temp4->val_flag != 0 && head != NULL)
						temp4->size *= head->size;
	                head = temp3;
				}
				//if (head==NULL)
				//	head = tail = maketype(bt_long,8);
                break;
        default:
                ParseDeclarationSuffix();
                break;
        }
	return 0;
}
Exemple #7
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;
}