unsigned Id; /* Id of library if any */
LibInfo* Info; /* Pointer to library info */
} Lib;
+ ScopeInfo* MainScope; /* Pointer to main scope */
Collection FileInfoByName; /* Files for this module */
Collection ScopeInfoByName;/* Scopes for this module */
char Name[1]; /* Name of module with path */
ModInfo* M = xmalloc (sizeof (ModInfo) + SB_GetLen (Name));
/* Initialize it */
+ M->MainScope = 0;
CollInit (&M->FileInfoByName);
CollInit (&M->ScopeInfoByName);
memcpy (M->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1);
} else {
D->library_id = CC65_INV_ID;
}
+ D->scope_id = M->MainScope->Id;
}
CollGrow (&D->Info->SpanInfoById, D->IVal);
break;
- case TOK_SYM:
+ case TOK_SYM:
CollGrow (&D->Info->SymInfoById, D->IVal);
CollGrow (&D->Info->SymInfoByName, D->IVal);
CollGrow (&D->Info->SymInfoByVal, D->IVal);
/* Add the scope to the list of scopes for this module */
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 */
CollReplace (&S->SpanInfoList, SP, J);
/* Insert a backpointer into the span */
- if (SP->ScopeInfoList == 0) {
- SP->ScopeInfoList = CollNew ();
- }
+ if (SP->ScopeInfoList == 0) {
+ SP->ScopeInfoList = CollNew ();
+ }
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) {
/* Get this module */
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 */
CollSort (&M->ScopeInfoByName, CompareScopeInfoByName);
}
const char* module_name; /* Name of the module */
unsigned source_id; /* Id of the module main file */
unsigned library_id; /* Id of the library if any */
+ unsigned scope_id; /* Id of the main scope */
};
typedef struct cc65_moduleinfo cc65_moduleinfo;
cc65_size span_size; /* Size of the span */
unsigned segment_id; /* Id of the segment */
};
-
+
typedef struct cc65_spaninfo cc65_spaninfo;
struct cc65_spaninfo {
unsigned count; /* Number of data sets that follow */
cc65_spandata data[1]; /* Data sets, number is dynamic */
};
-
+
cc65_spaninfo* cc65_get_spanlist (cc65_dbginfo handle);
/* Return a list of all spans */
* cc65_spaninfo structure with one entry that contains the requested
* span information.
*/
-
+
void cc65_free_spaninfo (cc65_dbginfo handle, cc65_spaninfo* info);
/* Free a span info record */