From 47df3de153a2b976def504ca0d59cb91d9047f3a Mon Sep 17 00:00:00 2001 From: "Geoffrey.Coram" Date: Thu, 11 Jul 2024 16:14:58 -0400 Subject: [PATCH] Ignore `resetall (rather than erroring out) See https://github.com/pascalkuthe/OpenVAF/issues/124 --- openvaf/basedb/src/diagnostics/preprocessor_error.rs | 10 ++++++++++ openvaf/preprocessor/src/diagnostics.rs | 2 ++ openvaf/preprocessor/src/parser.rs | 2 ++ openvaf/preprocessor/src/processor.rs | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/openvaf/basedb/src/diagnostics/preprocessor_error.rs b/openvaf/basedb/src/diagnostics/preprocessor_error.rs index 308ff2b5..61a91042 100755 --- a/openvaf/basedb/src/diagnostics/preprocessor_error.rs +++ b/openvaf/basedb/src/diagnostics/preprocessor_error.rs @@ -52,6 +52,16 @@ impl Diagnostic for PreprocessorDiagnostic { }]) } PreprocessorDiagnostic::MacroRecursion { .. } => todo!(), + PreprocessorDiagnostic::UnsupportedCompDir { span, .. } => { + let span = span.to_file_span(&sm); + + Report::warning().with_labels(vec![Label { + style: LabelStyle::Primary, + file_id: span.file, + range: span.range.into(), + message: "directive ignored".to_owned(), + }]) + } PreprocessorDiagnostic::FileNotFound { span, .. } => { let labels = if let Some(span) = span { let span = span.to_file_span(&sm); diff --git a/openvaf/preprocessor/src/diagnostics.rs b/openvaf/preprocessor/src/diagnostics.rs index 6e8f1744..5a840df4 100644 --- a/openvaf/preprocessor/src/diagnostics.rs +++ b/openvaf/preprocessor/src/diagnostics.rs @@ -11,6 +11,7 @@ pub enum PreprocessorDiagnostic { MacroNotFound { name: String, span: CtxSpan }, MacroNotDefined { name: String, span: CtxSpan }, MacroRecursion { name: String, span: CtxSpan }, + UnsupportedCompDir { name: String, span: CtxSpan }, FileNotFound { file: String, error: io::ErrorKind, span: Option }, InvalidTextFormat { span: Option, file: VfsPath, err: InvalidTextFormatErr }, UnexpectedEof { expected: &'static str, span: CtxSpan }, @@ -26,6 +27,7 @@ impl_display! { MacroNotFound{name,..} => "macro '`{}' has not been declared", name; MacroNotDefined{name,..} => "cannot undefine macro '`{}'", name; MacroRecursion { name,..} => "macro '`{}' was called recursively",name; + UnsupportedCompDir { name,.. } => "unsupported compiler directive {}",name; FileNotFound { file, error, .. } => "failed to read '{}': {}", file, std::io::Error::from(*error); InvalidTextFormat { file, ..} => "failed to read {}: file contents are not valid text", file; UnexpectedEof { expected ,..} => "unexpected EOF, expected {}",expected; diff --git a/openvaf/preprocessor/src/parser.rs b/openvaf/preprocessor/src/parser.rs index acee37d6..707fe630 100755 --- a/openvaf/preprocessor/src/parser.rs +++ b/openvaf/preprocessor/src/parser.rs @@ -305,6 +305,7 @@ impl<'a, 'd> Parser<'a, 'd> { "`elsif" => CompilerDirective::ElseIf, "`endif" => CompilerDirective::EndIf, "`undef" => CompilerDirective::Undef, + "`resetall" => CompilerDirective::ResetAll, _ => CompilerDirective::Macro, } } @@ -332,5 +333,6 @@ pub enum CompilerDirective { ElseIf, EndIf, Undef, + ResetAll, Macro, } diff --git a/openvaf/preprocessor/src/processor.rs b/openvaf/preprocessor/src/processor.rs index 82b3a007..4950edcd 100755 --- a/openvaf/preprocessor/src/processor.rs +++ b/openvaf/preprocessor/src/processor.rs @@ -248,6 +248,14 @@ impl<'a> Processor<'a> { } p.bump(); } + CompilerDirective::ResetAll => { + let name = p.current_text(); + err.push(PreprocessorDiagnostic::UnsupportedCompDir { + name: name.to_owned(), + span: p.current_span() + }); + p.bump(); + } CompilerDirective::Macro => { let (call, range) = parse_macro_call(p, err, &[], &mut self.source_map, p.end());