mirror of
https://github.com/cc65/cc65.git
synced 2025-01-10 19:29:45 +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)
|
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
|
/* Return the name string of the given type split into a western part and an
|
||||||
** eastern part.
|
** eastern part.
|
||||||
@ -1395,34 +1454,11 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
|
|||||||
|
|
||||||
} else if (IsTypeFunc (T)) {
|
} 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 */
|
/* Get the parameter list string */
|
||||||
SymEntry* Param = D->SymTab->SymHead;
|
GetParameterList (&ParamList, &Buf, D, 0);
|
||||||
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);
|
|
||||||
|
|
||||||
/* Join the existing West and East together */
|
/* Join the existing West and East together */
|
||||||
if (!SB_IsEmpty (East)) {
|
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 */
|
/* Get the function descriptor used in definition */
|
||||||
const FuncDesc* D = GetFuncDefinitionDesc (T);
|
const FuncDesc* D = GetFuncDefinitionDesc (T);
|
||||||
|
|
||||||
/* Get the parameter list string. Start from the first parameter */
|
/* Get the parameter list string */
|
||||||
SymEntry* Param = D->SymTab->SymHead;
|
GetParameterList (&ParamList, &Buf, D, 1);
|
||||||
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 function qualifiers */
|
/* Get the function qualifiers */
|
||||||
if (GetQualifierTypeCodeNameBuf (&Buf, T->C, T_QUAL_NONE) > 0) {
|
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 */
|
/* Get the signature string without the return type */
|
||||||
SB_Printf (&West, "%s%s (%s)", SB_GetConstBuf (&Buf), Name, SB_GetConstBuf (&ParamList));
|
SB_Printf (&West, "%s%s (%s)", SB_GetConstBuf (&Buf), Name, SB_GetConstBuf (&ParamList));
|
||||||
SB_Done (&Buf);
|
|
||||||
SB_Done (&ParamList);
|
|
||||||
|
|
||||||
/* Complete with the return type */
|
/* Complete with the return type */
|
||||||
GetFullTypeNameWestEast (&West, &East, GetFuncReturnType (T));
|
GetFullTypeNameWestEast (&West, &East, GetFuncReturnType (T));
|
||||||
SB_Append (&West, &East);
|
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);
|
SB_Terminate (&West);
|
||||||
|
|
||||||
/* Output */
|
/* Output */
|
||||||
fprintf (F, "%s", SB_GetConstBuf (&West));
|
fprintf (F, "%s", SB_GetConstBuf (&West));
|
||||||
|
SB_Done (&ParamList);
|
||||||
|
SB_Done (&Buf);
|
||||||
SB_Done (&East);
|
SB_Done (&East);
|
||||||
SB_Done (&West);
|
SB_Done (&West);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user