about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorInokentiy Babushkin <twk@twki.de>2017-06-10 21:08:32 +0200
committerInokentiy Babushkin <twk@twki.de>2017-06-10 21:08:32 +0200
commitc2c31b2db33e0d0b5356a0c9e032269034cdc70a (patch)
tree4a2ddeafa8e6ff5a359c2bd954831adfbb60663f /src/libsyntax_pos
parentdd8f7cd126403955295c8b0cdbccc5ca5cbef763 (diff)
downloadrust-c2c31b2db33e0d0b5356a0c9e032269034cdc70a.tar.gz
rust-c2c31b2db33e0d0b5356a0c9e032269034cdc70a.zip
Added external crates' sources to FileMap.
They are now handled in their own member to prevent mutating access to
the `src` member. This way, we can safely load external sources, while
keeping the mutation of local source strings off-limits.
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 75ce8b675f3..d6adf45e68a 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -374,6 +374,14 @@ pub struct MultiByteChar {
     pub bytes: usize,
 }
 
+#[derive(PartialEq, Eq, Clone)]
+pub enum ExternalSource {
+    Present(String),
+    AbsentOk,
+    AbsentErr,
+    Unneeded,
+}
+
 /// A single source in the CodeMap.
 #[derive(Clone)]
 pub struct FileMap {
@@ -389,6 +397,9 @@ pub struct FileMap {
     pub src: Option<Rc<String>>,
     /// The source code's hash
     pub src_hash: u128,
+    /// The external source code (used for external crates, which will have a `None`
+    /// value as `self.src`.
+    pub external_src: RefCell<ExternalSource>,
     /// The start position of this source in the CodeMap
     pub start_pos: BytePos,
     /// The end position of this source in the CodeMap
@@ -513,6 +524,7 @@ impl Decodable for FileMap {
                 end_pos: end_pos,
                 src: None,
                 src_hash: src_hash,
+                external_src: RefCell::new(ExternalSource::AbsentOk),
                 lines: RefCell::new(lines),
                 multibyte_chars: RefCell::new(multibyte_chars)
             })
@@ -545,6 +557,7 @@ impl FileMap {
             crate_of_origin: 0,
             src: Some(Rc::new(src)),
             src_hash: src_hash,
+            external_src: RefCell::new(ExternalSource::Unneeded),
             start_pos: start_pos,
             end_pos: Pos::from_usize(end_pos),
             lines: RefCell::new(Vec::new()),