I'm trying to solve this bug report, where the documentation for a C++ library has some signature with ellipsis (... or ??) for places where the developers don't want to dive into the specifics (C++ metaprogramming is way too verbose); for example Tk_expr Ltuple<T1, ..., Tn>_expr::get<k>() const or Fmpz_expr::ternary operation(??, ??) const should just work.
If the documentation doesn't declare the language domain is C++, sphinx complains. If it does, sphinx complains it's invalid C++... I'm not sure if the information about Gentoo is important there.
Trivial fix : put complete signatures. Unreadable!
How can one use ellipsis?
Sphinx uses Pygments for syntax highlighting, and that's the source of the messages. You must have valid syntax for the language for highlighting to occur. You can either change the language to text which will remove desirable highlighting, or you can remove or comment out the elided output.
Related
I'm working on improving syntax highlighting for Ada in gtksourceview (currently, it is very outdated and very incomplete). An issue I'm having, is Ada is very positional, so matching many constructs requires matching those positions. I was able to do this in nano fairly easily.
So, let's consider a type declaration such as:
type Trit is range 0..2;
Keywords like "type", "is" and "range" are recognized (and were originally). However, type names were treated as keywords (a bad design decision, as Ada regularly defines new types, even for simple types like integers). What the use gets, is the types in Standard being colored, and all other types looking like normal text, defeating the purpose of highlighting. In some languages this might be a notable problem. However, the majority of type names occur after two regex patterns:
type\s+(\w|\.|_)+
:\s+(\w|\.|_)+
It might just be a matter of implementation (nano and gtksourceview seem to use different regex implementations). I thought the problem was recognizing spaces. As it turns out, putting the type context above the keyword context results in types now being highlighted, but the "type" keyword, or ":" operator are then not highlighted properly (they are highlighted as "type"). I was able to override this in nano, resulting in correct highlighting, but cannot seem to find out how gtksourceview does this.
Here you can see the old gtksourceview definition in action, which doesn't work for a file with many custom types. My nano definition in action sidebyside for comparison; matching by position is definately possible and works.
Here is what happens when I put the type context below the keyword context.
Here is what happens when I put the type context above the keyword context.
In both cases the context is the same, just a simple pattern to get started.
<context id="type" style-ref="type">
<match>(type)\s+\w+</match>
</context>
You may want to consider generating the parser from the formal description of the syntax of Ada in annex P of the Language Reference Manual.
Unfortunately this doesn't answer your question of how to formulate the syntax for a GtkSourceView.
I am using Boost 1.46 with Turtle lib 1.2.4 and compiler from Visual Studio Express 2013. I have following class to MOCK:
struct IPredicate
{
virtual ~IPredicate() {}
virtual bool operator()(float value) = 0;
};
When I mock operator() with MOCK_NON_CONST_METHOD:
MOCK_BASE_CLASS(MockPredicate, IPredicate)
{
MOCK_NON_CONST_METHOD(operator(), 1, bool(float), id)
};
I got bunch of compiler errors, e.g. syntax error 'operator ' and so on. But when I mock it with MOCK_NON_CONST_METHOD_EXT:
MOCK_BASE_CLASS(MockPredicate, IPredicate)
{
MOCK_NON_CONST_METHOD_EXT(operator(), 1, bool(float), id)
};
everything is ok and works perfectly! According to http://turtle.sourceforge.net/turtle/reference.html MOCKS with EXT suffix are for "compilers without support for variadic macros", but the one I am using has support (checked it with these examples: http://msdn.microsoft.com/en-us/library/ms177415.aspx ). The rest of the documentation isn't really clear about this case.
Is anyone able to explain me what's the case here? Why I have the errors when I don't use EXT suffixed MOCK version?
The stickler’s answer would be that generally there are no guarantees with respect to variadic macros, as variadic macros are non-standard in C++03 (but are standard in C++11). So if you have a method which avoids variadic macros you should definitely use it instead the one with the variadic macros.
Practically though it is very likely that the turtle library hasn’t been extensively tested with msc and is simply relying on one of the non-standard gcc extensions for the macros. The extensions are discussed on the Variadic Macros http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html page. Specifically, for the turtle library to be portable for all C99 conformant compilers only __VA_ARGS__ could be used.
With macros, when you are after the root case - use the /P switch for msc (Preprocess to a File) to generate an .i file with the pre-processors directives expanded, where you can check what's it unhappy about.
Update. As I finished spanning this long story, I decided to quickly download the turtle and check how the macro is defined. And as I did, I discovered that this is simply a sad case of unmaintained documentation. Running grep on the library includes I couldn't find MOCK_NON_CONST_METHOD defined at all. That's why you are getting syntax errors. Another reason to avoid macros - clarity and sanity of C++ error messages.
(I'm the author of turtle)
What happened with 1.2.4 is that for a reason I didn't really investigate the code provided is actually 1.2.1 along with the 1.2.4 documentation.
As nobody complained by opening a ticket directly on sourceforge I didn't notice until quite some time had passed (all my personal and company projects using turtle are continuously integrated with the latest source code).
Anyway, I just tested your code and it compiles with MSVC 2013, turtle 1.2.6 and boost 1.55. If you haven't already done so by the time, you should consider upgrading.
I am aware of this script: http://www.vim.org/scripts/script.php?script_id=3797. It has been suggested a few times, and other questions regarding C++11 syntax for Vim have been shut down due to duplicating this question: Is there a C++11 syntax file for vim?.
Unfortunately, the suggested script results in scoping constructs (e.g. "namespace::member()") not being highlighted anymore, and functions and class names are no longer highlighted.
Does anyone have a better C++11 plugin for Vim available now? Ideally, all the features of the regular C++ plugin being retained, new keywords/reserved words marked (e.g. nullptr), lambda expressions/universal initialization syntax not flagged as errors. etc. etc.
Have you tried the following? I use this one and like it
http://www.vim.org/scripts/script.php?script_id=4617
I have seen the following definition throughout legacy code:
std::vector<boost::shared_ptr<ClassNameAAA>> vecClass;
I am able to compile it with VS2008 w/o problems.
Question> My understanding is that the following line should be used instead:
std::vector<boost::shared_ptr<ClassNameAAA> > vecClass;
^ Add a space here
Am i correct on this? If any, why VS2008 allows this?
Thank you
This is one of those several MS extensions.
Am i correct on this?
Yes your understanding is correct. >> would be parsed as right shift operator.
However C++11 supports right-angle brackets.
MSVC++ 2008 is able to parse this because of a language extension.
Many compilers have extensions for features that eventually become part of the language. Being able to parse nested template declarations without the space is now required in the new C++11 standard.
The task
I am trying to work out how best to add C++0x's override identifier to all existing methods that are already overrides in a large body of C++ code, without doing it manually.
(We have many, many hundreds of thousands of lines of code, and doing it manually would be a complete non-starter.)
Current idea
Our coding standards say that we should add the virtual keyword against all implicitly virtual methods in derived classes, even though strictly unnecessary (to aid comprehension).
So if I were to script the addition myself, I'd write a script that read all our headers, found all functions beginning with virtual, and insert override before the following semi-colon. Then compile it on a compiler that supports override, and fix all the errors in base classes.
But I'd really much rather not use this home-grown way, as:
it's obviously going to be tedious and error-prone.
not everyone has remembered, every time, to add the virtual keyword, so this method would miss out some existing overrides
Is there an existing tool?
So, is there already a tool that parses C++ code, detects existing methods that overrides, and appends override to their declarations?
(I am aware of static analysis tools such as PC-lint that warn about functions that look like they should be overrides. What I'm after is something that would actually munge our code, so that future errors in overrides will be detected at compiler-time, rather than later on in static analysis)
(In case anyone is tempted to point out that C++03 doesn't support 'override'... In practice, I'd be adding a macro, rather than the actual "override" identifier, to use our code on older compilers that don't support this feature. So after the identifier was added, I'd run a separate script to replace it with whatever macro we're going to use...)
Thanks in advance...
There is a tool under development by the LLVM project called "cpp11-migrate" which currently has the following features:
convert loops to range-based for loops
convert null pointer constants (like NULL or 0) to C++11 nullptr
replace the type specifier in variable declarations with the auto type specifier
add the override specifier to applicable member functions
This tool is documented here and should be released as part of clang 3.3.
However, you can download the source and build it yourself today.
Edit
Some more info:
Status of the C++11 Migrator - a blog post, dated 2013-04-15
cpp11-migrate User’s Manual
Edit 2: 2013-09-07
"cpp11-migrate" has been renamed to "clang-modernize". For windows users, it is now included in the new LLVM Snapshot Builds.
Edit 3: 2020-10-07
"clang-modernize" has bee renamed to "Clang-Tidy".
Our DMS Software Reengineering Toolkit with its C++11-capable C++ Front End can do this.
DMS is a general purpose program transformation system for arbitrary programming languages; the C++ front end allows it to process C++. DMS parses, builds ASTs and symbol tables that are accurate (this is hard to do for C++), provides support for querying properties of the AST nodes and trees, allows procedural and source-to-source transformations on the tree. After all changes are made, the modified tree can be regenerated with comments retained.
Your problem requires that you find derived virtual methods and change them. A DMS source-to-source transformation rule to do that would look something like:
source domain Cpp. -- tells DMS the following rules are for C++
rule insert_virtual_keyword (n:identifier, a: arguments, s: statements):
method_declaration -> method_declaration " =
" void \n(\a) { \s } " -> " virtual void \n(\a) { \s }"
if is_implicitly_virtual(n).
Such rules match against the syntax trees, so they can't mismatch to a comment, string, or whatever. The funny quotes are not C++ string quotes; they are meta-quotes to allow the rule language to know that what is inside them has to be treated as target language ("Cpp") syntax. The backslashes are escapes from the target language text, allowing matches to arbitrary structures e.g., \a indicates a need for an "a", which is defined to be the syntactic category "arguments".
You'd need more rules to handle cases where the function returns a non-void result, etc. but you shouldn't need a lot of them.
The fun part is implementing the predicate (returning TRUE or FALSE) controlling application of the transformation: is_implicitly_virtual. This predicate takes (an abstract syntax tree for) the method name n.
This predicate would consult the full C++ symbol table to determine what n really is. We already know it is a method from just its syntactic setting, but we want to know in what class context.
The symbol table provides the linkage between the method and class, and the symbol table information for the class tells us what the class inherits from, and for those classes, which methods they contain and how they are declared, eventually leading to the discovery (or not) that the parent class method is virtual. The code to do this has to be implemented as procedural code going against the C++ symbol table API. However, all the hard work is done; the symbol table is correct and contains references to all the other data needed. (If you don't have this information, you can't possibly decide algorithmically, and any code changes will likely be erroneous).
DMS has been used to carry out massive changes on C++ code in the past using program transformations.(Check the Papers page at the web site for C++ rearchitecting topics).
(I'm not a C++ expert, merely the DMS architect, so if I have minor detail wrong, please forgive.)
I did something like this a few months ago with about 3 MB worth of code and while you say that "doing it manually would be a complete non-starter," I think it is the only way. The reason is that you should be applying the override keyword to the prototypes that are intended to override base class methods. Any tool that adds it will put it on the prototypes that actually override base class methods. The compiler already knows which methods those are so adding the keyword doesn't change anything. (Please note that I am not terribly familiar with the new standard and I am assuming the override keyword is optional. Visual Studio has supported override since at least VS2005.)
I used a search for "virtual" in the header files to find most of them and I still occasionally find another prototype that is missing the override keyword.
I found two bugs by going through that.
Eclipse CDT has a working C++ parser and semantic utilities. The latest version IIRC also has markers for overriding methods.
It wouldn't require much code to write a plug-in which would base on that and rewrite the code to contain the override tags where appropriate.
one option is to
Enable suggest-override compiler warning And then write a script
which can insert override keyword to location pointed by the emitted warnings