ModuleGraphs.Mesa
Mike Spreitzer August 21, 1986 3:58:22 pm PDT
DIRECTORY AMModel, Atom, Graphs, Rope, VM, WorldVM;
ModuleGraphs: CEDAR PROGRAM
IMPORTS AMModel, Atom, Graphs, Rope, VM, WorldVM
=
BEGIN
ROPE: TYPE = Rope.ROPE;
vertexKey: ATOM ← Atom.MakeAtom["Spreitzer January 5, 1984 6:48 pm"];
worldContext: AMModel.Context;
NewModuleVertex: PROC [moduleName: ROPE] RETURNS [vertex: Graphs.Vertex] =
BEGIN
atom: ATOM ← Atom.MakeAtom[moduleName];
IF (vertex ← NARROW[Atom.GetProp[atom: atom, prop: vertexKey]]) # NIL THEN RETURN;
Atom.PutProp[
atom: atom,
prop: vertexKey,
val: vertex ← NEW [Graphs.VertexPrivate ← [
class: moduleVertexClass,
rep: moduleName]]
];
END;
ExpandModule: PROC [vertex: Graphs.Vertex, consume: Graphs.EdgeConsumer, filter: Graphs.EdgeFilter ← Graphs.all] --Graphs.ExpandProc-- =
BEGIN
moduleName: ROPE = NARROW[vertex.rep];
IF filter[Incoming] THEN ERROR Graphs.Cant;
IF NOT filter[Outgoing] THEN RETURN;
consume.proc[[Outgoing, "imports", NewImportsVertex[moduleName]], consume.data];
consume.proc[[Outgoing, "exports", NewExportsVertex[moduleName]], consume.data];
END;
NewImportsVertex: PROC [moduleName: ROPE] RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ← NEW [Graphs.VertexPrivate ← [
class: importsVertexClass,
rep: moduleName]]
END;
NewExportsVertex: PROC [moduleName: ROPE] RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ← NEW [Graphs.VertexPrivate ← [
class: exportsVertexClass,
rep: moduleName]]
END;
ExpandImports: PROC [vertex: Graphs.Vertex, consume: Graphs.EdgeConsumer, filter: Graphs.EdgeFilter ← Graphs.all] --Graphs.ExpandProc-- =
BEGIN
moduleName: ROPENARROW[vertex.rep];
context: AMModel.Context;
imports: LIST OF AMModel.PartialInterfaceInstance;
IF filter[Incoming] THEN ERROR Graphs.Cant;
IF NOT filter[Outgoing] THEN RETURN;
TRUSTED {context ← AMModel.MostRecentNamedContext[name: moduleName, context: worldContext]};
IF context = NIL THEN RETURN;
TRUSTED {imports ← AMModel.Imports[context !VM.AddressFault => CONTINUE]};
FOR imports ← imports, imports.rest WHILE imports # NIL DO
name: ROPE;
TRUSTED {name ← AMModel.ContextName[imports.first.ir]};
consume.proc[[Outgoing, name, NewInterfaceVertex[name]], consume.data];
ENDLOOP;
END;
ExpandExports: PROC [vertex: Graphs.Vertex, consume: Graphs.EdgeConsumer, filter: Graphs.EdgeFilter ← Graphs.all] --Graphs.ExpandProc-- =
BEGIN
moduleName: ROPENARROW[vertex.rep];
context: AMModel.Context;
exports: LIST OF AMModel.PartialInterfaceInstance;
IF filter[Incoming] THEN ERROR Graphs.Cant;
IF NOT filter[Outgoing] THEN RETURN;
TRUSTED {context ← AMModel.MostRecentNamedContext[name: moduleName, context: worldContext]};
IF context = NIL THEN RETURN;
TRUSTED {exports ← AMModel.Exports[context !VM.AddressFault => CONTINUE]};
FOR exports ← exports, exports.rest WHILE exports # NIL DO
name: ROPE;
TRUSTED {name ← AMModel.ContextName[exports.first.ir]};
consume.proc[[Outgoing, name, NewInterfaceVertex[name]], consume.data];
ENDLOOP;
END;
NewInterfaceVertex: PROC [moduleName: ROPE] RETURNS [vertex: Graphs.Vertex] =
BEGIN
atom: ATOM ← Atom.MakeAtom[moduleName];
IF (vertex ← NARROW[Atom.GetProp[atom: atom, prop: vertexKey]]) # NIL THEN RETURN;
Atom.PutProp[
atom: atom,
prop: vertexKey,
val: vertex ← NEW [Graphs.VertexPrivate ← [
class: interfaceVertexClass,
rep: moduleName]]
];
END;
ExpandInterface: PROC [vertex: Graphs.Vertex, consume: Graphs.EdgeConsumer, filter: Graphs.EdgeFilter ← Graphs.all] --Graphs.ExpandProc-- =
BEGIN
interfaceName: ROPE = NARROW[vertex.rep];
IF filter[Incoming] THEN ERROR Graphs.Cant;
IF NOT filter[Outgoing] THEN RETURN;
consume.proc[[Outgoing, "importedBy", NewImportedByVertex[interfaceName]], consume.data];
consume.proc[[Outgoing, "exportedBy", NewExportedByVertex[interfaceName]], consume.data];
END;
NewImportedByVertex: PROC [moduleName: ROPE] RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ← NEW [Graphs.VertexPrivate ← [
class: importedByVertexClass,
rep: moduleName]]
END;
NewExportedByVertex: PROC [moduleName: ROPE] RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ← NEW [Graphs.VertexPrivate ← [
class: exportedByVertexClass,
rep: moduleName]]
END;
ExpandImportedBy: PROC [vertex: Graphs.Vertex, consume: Graphs.EdgeConsumer, filter: Graphs.EdgeFilter ← Graphs.all] --Graphs.ExpandProc-- =
BEGIN
interfaceName: ROPENARROW[vertex.rep];
FindInterface: PROC [prog: AMModel.Context] RETURNS [stop: BOOLEAN] =
BEGIN
imports: LIST OF AMModel.PartialInterfaceInstance;
TRUSTED {imports ← AMModel.Imports[prog !VM.AddressFault => CONTINUE]};
stop ← FALSE;
FOR imports ← imports, imports.rest WHILE imports # NIL DO
name: ROPE;
TRUSTED {name ← AMModel.ContextName[imports.first.ir]};
IF name.Equal[interfaceName] THEN {
consume.proc[[Outgoing, name, NewModuleVertex[name]], consume.data];
EXIT};
ENDLOOP;
END;
IF filter[Incoming] THEN ERROR Graphs.Cant;
IF NOT filter[Outgoing] THEN RETURN;
TRUSTED {[] ← AMModel.ContextChildren[context: worldContext, proc: FindInterface]};
END;
ExpandExportedBy: PROC [vertex: Graphs.Vertex, consume: Graphs.EdgeConsumer, filter: Graphs.EdgeFilter ← Graphs.all] --Graphs.ExpandProc-- =
BEGIN
interfaceName: ROPENARROW[vertex.rep];
FindInterface: PROC [prog: AMModel.Context] RETURNS [stop: BOOLEAN] =
BEGIN
exports: LIST OF AMModel.PartialInterfaceInstance;
TRUSTED {exports ← AMModel.Exports[prog !VM.AddressFault => CONTINUE]};
stop ← FALSE;
FOR exports ← exports, exports.rest WHILE exports # NIL DO
name: ROPE;
TRUSTED {name ← AMModel.ContextName[exports.first.ir]};
IF name.Equal[interfaceName] THEN {
consume.proc[[Outgoing, name, NewModuleVertex[name]], consume.data];
EXIT};
ENDLOOP;
END;
IF filter[Incoming] THEN ERROR Graphs.Cant;
IF NOT filter[Outgoing] THEN RETURN;
TRUSTED {[] ← AMModel.ContextChildren[context: worldContext, proc: FindInterface]};
END;
moduleVertexClass: Graphs.VertexClass ← Graphs.NewVertexClass[[
Expand: ExpandModule
]];
importsVertexClass: Graphs.VertexClass ← Graphs.NewVertexClass[[
Expand: ExpandImports
]];
exportsVertexClass: Graphs.VertexClass ← Graphs.NewVertexClass[[
Expand: ExpandExports
]];
interfaceVertexClass: Graphs.VertexClass ← Graphs.NewVertexClass[[
Expand: ExpandInterface
]];
importedByVertexClass: Graphs.VertexClass ← Graphs.NewVertexClass[[
Expand: ExpandImportedBy
]];
exportedByVertexClass: Graphs.VertexClass ← Graphs.NewVertexClass[[
Expand: ExpandExportedBy
]];
TRUSTED {worldContext ← AMModel.RootContext[WorldVM.LocalWorld[]]};
END.
GraphBrowsers.Browse[vertex: ModuleGraphs.NewModuleVertex["ModuleGraphs"], browserClass: GraphBrowsers.basicBrowserClass, viewerInit: [name: "ModuleGraphs", iconic: FALSE]]