@@ -320,6 +320,7 @@ namespace pl::core {
320320 std::ranges::copy (preprocessor.m_pragmas .begin (), preprocessor.m_pragmas .end (), std::inserter (this ->m_pragmas , this ->m_pragmas .begin ()));
321321 std::ranges::copy (preprocessor.m_keys .begin (), preprocessor.m_keys .end (), std::inserter (this ->m_keys , this ->m_keys .begin ()));
322322 std::ranges::copy (preprocessor.m_namespaces .begin (), preprocessor.m_namespaces .end (), std::inserter (this ->m_namespaces , this ->m_namespaces .begin ()));
323+ std::ranges::copy (preprocessor.m_parsedImports .begin (), preprocessor.m_parsedImports .end (),std::inserter (this ->m_parsedImports , this ->m_parsedImports .begin ()));
323324
324325 if (shouldInclude) {
325326 auto content = result.unwrap ();
@@ -540,19 +541,16 @@ namespace pl::core {
540541 for (auto token = tokens.begin (); token != tokens.end (); token++ ) {
541542 u32 idx = 1 ;
542543 if (auto *keyword = std::get_if<Token::Keyword>(&token->value ); keyword != nullptr && *keyword == Token::Keyword::Namespace) {
543- if (auto *valueType = std::get_if<Token::ValueType>(&token[1 ].value );
544- valueType != nullptr && *valueType == Token::ValueType::Auto)
544+ if (auto *valueType = std::get_if<Token::ValueType>(&token[1 ].value ); valueType != nullptr && *valueType == Token::ValueType::Auto)
545545 idx += 1 ;
546546 auto *identifier = std::get_if<Token::Identifier>(&token[idx].value );
547547 while (identifier != nullptr ) {
548- if (auto *separator = std::get_if<Token::Separator>(&token[idx].value );
549- separator != nullptr && *separator == Token::Separator::EndOfProgram)
548+ if (auto *separator = std::get_if<Token::Separator>(&token[idx].value ); separator != nullptr && *separator == Token::Separator::EndOfProgram)
550549 break ;
551550 if (std::ranges::find (m_namespaces, identifier->get ()) == m_namespaces.end ())
552551 m_namespaces.push_back (identifier->get ());
553552 idx += 1 ;
554- if (auto *operatorToken = std::get_if<Token::Operator>(&token[idx].value );
555- operatorToken == nullptr || *operatorToken != Token::Operator::ScopeResolution)
553+ if (auto *operatorToken = std::get_if<Token::Operator>(&token[idx].value ); operatorToken == nullptr || *operatorToken != Token::Operator::ScopeResolution)
556554 break ;
557555 idx += 1 ;
558556 identifier = std::get_if<Token::Identifier>(&token[idx].value );
@@ -608,6 +606,7 @@ namespace pl::core {
608606 process ();
609607
610608 appendToNamespaces (m_output);
609+ saveTokens (source, m_result);
611610
612611 // Handle pragmas
613612 for (const auto &[type, datas] : this ->m_pragmas ) {
@@ -616,8 +615,7 @@ namespace pl::core {
616615
617616 if (this ->m_pragmaHandlers .contains (type)) {
618617 if (!this ->m_pragmaHandlers [type](*m_runtime, value))
619- errorAt (Location { m_source, line, 1 , value.length () },
620- " Value '{}' cannot be used with the '{}' pragma directive." , value, type);
618+ errorAt (Location { m_source, line, 1 , value.length () }, " Value '{}' cannot be used with the '{}' pragma directive." , value, type);
621619 }
622620 }
623621 }
@@ -626,6 +624,12 @@ namespace pl::core {
626624 return { m_output, collectErrors () };
627625 }
628626
627+ void Preprocessor::saveTokens (api::Source *source, const std::vector<Token> &tokens) {
628+ if (!source->mainSource && !m_parsedImports.contains (source->source )) {
629+ m_parsedImports[source->source ] = tokens;
630+ }
631+ }
632+
629633 bool Preprocessor::eof () {
630634 return m_token == m_result.end ();
631635 }
0 commit comments