示例#1
0
void PrintType(Type *type)
{
	if(type->ty == typeIDENTIFIER || type->ty == typeTYPEDEF)
		printf("'%s' :-  ", type->sym->name);

	while(type)
	{
		switch(type->ty)
		{
		case typePOINTER:	printf(" POINTER(*) -> "); break;
		case typeARRAY:		printf(" ARRAY[%d] -> ", (int)Evaluate(type->elements)); break;
		case typeTYPEDEF:	printf(" TYPEDEF(%s) -> ", type->sym->name); break;
		case typeSTRUCT:	printf(" STRUCT(%s) ", type->sptr->symbol->name);	break;
		case typeENUM:		printf(" ENUM(%s) ", type->eptr->symbol->name);		break;
		case typeFUNCTION:	printf(" FUNC-returning(%s)", type->fptr->symbol->name);		break;	

		case typeCHAR:		case typeWCHAR: 
		case typeBYTE:		case typeWORD:
		case typeDWORD:		case typeQWORD:
			printf("%s ", Parser::inenglish(TypeToToken(type->ty))); 
			break;

		case typeUNSIGNED:	printf(" UNSIGNED -> "); break;
		case typeSIGNED:	printf(" SIGNED -> "); break;
		case typeCONST:		printf(" CONST -> "); break;

		case typeIDENTIFIER:
			//printf("%s ", type->var->varName);
			//printf("ID(%s) > ", type->sym->name);
			break;
		}

		type = type->link;
	}

	//printf("\n");
}
示例#2
0
static int RecurseRenderType(stringprint &sbuf, Type *type)
{
	Structure *sptr;

	if(type == 0)
		return 0;

	switch(type->ty)
	{
	case typeSTRUCT: case typeUNION:
		
		sptr = type->sptr;
		
		sbuf._stprintf(TEXT("%hs "), Parser::inenglish(TypeToToken(type->ty)));

		if(!sptr->symbol->anonymous)
			sbuf._stprintf(TEXT("%hs "), sptr->symbol->name); 

		RecurseRenderType(sbuf, type->link);
		
		break;
		
	case typeCHAR:		case typeWCHAR: 
	case typeBYTE:		case typeWORD:
	case typeDWORD:		case typeQWORD:
	case typeFLOAT:		case typeDOUBLE:
		sbuf._stprintf(TEXT("%hs "), Parser::inenglish(TypeToToken(type->ty))); 
		RecurseRenderType(sbuf, type->link);

		break;

	case typeTYPEDEF:		
		sbuf._stprintf(TEXT("%hs "), type->sym->name);
		RecurseRenderType(sbuf, type->link);
		break;
		
	case typeIDENTIFIER:
		sbuf._stprintf(TEXT("%hs"), type->sym->name);
		RecurseRenderType(sbuf, type->link);
		break;

	case typePOINTER:

		if(type->brackets)//sbuf.brackets)
			sbuf._stprintf(TEXT("("));

		sbuf._stprintf(TEXT("*"));
		RecurseRenderType(sbuf, type->link);

		if(type->brackets)//sbuf.brackets)
			sbuf._stprintf(TEXT(")"));

		break;

	case typeENUM:
		sbuf._stprintf(TEXT("enum %hs "), type->eptr->symbol->name);
		RecurseRenderType(sbuf, type->link);
		break;

	case typeARRAY:

		RecurseRenderType(sbuf, type->link);
		sbuf._stprintf(TEXT("["));
		RecurseFlatten(sbuf, type->elements);
		sbuf._stprintf(TEXT("]"));
		break;
		
	default:
		break;
		}
		

	return 0;
}
示例#3
0
size_t RecurseDisplayType(FILE *fp, TypeDecl *typeDecl, Type *type, int indent, int padtype)
{
	Enum		*eptr;
	Structure	*sptr;
	Function	*fptr;

	size_t i;
	size_t len = 0;

	if(type)
	{
		if(type->brackets)
			len += fprintf(fp, "(");

		switch(type->ty)
		{
		case typeIDENTIFIER:

			if(fPreserveWhitespace)
				DisplayWhitespace(fp, &type->fileRef);
			len += fprintf(fp, "%s", type->sym->name);
			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;

		case typePOINTER:	
			
			len += fprintf(fp, "*"); 
			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;

		case typeARRAY:		

			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			len += fprintf(fp, "[");
			len += Flatten(fp, type->elements);
			len += fprintf(fp, "]");
			break;

		case typeENUM:

			eptr = type->eptr;

			len += fprintf(fp, "enum %s ", eptr->symbol->anonymous ? "" : eptr->symbol->name);

			if(typeDecl->compoundType)
			{
				if(fPreserveWhitespace)
				{
					len += DisplayWhitespace(fp, &eptr->postNameRef);
					len += fprintf(fp, "{");
					//len += DisplayWhitespace(fp, &eptr->postBraceRef);
					//len += DisplayWhitespace(fp, 
				}
				else
				{
					len += fprintf(fp, "\n");
					len += print_indent(fp, indent);
					len += fprintf(fp, "{\n");
				}
				
				for(i = 0; i < eptr->fieldList.size(); i++)
				{
					if(fPreserveWhitespace)
						len += DisplayWhitespace(fp, &eptr->fieldList[i]->fileRef);
					else
						len += print_indent(fp, indent+1);

					len += fprintf(fp, "%s", (char *)eptr->fieldList[i]->name);
					
					if(eptr->fieldList[i]->expr)
					{
						DisplayWhitespace(fp, &eptr->fieldList[i]->after);
						len += fprintf(fp, " = ");
						len += Flatten(fp, eptr->fieldList[i]->expr);
					}
					
					if(i < eptr->fieldList.size() - 1)
						len += fprintf(fp, ","); // ",\n")
					else
						len += fprintf(fp, "");	 // "\n"

					//DisplayWhitespace(fp, &eptr->fieldList[i]->postRef);
				}
				
				if(fPreserveWhitespace)
					len += DisplayWhitespace(fp, &eptr->lastBraceRef);
				else
					len += print_indent(fp, indent);
				len += fprintf(fp, "}");
			}

			if(type->link)
				len += fprintf(fp, " ");

			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;

		case typeTYPEDEF:	
			len += fprintf(fp, "%s", type->sym->name); 
			break;

		case typeFUNCTION:

			// display the return-type
			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			
			fptr = type->fptr;

			len += fprintf(fp, " (\n");//, fptr->symbol->name);

			for(i = 0; i < fptr->paramDeclList.size(); i++)
			{
				TypeDecl *typeDecl = fptr->paramDeclList[i];
				len += DisplayTypeDecl(fp, typeDecl, indent+1);

				if(i < fptr->paramDeclList.size() - 1)
				{
					len += fprintf(fp, ",\n");
				}
			}

			len += fprintf(fp, "\n)");
			break;

		case typeSTRUCT: case typeUNION:
			
			sptr = type->sptr;

			FILE_DESC *fileDesc;
			fileDesc = sptr->symbol->fileRef.fileDesc;

			if(type->ty == typeUNION)
				len += fprintf(fp, "union");
			else
				len += fprintf(fp, "struct");

			len += fprintf(fp, " %s", sptr->symbol->anonymous ? "" : sptr->symbol->name); 
			
			if(typeDecl->compoundType)
			{
				if(fPreserveWhitespace)
				{
					len += DisplayWhitespace(fp, &sptr->postNameRef);
					len += fprintf(fp, "{");
					len += DisplayWhitespace(fp, &sptr->postBraceRef);
				}
				else
				{
					len += fprintf(fp, "\n");
					len += print_indent(fp, indent);
					len += fprintf(fp, "{\n");
				}
				
				for(i = 0; i < sptr->typeDeclList.size(); i++)
				{
					TypeDecl *typeDecl = sptr->typeDeclList[i];

					if(typeDecl->nested && typeDecl->compoundType && i > 0 && !fPreserveWhitespace)
					{
						len += fprintf(fp, "\n");
					}

					//len += DisplayWhitespace(fp, &typeDecl->fileRef);
					len += DisplayTypeDecl(fp, typeDecl, indent+1);
					len += fprintf(fp, ";");//\n");
					//len += DisplayWhitespace(fp, &typeDecl->postRef);

					if(typeDecl->comment)
					{
						if(typeDecl->postRef.wspStart < typeDecl->postRef.wspEnd)
						{
							DisplayWhitespace(fp, &typeDecl->postRef, typeDecl->comment);
						}
						else
						{
							len += fprintf(fp, " // %s\n", typeDecl->comment);
							len += print_indent(fp, indent);
						}
					}
					else
					{
						if(DisplayWhitespace(fp, &typeDecl->postRef) == 0)
						{
							fprintf(fp, "\n");
							print_indent(fp, indent);
						}
					}

					if(typeDecl->nested && typeDecl->compoundType && i < sptr->typeDeclList.size()-1 && !fPreserveWhitespace)
					{
						len += fprintf(fp, "\n");
					}
				}
				
				if(fPreserveWhitespace)
					;//len += DisplayWhitespace(fp, &sptr->lastBraceRef);
				else
					len += print_indent(fp, indent);

				len += fprintf(fp, "}");
			}

			if(type->link)
				len += fprintf(fp, " ");

			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;
			
		case typeCHAR:		case typeWCHAR: 
		case typeBYTE:		case typeWORD:
		case typeDWORD:		case typeQWORD:
		case typeFLOAT:		case typeDOUBLE:
			
			//if(type->link)
			if(padtype && !fPreserveWhitespace)
				len += fprintf(fp, "%-7s ", Parser::inenglish(TypeToToken(type->ty))); 
			else
				len += fprintf(fp, "%s", Parser::inenglish(TypeToToken(type->ty))); 

			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;

		case typeCONST:

			len += fprintf(fp, "const ");
			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;
			
		case typeUNSIGNED:

			len += fprintf(fp, "unsigned ");
			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;

		case typeSIGNED:

			len += fprintf(fp, "signed ");
			len += RecurseDisplayType(fp, typeDecl, type->link, indent, padtype);
			break;
			
		default:
			break;
		}

		if(type->brackets) 
			len += fprintf(fp, ")");
		
		type = type->link;
	}

	return len;
}