ModuleGraphs.Mesa
Last Edited by: Spreitzer, June 6, 1985 5:24:47 pm PDT
DIRECTORY AMModel, Atom, Graphs, Rope, WorldVM;
ModuleGraphs:
CEDAR
PROGRAM
IMPORTS AMModel, Atom, Rope, 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.VertexRep ← [
type: moduleVertexType,
rep: moduleName]]
];
END;
ExpandModule: Graphs.ExpandProc
--PROC [vertex: Vertex, consume: EdgeConsumer, data: REF ANY ← NIL]-- =
BEGIN
moduleName: ROPE ← NARROW[vertex.rep];
consume.proc[["imports", NewImportsVertex[moduleName]], consume.data];
consume.proc[["exports", NewExportsVertex[moduleName]], consume.data];
END;
NewImportsVertex:
PROC [moduleName:
ROPE]
RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ←
NEW [Graphs.VertexRep ← [
type: importsVertexType,
rep: moduleName]]
END;
NewExportsVertex:
PROC [moduleName:
ROPE]
RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ←
NEW [Graphs.VertexRep ← [
type: exportsVertexType,
rep: moduleName]]
END;
ExpandImports: Graphs.ExpandProc
--PROC [vertex: Vertex, consume: EdgeConsumer, data: REF ANY ← NIL]-- =
BEGIN
moduleName: ROPE ← NARROW[vertex.rep];
context: AMModel.Context;
imports: LIST OF AMModel.PartialInterfaceInstance;
TRUSTED {context ← AMModel.MostRecentNamedContext[name: moduleName, context: worldContext]};
IF context = NIL THEN RETURN;
TRUSTED {imports ← AMModel.Imports[context]};
FOR imports ← imports, imports.rest
WHILE imports #
NIL
DO
name: ROPE;
TRUSTED {name ← AMModel.ContextName[imports.first.ir]};
consume.proc[[name, NewInterfaceVertex[name]], consume.data];
ENDLOOP;
END;
ExpandExports: Graphs.ExpandProc
--PROC [vertex: Vertex, consume: EdgeConsumer, data: REF ANY ← NIL]-- =
BEGIN
moduleName: ROPE ← NARROW[vertex.rep];
context: AMModel.Context;
exports: LIST OF AMModel.PartialInterfaceInstance;
TRUSTED {context ← AMModel.MostRecentNamedContext[name: moduleName, context: worldContext]};
IF context = NIL THEN RETURN;
TRUSTED {exports ← AMModel.Exports[context]};
FOR exports ← exports, exports.rest
WHILE exports #
NIL
DO
name: ROPE;
TRUSTED {name ← AMModel.ContextName[exports.first.ir]};
consume.proc[[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.VertexRep ← [
type: interfaceVertexType,
rep: moduleName]]
];
END;
ExpandInterface: Graphs.ExpandProc
--PROC [vertex: Vertex, consume: EdgeConsumer, data: REF ANY ← NIL]-- =
BEGIN
interfaceName: ROPE ← NARROW[vertex.rep];
consume.proc[["importedBy", NewImportedByVertex[interfaceName]], consume.data];
consume.proc[["exportedBy", NewExportedByVertex[interfaceName]], consume.data];
END;
NewImportedByVertex:
PROC [moduleName:
ROPE]
RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ←
NEW [Graphs.VertexRep ← [
type: importedByVertexType,
rep: moduleName]]
END;
NewExportedByVertex:
PROC [moduleName:
ROPE]
RETURNS [vertex: Graphs.Vertex] =
BEGIN
vertex ←
NEW [Graphs.VertexRep ← [
type: exportedByVertexType,
rep: moduleName]]
END;
ExpandImportedBy: Graphs.ExpandProc
--PROC [vertex: Vertex, consume: EdgeConsumer, data: REF ANY ← NIL]-- =
BEGIN
interfaceName: ROPE ← NARROW[vertex.rep];
FindInterface:
PROC [prog: AMModel.Context]
RETURNS [stop:
BOOLEAN] =
BEGIN
imports: LIST OF AMModel.PartialInterfaceInstance;
TRUSTED {imports ← AMModel.Imports[prog]};
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[[name, NewModuleVertex[name]], consume.data];
EXIT};
ENDLOOP;
END;
TRUSTED {[] ← AMModel.ContextChildren[context: worldContext, proc: FindInterface]};
END;
ExpandExportedBy: Graphs.ExpandProc
--PROC [vertex: Vertex, consume: EdgeConsumer, data: REF ANY ← NIL]-- =
BEGIN
interfaceName: ROPE ← NARROW[vertex.rep];
FindInterface:
PROC [prog: AMModel.Context]
RETURNS [stop:
BOOLEAN] =
BEGIN
exports: LIST OF AMModel.PartialInterfaceInstance;
TRUSTED {exports ← AMModel.Exports[prog]};
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[[name, NewModuleVertex[name]], consume.data];
EXIT};
ENDLOOP;
END;
TRUSTED {[] ← AMModel.ContextChildren[context: worldContext, proc: FindInterface]};
END;
moduleVertexType: Graphs.VertexType ←
NEW [Graphs.VertexTypeRep ← [
Expand: ExpandModule
]];
importsVertexType: Graphs.VertexType ←
NEW [Graphs.VertexTypeRep ← [
Expand: ExpandImports
]];
exportsVertexType: Graphs.VertexType ←
NEW [Graphs.VertexTypeRep ← [
Expand: ExpandExports
]];
interfaceVertexType: Graphs.VertexType ←
NEW [Graphs.VertexTypeRep ← [
Expand: ExpandInterface
]];
importedByVertexType: Graphs.VertexType ←
NEW [Graphs.VertexTypeRep ← [
Expand: ExpandImportedBy
]];
exportedByVertexType: Graphs.VertexType ←
NEW [Graphs.VertexTypeRep ← [
Expand: ExpandExportedBy
]];
TRUSTED {worldContext ← AMModel.RootContext[WorldVM.LocalWorld[]]};
END.
GraphBrowsers.Browse[vertex: ModuleGraphs.NewModuleVertex["ModuleGraphs"], browserClass: GraphBrowsers.basicBrowserClass, viewerInit: [name: "ModuleGraphs", iconic: FALSE]]