1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays definitions generic assocs kernel math namespaces
4 prettyprint sequences strings vectors words quotations inspector
5 io.styles io combinators sorting splitting math.parser effects
6 continuations debugger io.files checksums checksums.crc32 vocabs
7 hashtables graphs compiler.units io.encodings.utf8 accessors ;
17 : record-checksum ( lines source-file -- )
18 >r crc32 checksum-lines r> set-source-file-checksum ;
20 : (xref-source) ( source-file -- pathname uses )
21 dup source-file-path <pathname>
22 swap source-file-uses [ crossref? ] filter ;
24 : xref-source ( source-file -- )
25 (xref-source) crossref get add-vertex ;
27 : unxref-source ( source-file -- )
28 (xref-source) crossref get remove-vertex ;
31 source-files get [ nip xref-source ] assoc-each ;
33 : record-form ( quot source-file -- )
35 swap quot-uses keys over set-source-file-uses
38 : record-definitions ( file -- )
39 new-definitions get swap set-source-file-definitions ;
41 : <source-file> ( path -- source-file )
44 <definitions> >>definitions ;
46 : source-file ( path -- source-file )
47 dup string? [ "Invalid source file path" throw ] unless
48 source-files get [ <source-file> ] cache ;
50 : reset-checksums ( -- )
53 utf8 file-lines swap record-checksum
57 M: pathname where pathname-string 1 2array ;
59 : forget-source ( path -- )
63 [ definitions>> [ keys forget-all ] each ]
66 [ source-files get delete-at ]
70 pathname-string forget-source ;
72 : rollback-source-file ( file -- )
73 dup source-file-definitions new-definitions get [ assoc-union ] 2map
74 swap set-source-file-definitions ;
78 TUPLE: source-file-error file error ;
80 : <source-file-error> ( msg -- error )
81 \ source-file-error new
85 : file. ( file -- ) path>> <pathname> . ;
87 M: source-file-error error.
88 [ file>> file. ] [ error>> error. ] bi ;
90 M: source-file-error summary
93 M: source-file-error compute-restarts
94 error>> compute-restarts ;
96 M: source-file-error error-help
99 : with-source-file ( name quot -- )
100 #! Should be called from inside with-compilation-unit.
104 source-file-definitions old-definitions set
106 file get rollback-source-file
107 <source-file-error> rethrow
109 ] with-scope ; inline