next up previous contents
Next: 11.2.2 Adding a class Up: 11.2 Adding other classes Previous: 11.2 Adding other classes   Contents

11.2.1 Filename abstractions

CM represents filenames as something that could be called a filename closure. Essentially, what this means is that not only a string is being remembered but also the context in which to interpret the string. For a relative path, context information is the directory in which it is to be interpreted; for an anchored path, the context takes care of the anchoring.

The Tools module provides two abstract types related to this filename abstraction:


  type presrcpath
  type srcpath

Since many tools invoke external shell commands or perform other operation on physical files, it is often necessary to obtain an actual native filename string from an abstract path:


  val nativeSpec : srcpath -> string
  val nativePreSpec : presrcpath -> string

It is important to remember that these two functions frequently return relative filenames, and such relative names must be interpreted from within the right directory. This ``right'' directory is the directory that contains the CM description file on whose behalf the tool's rule was invoked. Rules that perform physical operations on files whose names result from nativeSpec or nativePreSpec must therefore first switch to that directory. See the discussion of the context argument to rule functions below.

Strings that can potentially be used as pathnames are being passed around as records containing a name- and a mkpath field. The name field contains the string itself while mkpath is a ``suspended'' abstract version of the path.

A fresh pathmaker can be constructed from native strings using native2pathmaker, which like context is also an argument to rule functions. This function takes care of interpreting relative strings within the correct context. (For this, it is not even necessary to first switch the current working directory.)

Recall that filenames that appear in description files can be written using either ``standard'' or ``native'' syntax. The field name will, thus, contain a string that can be in either of these two forms. However, CM will pass an mkpath function that accounts for these syntactic differences and which also takes care of interpreting the string in the correct context.

When new name specifications are constructed by the tool, the appropriate mkpath function must be provided. For most tools this will be a value constructed by applying native2pathmaker to some native filename string (because most tools internally operate on native paths).

As shown above, there are two abstract path types: presrcpath and srcpath. The former can represent both directory names and source file names, the latter can represent only source file names. To convert from presrcpath to srcpath, use function Tools.srcpath:


  val srcpath : presrcpath -> srcpath
This function enforces CM's rule that there has to be at least one arc in every such name (i.e., that it cannot be just an anchor).

One can also construct a new abstract path from an existing path by adding arcs at the end. The constructed path will share its internal context with the old one.


  val augment : presrcpath -> string list -> presrcpath

The list of strings must contain simple pathname arcs.


next up previous contents
Next: 11.2.2 Adding a class Up: 11.2 Adding other classes Previous: 11.2 Adding other classes   Contents
Matthias Blume
2001-07-19