mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 21:32:19 +00:00
Fixed type name output with K&R-style functions.
This commit is contained in:
parent
4343eebe67
commit
f3199e4308
@ -1356,6 +1356,65 @@ const char* GetFullTypeName (const Type* T)
|
||||
|
||||
|
||||
|
||||
static void GetParameterList (StrBuf* ParamList, StrBuf* Buf, const FuncDesc* D, int Detailed)
|
||||
{
|
||||
/* First argument */
|
||||
const SymEntry* Param = D->SymTab->SymHead;
|
||||
unsigned I;
|
||||
|
||||
if ((D->Flags & FD_OLDSTYLE) == 0) {
|
||||
/* ANSI style */
|
||||
for (I = 0; I < D->ParamCount; ++I) {
|
||||
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
|
||||
if (I > 0) {
|
||||
SB_AppendStr (ParamList, ", ");
|
||||
}
|
||||
if (Detailed) {
|
||||
if (SymIsRegVar (Param)) {
|
||||
SB_AppendStr (ParamList, "register ");
|
||||
}
|
||||
if (!SymHasAnonName (Param)) {
|
||||
SB_AppendStr (Buf, Param->Name);
|
||||
}
|
||||
}
|
||||
SB_AppendStr (ParamList, SB_GetConstBuf (GetFullTypeNameBuf (Buf, Param->Type)));
|
||||
SB_Clear (Buf);
|
||||
/* Next argument */
|
||||
Param = Param->NextSym;
|
||||
}
|
||||
if ((D->Flags & FD_VARIADIC) == 0) {
|
||||
if (D->ParamCount == 0 && (D->Flags & FD_EMPTY) == 0) {
|
||||
SB_AppendStr (ParamList, "void");
|
||||
}
|
||||
} else {
|
||||
if (D->ParamCount > 0) {
|
||||
SB_AppendStr (ParamList, ", ...");
|
||||
} else {
|
||||
SB_AppendStr (ParamList, "...");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* K&R style */
|
||||
if (Detailed) {
|
||||
for (I = 0; I < D->ParamCount; ++I) {
|
||||
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
|
||||
if (I > 0) {
|
||||
SB_AppendStr (ParamList, ", ");
|
||||
}
|
||||
if (!SymHasAnonName (Param)) {
|
||||
SB_AppendStr (ParamList, Param->Name);
|
||||
}
|
||||
/* Next argument */
|
||||
Param = Param->NextSym;
|
||||
}
|
||||
}
|
||||
SB_Clear (Buf);
|
||||
}
|
||||
SB_Terminate (ParamList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBuf* East, const Type* T)
|
||||
/* Return the name string of the given type split into a western part and an
|
||||
** eastern part.
|
||||
@ -1395,34 +1454,11 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
|
||||
|
||||
} else if (IsTypeFunc (T)) {
|
||||
|
||||
FuncDesc* D = GetFuncDesc (T);
|
||||
struct StrBuf ParamList = AUTO_STRBUF_INITIALIZER;
|
||||
struct StrBuf ParamList = AUTO_STRBUF_INITIALIZER;
|
||||
const FuncDesc* D = GetFuncDesc (T);
|
||||
|
||||
/* First argument */
|
||||
SymEntry* Param = D->SymTab->SymHead;
|
||||
unsigned I;
|
||||
for (I = 0; I < D->ParamCount; ++I) {
|
||||
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
|
||||
if (I > 0) {
|
||||
SB_AppendStr (&ParamList, ", ");
|
||||
}
|
||||
SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type)));
|
||||
SB_Clear (&Buf);
|
||||
/* Next argument */
|
||||
Param = Param->NextSym;
|
||||
}
|
||||
if ((D->Flags & FD_VARIADIC) == 0) {
|
||||
if (D->ParamCount == 0 && (D->Flags & FD_EMPTY) == 0) {
|
||||
SB_AppendStr (&ParamList, "void");
|
||||
}
|
||||
} else {
|
||||
if (D->ParamCount > 0) {
|
||||
SB_AppendStr (&ParamList, ", ...");
|
||||
} else {
|
||||
SB_AppendStr (&ParamList, "...");
|
||||
}
|
||||
}
|
||||
SB_Terminate (&ParamList);
|
||||
/* Get the parameter list string */
|
||||
GetParameterList (&ParamList, &Buf, D, 0);
|
||||
|
||||
/* Join the existing West and East together */
|
||||
if (!SB_IsEmpty (East)) {
|
||||
@ -1600,37 +1636,8 @@ void PrintFuncSig (FILE* F, const char* Name, const Type* T)
|
||||
/* Get the function descriptor used in definition */
|
||||
const FuncDesc* D = GetFuncDefinitionDesc (T);
|
||||
|
||||
/* Get the parameter list string. Start from the first parameter */
|
||||
SymEntry* Param = D->SymTab->SymHead;
|
||||
unsigned I;
|
||||
for (I = 0; I < D->ParamCount; ++I) {
|
||||
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
|
||||
if (I > 0) {
|
||||
SB_AppendStr (&ParamList, ", ");
|
||||
}
|
||||
if (SymIsRegVar (Param)) {
|
||||
SB_AppendStr (&ParamList, "register ");
|
||||
}
|
||||
if (!SymHasAnonName (Param)) {
|
||||
SB_AppendStr (&Buf, Param->Name);
|
||||
}
|
||||
SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type)));
|
||||
SB_Clear (&Buf);
|
||||
/* Next argument */
|
||||
Param = Param->NextSym;
|
||||
}
|
||||
if ((D->Flags & FD_VARIADIC) == 0) {
|
||||
if (D->ParamCount == 0 && (D->Flags & FD_EMPTY) == 0) {
|
||||
SB_AppendStr (&ParamList, "void");
|
||||
}
|
||||
} else {
|
||||
if (D->ParamCount > 0) {
|
||||
SB_AppendStr (&ParamList, ", ...");
|
||||
} else {
|
||||
SB_AppendStr (&ParamList, "...");
|
||||
}
|
||||
}
|
||||
SB_Terminate (&ParamList);
|
||||
/* Get the parameter list string */
|
||||
GetParameterList (&ParamList, &Buf, D, 1);
|
||||
|
||||
/* Get the function qualifiers */
|
||||
if (GetQualifierTypeCodeNameBuf (&Buf, T->C, T_QUAL_NONE) > 0) {
|
||||
@ -1641,16 +1648,44 @@ void PrintFuncSig (FILE* F, const char* Name, const Type* T)
|
||||
|
||||
/* Get the signature string without the return type */
|
||||
SB_Printf (&West, "%s%s (%s)", SB_GetConstBuf (&Buf), Name, SB_GetConstBuf (&ParamList));
|
||||
SB_Done (&Buf);
|
||||
SB_Done (&ParamList);
|
||||
|
||||
/* Complete with the return type */
|
||||
GetFullTypeNameWestEast (&West, &East, GetFuncReturnType (T));
|
||||
SB_Append (&West, &East);
|
||||
|
||||
/* Check if the function is defined in K&R style */
|
||||
if ((D->Flags & FD_OLDSTYLE) != 0 && D->ParamCount > 0) {
|
||||
/* First argument */
|
||||
const SymEntry* Param = D->SymTab->SymHead;
|
||||
unsigned I;
|
||||
|
||||
SB_Clear (&ParamList);
|
||||
SB_Clear (&Buf);
|
||||
for (I = 0; I < D->ParamCount; ++I) {
|
||||
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
|
||||
SB_AppendChar (&ParamList, ' ');
|
||||
if (SymIsRegVar (Param)) {
|
||||
SB_AppendStr (&ParamList, "register ");
|
||||
}
|
||||
if (!SymHasAnonName (Param)) {
|
||||
SB_AppendStr (&Buf, Param->Name);
|
||||
}
|
||||
SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type)));
|
||||
SB_AppendChar (&ParamList, ';');
|
||||
SB_Clear (&Buf);
|
||||
|
||||
/* Next argument */
|
||||
Param = Param->NextSym;
|
||||
}
|
||||
SB_Append (&West, &ParamList);
|
||||
}
|
||||
|
||||
SB_Terminate (&West);
|
||||
|
||||
/* Output */
|
||||
fprintf (F, "%s", SB_GetConstBuf (&West));
|
||||
SB_Done (&ParamList);
|
||||
SB_Done (&Buf);
|
||||
SB_Done (&East);
|
||||
SB_Done (&West);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user