-
Notifications
You must be signed in to change notification settings - Fork 36
Attempt to process cell without semicolon #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||||||||||||
/************************************************************************************ | ||||||||||||||||
* Copyright (c) 2016, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht * | ||||||||||||||||
* Copyright (c) 2016, QuantStack * | ||||||||||||||||
* * | ||||||||||||||||
* Distributed under the terms of the BSD 3-Clause License. * | ||||||||||||||||
* * | ||||||||||||||||
* The full license is in the file LICENSE, distributed with this software. * | ||||||||||||||||
************************************************************************************/ | ||||||||||||||||
|
||||||||||||||||
#ifndef XCPP_MIME_INTERNAL_HPP | ||||||||||||||||
#define XCPP_MIME_INTERNAL_HPP | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: header guard does not follow preferred style [llvm-header-guard]
Suggested change
|
||||||||||||||||
|
||||||||||||||||
#include <cstddef> | ||||||||||||||||
#include <locale> | ||||||||||||||||
#include <string> | ||||||||||||||||
|
||||||||||||||||
#include "clang/Interpreter/CppInterOp.h" // from CppInterOp package | ||||||||||||||||
|
||||||||||||||||
#include <nlohmann/json.hpp> | ||||||||||||||||
|
||||||||||||||||
namespace nl = nlohmann; | ||||||||||||||||
|
||||||||||||||||
namespace xcpp | ||||||||||||||||
{ | ||||||||||||||||
inline nl::json mime_repr(intptr_t V) | ||||||||||||||||
{ | ||||||||||||||||
// Return a JSON mime bundle representing the specified value. | ||||||||||||||||
void* value_ptr = reinterpret_cast<void*>(V); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast] void* value_ptr = reinterpret_cast<void*>(V);
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr] void* value_ptr = reinterpret_cast<void*>(V);
^ |
||||||||||||||||
|
||||||||||||||||
// Include "xcpp/xmime.hpp" only on the first time a variable is displayed. | ||||||||||||||||
static bool xmime_included = false; | ||||||||||||||||
|
||||||||||||||||
if (!xmime_included) | ||||||||||||||||
{ | ||||||||||||||||
Cpp::Declare("#include \"xcpp/xmime.hpp\""); | ||||||||||||||||
xmime_included = true; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
intptr_t mimeReprV; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'mimeReprV' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||||||||||||
bool hadError = false; | ||||||||||||||||
{ | ||||||||||||||||
std::ostringstream code; | ||||||||||||||||
code << "using xcpp::mime_bundle_repr;"; | ||||||||||||||||
code << "mime_bundle_repr("; | ||||||||||||||||
// code << "*(" << getTypeAsString(V); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented out. |
||||||||||||||||
code << &value_ptr; | ||||||||||||||||
code << "));"; | ||||||||||||||||
|
||||||||||||||||
std::string codeString = code.str(); | ||||||||||||||||
|
||||||||||||||||
mimeReprV = Cpp::Evaluate(codeString.c_str(), &hadError); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: Value stored to 'mimeReprV' is never read [clang-analyzer-deadcode.DeadStores] mimeReprV = Cpp::Evaluate(codeString.c_str(), &hadError);
^ Additional contextsrc/xmime_internal.hpp:50: Value stored to 'mimeReprV' is never read mimeReprV = Cpp::Evaluate(codeString.c_str(), &hadError);
^ |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
void* mimeReprV_ptr = reinterpret_cast<void*>(V); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast] void* mimeReprV_ptr = reinterpret_cast<void*>(V);
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr] void* mimeReprV_ptr = reinterpret_cast<void*>(V);
^ |
||||||||||||||||
|
||||||||||||||||
if (!hadError && mimeReprV_ptr) | ||||||||||||||||
{ | ||||||||||||||||
return *(nl::json*) mimeReprV_ptr; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] return *(nl::json*) mimeReprV_ptr;
^ |
||||||||||||||||
} | ||||||||||||||||
else | ||||||||||||||||
{ | ||||||||||||||||
return nl::json::object(); | ||||||||||||||||
} | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use 'else' after 'return' [llvm-else-after-return]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use 'else' after 'return' [llvm-else-after-return]
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
anutosh491 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
||||||||||||||||
#endif |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,4 +54,80 @@ namespace xcpp | |||||
|
||||||
return result; | ||||||
} | ||||||
|
||||||
std::vector<std::string> get_lines(const std::string& input) | ||||||
{ | ||||||
std::vector<std::string> lines; | ||||||
std::regex re("\\n"); | ||||||
|
||||||
std::copy( | ||||||
std::sregex_token_iterator(input.begin(), input.end(), re, -1), | ||||||
std::sregex_token_iterator(), | ||||||
std::back_inserter(lines) | ||||||
); | ||||||
return lines; | ||||||
} | ||||||
|
||||||
std::vector<std::string> split_from_includes(const std::string& input) | ||||||
{ | ||||||
// this function split the input into part where we have only #include. | ||||||
|
||||||
// split input into lines | ||||||
std::vector<std::string> lines = get_lines(input); | ||||||
|
||||||
// check if each line contains #include and concatenate the result in the good part of the result | ||||||
std::regex incl_re("\\#include.*"); | ||||||
std::regex magic_re("^\\%\\w+"); | ||||||
std::vector<std::string> result; | ||||||
result.push_back(""); | ||||||
anutosh491 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
std::size_t current = 0; // 0 include, 1 other | ||||||
std::size_t rindex = 0; // current index of result vector | ||||||
for (std::size_t i = 0; i < lines.size(); ++i) | ||||||
{ | ||||||
if (!lines[i].empty()) | ||||||
{ | ||||||
if (std::regex_search(lines[i], magic_re)) | ||||||
{ | ||||||
result.push_back(lines[i] + "\n"); | ||||||
result.push_back(""); | ||||||
anutosh491 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
rindex += 2; | ||||||
} | ||||||
else | ||||||
{ | ||||||
if (std::regex_match(lines[i], incl_re)) | ||||||
{ | ||||||
// if we have #include in this line | ||||||
// but the current item of result vector contains | ||||||
// other things | ||||||
if (current != 0) | ||||||
{ | ||||||
current = 0; | ||||||
result.push_back(""); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: use emplace_back instead of push_back [modernize-use-emplace]
Suggested change
|
||||||
rindex++; | ||||||
} | ||||||
} | ||||||
else | ||||||
{ | ||||||
// if we don't have #include in this line | ||||||
// but the current item of result vector contains | ||||||
// the include parts | ||||||
if (current != 1) | ||||||
{ | ||||||
current = 1; | ||||||
result.push_back(""); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: use emplace_back instead of push_back [modernize-use-emplace]
Suggested change
|
||||||
rindex++; | ||||||
} | ||||||
} | ||||||
// if we have multiple lines, we add a semicolon at the end of the lines that not contain | ||||||
// #include keyword (except for the last line) | ||||||
result[rindex] += lines[i]; | ||||||
if (i != lines.size() - 1) | ||||||
{ | ||||||
result[rindex] += "\n"; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
return result; | ||||||
} | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.