Track the main scope of modules.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5174 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -270,6 +270,7 @@ struct ModInfo {
|
|||||||
unsigned Id; /* Id of library if any */
|
unsigned Id; /* Id of library if any */
|
||||||
LibInfo* Info; /* Pointer to library info */
|
LibInfo* Info; /* Pointer to library info */
|
||||||
} Lib;
|
} Lib;
|
||||||
|
ScopeInfo* MainScope; /* Pointer to main scope */
|
||||||
Collection FileInfoByName; /* Files for this module */
|
Collection FileInfoByName; /* Files for this module */
|
||||||
Collection ScopeInfoByName;/* Scopes for this module */
|
Collection ScopeInfoByName;/* Scopes for this module */
|
||||||
char Name[1]; /* Name of module with path */
|
char Name[1]; /* Name of module with path */
|
||||||
@@ -1422,6 +1423,7 @@ static ModInfo* NewModInfo (const StrBuf* Name)
|
|||||||
ModInfo* M = xmalloc (sizeof (ModInfo) + SB_GetLen (Name));
|
ModInfo* M = xmalloc (sizeof (ModInfo) + SB_GetLen (Name));
|
||||||
|
|
||||||
/* Initialize it */
|
/* Initialize it */
|
||||||
|
M->MainScope = 0;
|
||||||
CollInit (&M->FileInfoByName);
|
CollInit (&M->FileInfoByName);
|
||||||
CollInit (&M->ScopeInfoByName);
|
CollInit (&M->ScopeInfoByName);
|
||||||
memcpy (M->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1);
|
memcpy (M->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1);
|
||||||
@@ -1469,6 +1471,7 @@ static void CopyModInfo (cc65_moduledata* D, const ModInfo* M)
|
|||||||
} else {
|
} else {
|
||||||
D->library_id = CC65_INV_ID;
|
D->library_id = CC65_INV_ID;
|
||||||
}
|
}
|
||||||
|
D->scope_id = M->MainScope->Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -4137,6 +4140,14 @@ static void ProcessScopeInfo (InputData* D)
|
|||||||
|
|
||||||
/* Add the scope to the list of scopes for this module */
|
/* Add the scope to the list of scopes for this module */
|
||||||
CollAppend (&S->Mod.Info->ScopeInfoByName, S);
|
CollAppend (&S->Mod.Info->ScopeInfoByName, S);
|
||||||
|
|
||||||
|
/* If this is a main scope, add a pointer to the corresponding
|
||||||
|
* module.
|
||||||
|
*/
|
||||||
|
if (S->Parent.Id == CC65_INV_ID) {
|
||||||
|
/* No parent means main scope */
|
||||||
|
S->Mod.Info->MainScope = S;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resolve the parent scope */
|
/* Resolve the parent scope */
|
||||||
@@ -4185,20 +4196,30 @@ static void ProcessScopeInfo (InputData* D)
|
|||||||
CollReplace (&S->SpanInfoList, SP, J);
|
CollReplace (&S->SpanInfoList, SP, J);
|
||||||
|
|
||||||
/* Insert a backpointer into the span */
|
/* Insert a backpointer into the span */
|
||||||
if (SP->ScopeInfoList == 0) {
|
if (SP->ScopeInfoList == 0) {
|
||||||
SP->ScopeInfoList = CollNew ();
|
SP->ScopeInfoList = CollNew ();
|
||||||
}
|
}
|
||||||
CollAppend (SP->ScopeInfoList, S);
|
CollAppend (SP->ScopeInfoList, S);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Walk over all modules and sort the scopes by name */
|
/* Walk over all modules, check that eacxh one has a main scope assigned,
|
||||||
|
* then sort the scopes by name
|
||||||
|
*/
|
||||||
for (I = 0; I < CollCount (&D->Info->ModInfoById); ++I) {
|
for (I = 0; I < CollCount (&D->Info->ModInfoById); ++I) {
|
||||||
|
|
||||||
/* Get this module */
|
/* Get this module */
|
||||||
ModInfo* M = CollAt (&D->Info->ModInfoById, I);
|
ModInfo* M = CollAt (&D->Info->ModInfoById, I);
|
||||||
|
|
||||||
|
/* Must have a main scope */
|
||||||
|
if (M->MainScope == 0) {
|
||||||
|
ParseError (D,
|
||||||
|
CC65_ERROR,
|
||||||
|
"Module with id %u has no main scope",
|
||||||
|
M->Id);
|
||||||
|
}
|
||||||
|
|
||||||
/* Sort the scopes for this module by name */
|
/* Sort the scopes for this module by name */
|
||||||
CollSort (&M->ScopeInfoByName, CompareScopeInfoByName);
|
CollSort (&M->ScopeInfoByName, CompareScopeInfoByName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ struct cc65_moduledata {
|
|||||||
const char* module_name; /* Name of the module */
|
const char* module_name; /* Name of the module */
|
||||||
unsigned source_id; /* Id of the module main file */
|
unsigned source_id; /* Id of the module main file */
|
||||||
unsigned library_id; /* Id of the library if any */
|
unsigned library_id; /* Id of the library if any */
|
||||||
|
unsigned scope_id; /* Id of the main scope */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct cc65_moduleinfo cc65_moduleinfo;
|
typedef struct cc65_moduleinfo cc65_moduleinfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user