Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/compiler/MiscUtil/util/source.nw
ViewVC logotype

View of /sml/trunk/src/compiler/MiscUtil/util/source.nw

Parent Directory Parent Directory | Revision Log Revision Log


Revision 114 - (download) (annotate)
Fri Jun 5 19:41:21 1998 UTC (22 years, 2 months ago) by monnier
File size: 5157 byte(s)
This commit was generated by cvs2svn to compensate for changes in r113,
which included commits to RCS files with non-trunk default branches.
<<source.sig>>=
(* source.sig
 *
 * COPYRIGHT (c) 1996 Bell Laboratories.
 *
 * $Log: source.nw,v $
 * Revision 1.1.1.1  1997/01/14  01:38:49  george
 *   Version 109.24
 *
# Revision 1.1  1996/08/08  19:30:29  nr
# split old Source structure into Source and SourceMap
#
# changed ErrorMsg to use SourceMap to get source locations; only the
# formatting is done internally
#
# added SourceMap structure
#
# .sig and .sml for sourcemap, source, and errormsg are derived from .nw
# files.  to extract, try
#   for base in sourcemap source errormsg
#   do
#     for suffix in sml sig
#     do
#       $cmd -L'(*#line %L "%F"*)' -R$base.$suffix $base.nw > $base.$suffix
#     done
#   done
# where
#   cmd=notangle
# or
#   cmd="nountangle -ml"
#
# At some point, it may be desirable to move noweb support into CM
#
 * Revision 1.6  1996/07/29  15:24:04  jhr
 * Removed index file mechanism.
 *
 * Revision 1.5  1996/03/22  15:58:23  jhr
 * Changed code to use TextIO.openString.
 *
 * Revision 1.4  1996/02/26  14:56:52  george
 *   print no longer overloaded.
 *   use of makestring has been removed and replaced with Int.toString ..
 *   use of IO replaced with TextIO
 *
 * Revision 1.3  1996/02/21  16:28:52  jhr
 * Added copyright and CVS Log tag
 *
 *)
<<source.sig>>=
signature SOURCE =
  sig
    type inputSource = {
	sourceMap: SourceMap.sourcemap,
	fileOpened: string,
	interactive: bool,
	sourceStream: TextIO.instream, 
	anyErrors: bool ref,
	errConsumer: PrettyPrint.ppconsumer
      }

    val newSource : (string * int * TextIO.instream * bool * PrettyPrint.ppconsumer)
	  -> inputSource
    val closeSource: inputSource -> unit
    val filepos: inputSource -> SourceMap.charpos -> string * int * int

  end
@ 
The [[fileOpened]] field contains the name of the file that was opened
to produce a particular [[inputSource]].
It is used only to derive related file names.
(For an example, see [[CompileF.codeopt]] and [[CompileF.parse]] in
\texttt{build/compile.sml}.) 

[[newSource]] has some old warts build in.  It takes as argument a
file and line number, and it assumes column~1.  The reason we don't
simply pass a [[SourceMap.sourcemap]] is that we have to hide the
awful truth about the beginning position according to ml-lex (it's~2).
That position, and therefore the creation of the source map, are
encapsulated inside [[newSource]].

[[filepos]] is kept around for historical reasons, to avoid having to
change lots of code elsewhere in the compiler; it wraps a
call to [[SourceMap.filepos]] and massages the return type.  
It probably should be eliminated, but then somebody would have to fix
all those call sites.
<<source.sig>>=
@ 
<<source.sml>>=
(* source.sml
 *
 * COPYRIGHT (c) 1996 Bell Laboratories.
 *
 * $Log: source.nw,v $
 * Revision 1.1.1.1  1997/01/14  01:38:49  george
 *   Version 109.24
 *
# Revision 1.1  1996/08/08  19:30:29  nr
# split old Source structure into Source and SourceMap
#
# changed ErrorMsg to use SourceMap to get source locations; only the
# formatting is done internally
#
# added SourceMap structure
#
# .sig and .sml for sourcemap, source, and errormsg are derived from .nw
# files.  to extract, try
#   for base in sourcemap source errormsg
#   do
#     for suffix in sml sig
#     do
#       $cmd -L'(*#line %L "%F"*)' -R$base.$suffix $base.nw > $base.$suffix
#     done
#   done
# where
#   cmd=notangle
# or
#   cmd="nountangle -ml"
#
# At some point, it may be desirable to move noweb support into CM
#
 * Revision 1.7  1996/07/29  15:24:05  jhr
 * Removed index file mechanism.
 *
 * Revision 1.6  1996/03/22  15:58:24  jhr
 * Changed code to use TextIO.openString.
 *
 * Revision 1.5  1996/03/18  15:33:53  jhr
 * Added new I/O implementation, which implements the SML Basis Library API.
 *
 * Revision 1.4  1996/02/26  14:56:52  george
 *   print no longer overloaded.
 *   use of makestring has been removed and replaced with Int.toString ..
 *   use of IO replaced with TextIO
 *
 * Revision 1.3  1996/02/21  16:28:52  jhr
 * Added copyright and CVS Log tag
 *
 *)

structure Source : SOURCE =
struct

  type inputSource = {
	sourceMap: SourceMap.sourcemap,
	fileOpened: string,
	anyErrors: bool ref,
	errConsumer: PrettyPrint.ppconsumer,
	interactive: bool,
	sourceStream: TextIO.instream
      }

  fun say (msg : string) = Control.Print.say msg

  val lexer_initial_position = 2 (* position of first char according to ml-lex *)

  fun newSource(fileName,lineNum,sourceStream,interactive, errConsumer) =
      {sourceMap=SourceMap.newmap(lexer_initial_position, 
                                  {fileName=fileName, line=lineNum, column=1}),
       sourceStream=sourceStream,interactive=interactive,fileOpened=fileName,
       errConsumer=errConsumer,anyErrors=ref false}

  fun closeSource ({interactive=true, ...} : inputSource) = ()
    | closeSource ({sourceStream, ...}) = (
	(* app say ["[closing ", (Pathnames.trim fileName), "]\n"];*)
	TextIO.closeIn sourceStream handle IO.Io _ => ())

  fun filepos({sourceMap,...}: inputSource) pos = 
    let val {fileName, line, column} = SourceMap.filepos sourceMap pos
    in  (fileName, line, column)
    end

end (* structure Source *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0