コード例 #1
0
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;
        }
}
コード例 #2
0
// 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;
    }
}
コード例 #3
0
ファイル: ParseDeclarations.c プロジェクト: BigEd/Cores
// 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;
    }
}
コード例 #4
0
ファイル: ParseDeclarations.c プロジェクト: BigEd/Cores
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;
}