Exemplo n.º 1
0
int InitializePointer()
{   
	SYM *sp;

    if(lastst == and) {     /* address of a variable */
        NextToken();
        if( lastst != id)
            error(ERR_IDEXPECT);
		else if( (sp = gsearch(lastid)) == NULL)
            error(ERR_UNDEFINED);
        else {
            NextToken();
            if( lastst == plus || lastst == minus)
                GenerateReference(sp,GetIntegerExpression());
            else
                GenerateReference(sp,0);
            if( sp->storage_class == sc_auto)
                    error(ERR_NOINIT);
        }
    }
    else if(lastst == sconst) {
        GenerateLabelReference(stringlit(laststr));
        NextToken();
    }
    else
        GenerateLong(GetIntegerExpression());
    endinit();
    return 8;       /* pointers are 4 bytes long */
}
Exemplo n.º 2
0
int InitializePointer()
{   
	SYM *sp;
	ENODE *n;
	long lng;

    if(lastst == bitandd) {     /* address of a variable */
        NextToken();
        if( lastst != id)
            error(ERR_IDEXPECT);
		else if( (sp = gsearch(lastid)) == NULL)
            error(ERR_UNDEFINED);
        else {
            NextToken();
            if( lastst == plus || lastst == minus)
                GenerateReference(sp,GetIntegerExpression((ENODE **)NULL));
            else
                GenerateReference(sp,0);
            if( sp->storage_class == sc_auto)
                    error(ERR_NOINIT);
        }
    }
    else if(lastst == sconst) {
        GenerateLabelReference(stringlit(laststr));
        NextToken();
    }
	else if (lastst == rconst) {
        GenerateLabelReference(quadlit(&rval128));
        NextToken();
	}
	//else if (lastst == id) {
	//	sp = gsearch(lastid);
	//	if (sp->tp->type == bt_func || sp->tp->type == bt_ifunc) {
	//		NextToken();
	//		GenerateReference(sp,0);
	//	}
	//	else
	//		GenerateLong(GetIntegerExpression(NULL));
	//}
	else {
		lng = GetIntegerExpression(&n);
		if (n && n->nodetype == en_cnacon) {
			if (n->sp->length()) {
				sp = gsearch(*n->sp);
				GenerateReference(sp,0);
			}
			else
				GenerateLong(lng);
		}
		else {
			GenerateLong(lng);
        }
	}
    endinit();
    return 2;       /* pointers are 2 bytes long */
}
Exemplo n.º 3
0
void ParseEnumerationList(TABLE *table)
{
	int     evalue;
    SYM     *sp;
    evalue = 0;
    while(lastst == id) {
        sp = allocSYM();
        sp->name = litlate(lastid);
        sp->storage_class = sc_const;
        sp->tp = &stdconst;
        insert(sp,table);
        NextToken();
		if (lastst==assign) {
			NextToken();
			sp->value.i = GetIntegerExpression((ENODE **)NULL);
			evalue = sp->value.i+1;
		}
		else
			sp->value.i = evalue++;
        if( lastst == comma)
                NextToken();
        else if(lastst != end)
                break;
    }
    needpunc(end);
}
Exemplo n.º 4
0
Statement *ParseSpinunlockStatement()
{
	Statement *snp; 
	SYM *sp;

    snp = NewStatement(st_spinunlock, TRUE); 
	snp->incrExpr = 1;
	if (lastst==openpa)
		NextToken();
    if( expression(&(snp->exp)) == 0 ) 
        error(ERR_EXPREXPECT); 
	if (lastst==comma) {
		NextToken();
		snp->incrExpr = GetIntegerExpression();
		if (snp->incrExpr < 1 || snp->incrExpr > 15)
			error(ERR_SEMA_INCR);
		snp->incrExpr = (int)snp->incrExpr & 15;
	}
    //if( lastst != id ) { 
    //    error(ERR_IDEXPECT); 
    //    return 0; 
    //}
  //  if( (sp = search(lastid,&gsyms[0])) == NULL ) { 
  //      error( ERR_UNDEFINED ); 
		//return 0;
  //  }
	NextToken();
	if (lastst==closepa)
		NextToken();
    //snp->label = sp->name; 
    snp->next = 0; 
	return snp;
}
Exemplo n.º 5
0
void ParseEnumerationList(TABLE *table)
{
	int     evalue;
    SYM     *sp;
    evalue = 0;
    while(lastst == id) {
        sp = allocSYM();
        sp->SetName(*(new std::string(lastid)));
        sp->storage_class = sc_const;
        sp->tp = &stdconst;
        table->insert(sp);
        NextToken();
		if (lastst==assign) {
			NextToken();
			sp->value.i = GetIntegerExpression((ENODE **)NULL);
			evalue = (int)sp->value.i+1;
		}
		else
			sp->value.i = evalue++;
        if( lastst == comma)
                NextToken();
        else if(lastst != end)
                break;
    }
    needpunc(end,48);
}
Exemplo n.º 6
0
Statement *ParseCaseStatement()
{
	Statement *snp; 
    Statement *head, *tail;
	int buf[256];
	int nn;
	int *bf;

    snp = NewStatement(st_case, FALSE); 
	if (lastst == kw_fallthru)	// ignore "fallthru"
		NextToken();
    if( lastst == kw_case ) { 
        NextToken(); 
        snp->s2 = 0;
		nn = 0;
		do {
			buf[nn] = GetIntegerExpression((ENODE **)NULL);
			nn++;
			if (lastst != comma)
				break;
			NextToken();
		} while (nn < 256);
		if (nn==256)
			error(ERR_TOOMANYCASECONSTANTS);
		bf = (int *)xalloc(sizeof(int)*(nn+1));
		bf[0] = nn;
		for (; nn > 0; nn--)
			bf[nn]=buf[nn-1];
		snp->label = (int64_t *)bf;
    }
    else if( lastst == kw_default) { 
        NextToken(); 
        snp->s2 = (Statement *)1; 
		snp->stype = st_default;
    } 
    else { 
        error(ERR_NOCASE); 
        return (Statement *)NULL;
    } 
    needpunc(colon,35); 
    head = (Statement *)NULL; 
    while( lastst != end && lastst != kw_case && lastst != kw_default ) { 
		if( head == NULL ) {
			head = tail = ParseStatement(); 
			if (head)
				head->outer = snp;
		}
		else { 
			tail->next = ParseStatement(); 
			if( tail->next != NULL )  {
				tail->next->outer = snp;
				tail = tail->next;
			}
		}
        tail->next = 0; 
    } 
    snp->s1 = head; 
    return snp; 
} 
Exemplo n.º 7
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;
        }
}
Exemplo n.º 8
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;
    }
}
Exemplo n.º 9
0
Statement *Statement::ParseStop() 
{
	Statement *snp; 

	snp = NewStatement(st_stop, TRUE); 
	snp->num = (int)GetIntegerExpression(NULL);
	if( lastst != end )
		needpunc( semicolon,43 );
	return snp;
} 
Exemplo n.º 10
0
Statement *ParseSpinlockStatement()
{
	Statement *snp; 
	SYM *sp;

	snp = NewStatement(st_spinlock, TRUE); 
	if (lastst==openpa)
		NextToken();
    if( NonCommaExpression(&(snp->exp)) == 0 ) 
        error(ERR_EXPREXPECT); 
	snp->incrExpr = (ENODE *)1;
	snp->initExpr = (ENODE *)0;
	//if( lastst != id ) { 
 //       error(ERR_IDEXPECT); 
 //       return 0; 
 //   }
 //   if( (sp = search(lastid,&gsyms[0])) == NULL ) { 
 //           error( ERR_UNDEFINED ); 
	//		return 0;
 //           }
//	NextToken();
//	if (lastst==comma) {
//		NextToken();
//		snp->incrExpr = (ENODE *)GetIntegerExpression((ENODE **)NULL);
//		if ((int64_t)snp->incrExpr < 1 || (int64_t)snp->incrExpr > 15)
//			error(ERR_SEMA_INCR);
//		snp->incrExpr = (ENODE *)((int64_t)snp->incrExpr);
//	}
	if (lastst==comma) {
		NextToken();
		snp->initExpr = (ENODE *)GetIntegerExpression((ENODE **)NULL);
	}
	if (lastst==closepa)
		NextToken();
//    snp->label = sp->name; 
    snp->next = 0; 
	snp->s1 = ParseStatement();
	// Empty statements return NULL
	if (snp->s1)
		snp->s1->outer = snp;
	if (lastst==kw_lockfail) {
		NextToken();
		snp->s2 = ParseStatement();
		// Empty statements return NULL
		if (snp->s2)
			snp->s2->outer = snp;
	}
	return snp;
}
Exemplo n.º 11
0
Statement *Statement::ParseIf() 
{
	Statement *snp; 

	dfs.puts("<ParseIf>");
	NextToken();
	if (lastst == kw_firstcall)
		return (ParseFirstcall());
	currentFn->UsesPredicate = TRUE;
	snp = NewStatement(st_if, FALSE);
	snp->predreg = iflevel;
	iflevel++;
	if ((iflevel > maxPn-1) && isThor)
		error(ERR_OUTOFPREDS);
	if( lastst != openpa ) 
		error(ERR_EXPREXPECT); 
	else {
		NextToken(); 
		if( expression(&(snp->exp)) == 0 ) 
			error(ERR_EXPREXPECT); 
		if (lastst == semicolon) {
			NextToken();
			snp->prediction = (GetIntegerExpression(NULL) & 1) | 2;
		}
		needpunc( closepa,19 ); 
		if (lastst==kw_then)
			NextToken();
		snp->s1 = Statement::Parse(); 
		if (snp->s1)
			snp->s1->outer = snp;
		if( lastst == kw_else ) { 
			NextToken(); 
			snp->s2 = Statement::Parse(); 
			if (snp->s2)
				snp->s2->outer = snp;
		} 
		else if (lastst == kw_elsif) {
			snp->s2 = ParseIf(); 
			if (snp->s2)
				snp->s2->outer = snp;
		}
		else 
			snp->s2 = 0; 
	} 
	iflevel--;
	dfs.puts("</ParseIf>");
	return snp; 
} 
Exemplo n.º 12
0
int initbyte()
{   
	GenerateByte(GetIntegerExpression((ENODE **)NULL));
    return 1;
}
Exemplo n.º 13
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;
    }
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
int initchar()
{   
	GenerateChar(GetIntegerExpression());
    return 1;
}
Exemplo n.º 16
0
int initlong()
{
	GenerateLong(GetIntegerExpression((ENODE **)NULL));
    return 2;
}
Exemplo n.º 17
0
int initshort()
{
	GenerateWord(GetIntegerExpression((ENODE **)NULL));
    return 1;
}
Exemplo n.º 18
0
int initbyte()
{   
	GenerateByte(GetIntegerExpression());
    return 1;
}
Exemplo n.º 19
0
int initshort()
{
	GenerateWord(GetIntegerExpression());
    return 1;
}
Exemplo n.º 20
0
int StructDeclaration::Parse(int ztype)
{
  SYM *sp;
  TYP *tp;
	int ret;
	int psd;
	ENODE nd;
	ENODE *pnd = &nd;

  sp = nullptr;
	psd = isStructDecl;
	isStructDecl++;
	ret = 0;
	bit_offset = 0;
	bit_next = 0;
	bit_width = -1;
  if(lastst == id) {
    if((sp = tagtable.Find(lastid,false)) == NULL) {
      sp = allocSYM();
  		sp->SetName(*(new std::string(lastid)));
      sp->tp = allocTYP();
      sp->tp->type = (e_bt)ztype;
		  sp->tp->typeno = typeno++;
      sp->tp->lst.Clear();
      sp->storage_class = sc_type;
      sp->tp->sname = new std::string(*sp->name);
      sp->tp->alignment = 0;
      NextToken();

			if (lastst == kw_align) {
        NextToken();
        sp->tp->alignment = GetIntegerExpression(&pnd);
      }

			// Could be a forward structure declaration like:
			// struct buf;
			if (lastst==semicolon) {
				ret = 1;
        tagtable.insert(sp);
        NextToken();
			}
			// Defining a pointer to an unknown struct ?
			else if (lastst == star) {
        tagtable.insert(sp);
			}
      else if(lastst != begin)
        error(ERR_INCOMPLETE);
      else {
        tagtable.insert(sp);
        NextToken();
        ParseMembers(sp, sp->tp,ztype);
      }
    }
    // Else it is a known structure
		else {
      NextToken();
      if (lastst==kw_align) {
        NextToken();
        sp->tp->alignment = GetIntegerExpression(&pnd);
      }
			if (lastst==begin) {
        NextToken();
        ParseMembers(sp,sp->tp,ztype);
			}
		}
    head = sp->tp;
  }
  // Else there was no tag identifier
  else {
    tp = allocTYP();
    tp->type = (e_bt)ztype;
	  tp->typeno = typeno++;
    tp->sname = new std::string("");

    if (lastst==kw_align) {
      NextToken();
      tp->alignment = GetIntegerExpression(&pnd);
    }

    if( lastst != begin)
      error(ERR_INCOMPLETE);
    else {
			NextToken();
			ParseMembers(sp,tp,ztype);
    }
    head = tp;
  }
	isStructDecl = psd;
	return ret;
}
Exemplo n.º 21
0
int initlong()
{
	GenerateLong(GetIntegerExpression());
    return 1;
}
Exemplo n.º 22
0
// Class declarations have the form:
//
//	class identifier [: base class]
//  {
//		class members
//	}
//
// We could also have a forward reference:
//
//	class identifier;
//
// Or a pointer to a class:
//
//	class *identifier;
//
int ClassDeclaration::Parse(int ztype)
{
    SYM *sp, *bcsp;
	int ret;
	int psd;
	ENODE nd;
	ENODE *pnd = &nd;
	char *idsave;
	int alignment;
  SYM *cls;

  cls = currentClass;
	dfs.puts("<ParseClassDeclaration>\n");
	alignment = 0;
	isTypedef = TRUE;
	NextToken();
	if (lastst != id) {
		error(ERR_SYNTAX);
		goto lxit;
	}
//	ws = allocSYM();
	idsave = my_strdup(lastid);
//	ws->name = idsave;
//	ws->storage_class = sc_typedef;
	// Passes lastid onto struct parsing

	psd = isStructDecl;
	isStructDecl++;
	ret = 0;
	bit_offset = 0;
	bit_next = 0;
	bit_width = -1;

  dfs.printf("---------------------------------");
  dfs.printf("Class decl:%s\n", lastid);
  dfs.printf("---------------------------------");
	if((sp = tagtable.Find(std::string(lastid),false)) == NULL) {
    sp = allocSYM();
    sp->SetName(*(new std::string(lastid)));
		sp->tp = nullptr;
    NextToken();
    dfs.printf("A");
		if (lastst == kw_align) {
      NextToken();
      alignment = GetIntegerExpression(&pnd);
    }
    else
      alignment = AL_STRUCT;

		// Could be a forward structure declaration like:
		// struct buf;
		if (lastst==semicolon) {
      dfs.printf("B");
			ret = 1;
			printf("classdecl insert1\r\n");
      tagtable.insert(sp);
      NextToken();
		}
		// Defining a pointer to an unknown struct ?
		else if (lastst == star) {
      dfs.printf("C");
			printf("classdecl insert2\r\n");
      tagtable.insert(sp);
		}
		else if (lastst==colon) {
      dfs.printf("D");
			NextToken();
			// Absorb and ignore public/private keywords
			if (lastst == kw_public || lastst==kw_private)
				NextToken();
			if (lastst != id) {
				error(ERR_SYNTAX);
				goto lxit;
			}
			bcsp = tagtable.Find(std::string(lastid),false);
			if (bcsp==nullptr) {
				error(ERR_UNDEFINED);
				goto lxit;
			}
      dfs.printf("E");
			// Copy the type chain of base class
			//sp->tp = TYP::Copy(bcsp->tp);
			// Start off at the size of the base.
			sp->tp = allocTYP();
			sp->tp->lst.SetBase(bcsp->GetIndex());
			dfs.printf("Set base class: %d\n", sp->tp->lst.base);
			sp->tp->size = bcsp->tp->size;
			sp->tp->type = (e_bt)ztype;
			sp->tp->typeno = typeno++;
      sp->tp->sname = new std::string(*sp->name);
      sp->tp->alignment = alignment;
	    sp->storage_class = sc_type;
			NextToken();
			if (lastst != begin) {
        error(ERR_INCOMPLETE);
				goto lxit;
			}
			/*
			sp->tp = allocTYP();
			sp->tp->typeno = typeno++;
      sp->tp->sname =  new std::string(*sp->name);
      sp->tp->alignment = alignment;
			sp->tp->type = (e_bt)ztype;
			sp->tp->lst.SetBase(bcsp->GetIndex());
	    sp->storage_class = sc_type;
	    */
      tagtable.insert(sp);
      NextToken();
      currentClass = sp;
      dfs.printf("f");
      ParseMembers(sp,ztype);
      dfs.printf("G");
		}
    else if(lastst != begin)
      error(ERR_INCOMPLETE);
    else {
			if (sp->tp == nullptr) {
				sp->tp = allocTYP();
			}
			sp->tp->size = 0;
			sp->tp->typeno = typeno++;
      sp->tp->sname = new std::string(*sp->name);
      sp->tp->alignment = alignment;
			sp->tp->type = (e_bt)ztype;
			sp->tp->lst.SetBase(0);
	    sp->storage_class = sc_type;
      tagtable.insert(sp);
      NextToken();
      currentClass = sp;
      ParseMembers(sp,ztype);
    }
  }
  // Else the class was found in the tag table.
	else {
    NextToken();
    if (lastst==kw_align) {
	    NextToken();
      sp->tp->alignment = GetIntegerExpression(&pnd);
    }
		if (lastst==begin) {
        NextToken();
        currentClass = sp;
        ParseMembers(sp,ztype);
		}
	}
  head = sp->tp;
	isStructDecl = psd;
lxit:
	isTypedef = TRUE;
	if (classname) delete classname;
	classname = new std::string(idsave);
	currentClass = cls;
	dfs.puts("</ParseClassDeclaration>\n");
	return ret;
}
Exemplo n.º 23
0
int ParseStructDeclaration(int ztype)
{
    SYM     *sp;
    TYP     *tp;
    int gblflag;
    int ret;
    int psd;
    ENODE nd;
    ENODE *pnd = &nd;

    psd = isStructDecl;
    isStructDecl = TRUE;
    ret = 0;
    bit_offset = 0;
    bit_next = 0;
    bit_width = -1;
    if(lastst == id) {
        if((sp = search(lastid,&tagtable)) == NULL) {
            // If we encounted an unknown struct in a parameter list, we want
            // it to go into the global memory pool, not a local one.
            if (parsingParameterList) {
                gblflag = global_flag;
                global_flag++;
                sp = allocSYM();
                sp->name = litlate(lastid);
                global_flag = gblflag;
            }
            else {
                sp = allocSYM();
                sp->name = litlate(lastid);
            }
            sp->tp = allocTYP();
            sp->tp->type = ztype;
            sp->tp->typeno = typeno++;
            sp->tp->lst.head = 0;
            sp->storage_class = sc_type;
            sp->tp->sname = sp->name;
            sp->tp->alignment = 0;
            NextToken();

            if (lastst == kw_align) {
                NextToken();
                sp->tp->alignment = GetIntegerExpression(&pnd);
            }

            // Could be a forward structure declaration like:
            // struct buf;
            if (lastst==semicolon) {
                ret = 1;
                insert(sp,&tagtable);
                NextToken();
            }
            // Defining a pointer to an unknown struct ?
            else if (lastst == star) {
                insert(sp,&tagtable);
            }
            else if(lastst != begin)
                error(ERR_INCOMPLETE);
            else    {
                insert(sp,&tagtable);
                NextToken();
                ParseStructMembers(sp->tp,ztype);
            }
        }
        else {
            NextToken();
            if (lastst==kw_align) {
                NextToken();
                sp->tp->alignment = GetIntegerExpression(&pnd);
            }
            if (lastst==begin) {
                NextToken();
                ParseStructMembers(sp->tp,ztype);
            }
        }
        head = sp->tp;
    }
    else {
        tp = allocTYP();
        tp->type = ztype;
        tp->sname = 0;
        tp->lst.head = 0;

        if (lastst==kw_align) {
            NextToken();
            tp->alignment = GetIntegerExpression(&pnd);
        }

        if( lastst != begin)
            error(ERR_INCOMPLETE);
        else {
            NextToken();
            ParseStructMembers(tp,ztype);
        }
        head = tp;
    }
    isStructDecl = psd;
    return ret;
}
Exemplo n.º 24
0
int initchar()
{   
	GenerateChar(GetIntegerExpression((ENODE **)NULL));
    return 1;
}