mirror of
https://github.com/cc65/cc65.git
synced 2025-03-12 23:31:18 +00:00
commit
773ed23cea
@ -539,7 +539,7 @@ const Type* AddressOf (const Type* T)
|
|||||||
Type* P = TypeAlloc (Size + 1);
|
Type* P = TypeAlloc (Size + 1);
|
||||||
|
|
||||||
/* Create the return type... */
|
/* Create the return type... */
|
||||||
P[0].C = T_PTR | (T[0].C & T_QUAL_ADDRSIZE) | T_QUAL_CONST;
|
P[0].C = T_PTR | (T[0].C & T_QUAL_ADDRSIZE);
|
||||||
memcpy (P+1, T, Size * sizeof (Type));
|
memcpy (P+1, T, Size * sizeof (Type));
|
||||||
|
|
||||||
/* ...and return it */
|
/* ...and return it */
|
||||||
@ -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,12 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
|
|||||||
|
|
||||||
} else if (IsTypeFunc (T)) {
|
} else if (IsTypeFunc (T)) {
|
||||||
|
|
||||||
FuncDesc* D = GetFuncDesc (T);
|
int QualCount = 0;
|
||||||
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)) {
|
||||||
@ -1431,13 +1468,27 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
|
|||||||
SB_Clear (East);
|
SB_Clear (East);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add qualifiers */
|
||||||
|
if ((GetQualifier (T) & ~T_QUAL_NEAR) != T_QUAL_NONE) {
|
||||||
|
QualCount = GetQualifierTypeCodeNameBuf (&Buf, T->C, T_QUAL_NEAR);
|
||||||
|
if (QualCount > 0) {
|
||||||
|
SB_AppendChar (&Buf, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (SB_IsEmpty (West)) {
|
if (SB_IsEmpty (West)) {
|
||||||
/* Just use the param list */
|
/* Use no parentheses */
|
||||||
SB_Printf (West, "(%s)", SB_GetConstBuf (&ParamList));
|
SB_Terminate (&Buf);
|
||||||
|
|
||||||
|
/* Append the param list to the West */
|
||||||
|
SB_Printf (West, "%s(%s)", SB_GetConstBuf (&Buf), SB_GetConstBuf (&ParamList));
|
||||||
} else {
|
} else {
|
||||||
/* Append the param list to the existing West */
|
/* Append the existing West */
|
||||||
SB_Printf (&Buf, "(%s)(%s)", SB_GetConstBuf (West), SB_GetConstBuf (&ParamList));
|
SB_Append (&Buf, West);
|
||||||
SB_Printf (West, "%s", SB_GetConstBuf (&Buf));
|
SB_Terminate (&Buf);
|
||||||
|
|
||||||
|
/* Append the param list to the West */
|
||||||
|
SB_Printf (West, "(%s)(%s)", SB_GetConstBuf (&Buf), SB_GetConstBuf (&ParamList));
|
||||||
}
|
}
|
||||||
SB_Done (&ParamList);
|
SB_Done (&ParamList);
|
||||||
|
|
||||||
@ -1600,37 +1651,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 +1663,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