Next: Advance to the next
Up: Package Storage in the
Previous: Import a specific type
The scope of a type introduced by a class or interface declaration is the
declarations of all class and interface declarations of all compilation
units of the package in which it is declared.
When a package declaration is encountered in a program, the compiler must
make all class and interface declarations of that package available.
Similarly, an import-on-demand declaration makes all of those types
available.
void ImportPackage(char *pkg, DefTableKey key)[6]
:
/* Import package files
* On entry-
* pkg is the name of the package whose files are to be imported
* key is the key under which the package's type environment
* is to be stored
* pkg has not yet been examined
* On exit-
* The package's type environment has been established and stored
* Its fully-qualified types have been defined in TypRootEnv
* The .java files in pkg have been defined in FilRootEnv
***/
{ DIR *package;
char cwd[MAX_PATH+1], *dir;
struct dirent *this_entry;
int dirlen;
Environment env;
if((dir = DirectoryFor(pkg, strlen(pkg))) == NULL) return;
dirlen = strlen(dir);
if (!getcwd(cwd, MAX_PATH+1)) {
(void)perror(cwd);
return;
}
package = opendir(dir);
if (!package) {
(void)perror(dir);
return;
}
if (chdir(dir)) {
(void)perror(dir);
if (closedir(package)) (void)perror(dir);
return;
}
env = NewScope(PtyRootEnv);
ResetPtyScope(key, env);
ResetTypScope(key, env);
while(this_entry = readdir(package)) {
if ((strcmp(this_entry->d_name, ".") != 0) &&
(strcmp(this_entry->d_name, "..") != 0)) {
struct stat status;
if (stat(this_entry->d_name, &status)) {
(void)perror(this_entry->d_name);
break;
}
if (S_ISREG(status.st_mode)) {
char *tail;
if (tail = strchr(this_entry->d_name, '.')) {
if (strcmp(tail, ".java") == 0) {
Binding bind;
int len = strlen(this_entry->d_name);
obstack_grow(Csm_obstk, dir, dirlen);
CsmStrPtr = obstack_copy0(Csm_obstk, this_entry->d_name, len);
BindInScope(FilRootEnv, MakeName(CsmStrPtr));
}
}
}
}
}
if (chdir(cwd)) (void)perror(cwd);
if (closedir(package)) (void)perror(dir);
}
This macro is invoked in definition 9.
Next: Advance to the next
Up: Package Storage in the
Previous: Import a specific type
2008-09-11