i implemented a custom attribute in clang as described in the official manual:
http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute
So i added the following Code to Attr.td:
def MyAttr: InheritableAttr {
let Spellings = [GNU<"my_attr">, CXX11<"me", "my_attr">, GCC<"my_attr">, Declspec<"my_attr">];
let Subjects = SubjectList<[Var, Function, CXXRecord]>;
let Documentation = [MyAttrDocs];
}
and the documentation to AttrDocs.td. After rebuilding clang, it obviously knows the attribute because i don't get an unknown attribute warning when using it. I can even access the new attribute class with libtooling, but the attribute doesn't show up in the AST, even if i add the line let ASTNode = 1 to the attribute definition.
Is there something else i need to consider or what could be the problem?
Unfortunately this was my fault, the missing step is described in the manual in section "Boilerplate": i just had to implement the semantic processing of the attribute in SemaDeclAttr.cpp by adding a new case:
case AttributeList::AT_MyAttr:
handleSimpleAttribute<MyAttrAttr>(S, D, Attr);
break;
So it works fine now.
Related
What does the extension function SemanticModel.TryGetSpeculativeSemanticModel return? What is it good for?
I could not find any meaningful documentation on the subject.
The documentation for TryGetSpeculativeSemanticModel says:
Get a SemanticModel object that is associated with X that did not appear in this source code. This can be used to get detailed semantic information about sub-parts of X that did not appear in source code.
The analyzer code for the StyleCop SX1101 diagnostic offers a great example of this API's usage. SX1101 tells you that it's safe to remove a this. qualifier from your code.
Lets step through a slightly simplified version of the analyzer code:
var memberAccessExpression = (MemberAccessExpressionSyntax)ctx.Node.Parent;
var originalSymbolInfo = context.SemanticModel.GetSymbolInfo(
memberAccessExpression,
context.CancellationToken);
var statement = context.Node.FirstAncestorOrSelf<StatementSyntax>();
var annotation = new SyntaxAnnotation();
var speculationRoot = statement.ReplaceNode(
memberAccessExpression,
memberAccessExpression.Name.WithAdditionalAnnotations(annotation));
context.Node is a ThisExpressionSyntax. speculationRoot is an expression where we replaced this.SomeMember with SomeMember. The annotation is used for quick lookup later.
Now that we have generated a modified version of the code, we want to check if it would a) still compile, and b) still refer to the same thing. Since the sources in Roslyn are immutable, we'd need to compile the entire project again (which would be doable, but more expensive) to get a new SemanticModel for the changed code.
Here is where TryGetSpeculativeSemanticModel steps in:
if(!context.SemanticModel.TryGetSpeculativeSemanticModel(
statement.SpanStart,
speculationRoot,
out var speculativeModel)) return;
var mappedNode = speculationRoot.GetAnnotatedNodes(annotation).Single();
var newSymbolInfo = speculativeModel.GetSymbolInfo(mappedNode, context.CancellationToken);
So now if we manage to get a speculative semantic model, it means SomeMember was valid at that same position in code as this.SomeMember. We've used the annotation to quickly look up the SomeMember syntax node and then get it's semantic info from the speculativeModel.
All that's left to do now is to check whether the modified statement means the same thing as the original one.
if (!Equals(originalSymbolInfo.Symbol, newSymbolInfo.Symbol)) return;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation()));
İn this official tutorial I got the error in title. What should be the reason?
Ptr<Tracker> tracker = Tracker::create( "KCF" );
Here the part of tracking.hpp:
#endcode
of course, you can also add any additional methods of your choice. It should be pointed out,
however, that it is not expected to have a constructor declared, as creation should be done via
the corresponding createTracker() method.
In src/tracker.cpp file add BOILERPLATE_CODE(name,classname) line to the body of
Tracker::create() method you will find there, like :
#code
Ptr<Tracker> Tracker::create( const String& trackerType )
{
BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
BOILERPLATE_CODE("MIL",TrackerMIL);
return Ptr<Tracker>();
}
#endcode
- Finally, you should implement the function with signature :
#code
Ptr<classname> classname::createTracker(const classname::Params ¶meters){
...
}
#endcode
I am using 3.2.0 release.
The code you pasted from tracking.hpp isn't actual code, it's just sample code that's part of the documentation. The only relevant code in the tracking header file is:
#include <opencv2/tracking/tracker.hpp>
#include <opencv2/tracking/tldDataset.hpp>
Thus, to see what you're actually importing you need to look at the tracking/tracker.hpp file (here).
If you do that, you'll see that there's no static create method in the Tracker class declaration. The method was actually removed in this commit. So, basically, you're right: the tutorial wasn't updated after the method was removed. You should report your issue to the opencv team.
That being said, to make the tutorial work you'll probably need to replace the line that's not compiling with:
Ptr<TrackerKCF> tracker = TrackerKCF::create();
That should do the trick.
After the Swift 3 update, I'm having some trouble getting my app to compile. Most of the errors are pretty simple to fix, but I'm running into a few in particular with AWS. Is there some sort of updated AWS SDK for Swift 3? I've tried to look it up, but haven't found one. In any case, the two main errors I'm having trouble resolving are as follows:
"Type 'IdentityProviderManager' does not conform to protocol AWSIdentityProviderManager." This is for a class I created following a tutorial to set up logins through AWS Cognito. The code is:
class IdentityProviderManager: NSObject, AWSIdentityProviderManager{
var tokens : [NSString : NSString]?
init(tokens: [NSString : NSString]) {
self.tokens = tokens
}
#objc func logins() -> AWSTask<AnyObject> {
return AWSTask(result: tokens as AnyObject)
}
}
In the AWS documentation for AWSIdentityProviderManager, it says that the only required function is logins, which I have. Is there a simple way to resolve this that I'm missing?
The other error is in my LoginViewController class: "Type 'LoginViewController' does not conform to protocol 'AWSCognitoIdentityPasswordAuthentication'." Here the issue seems a bit more clear, since the documentation says that getPasswordAuthenticationDetails() is a required method and XCode seems to have changed this method to getDetails() when updating to Swift 3, unless I'm mistaken and it wasn't there to begin with or something. In any case, autocomplete doesn't give me the original method and I can't seem to make the class conform to the protocol.
Apologies if the answer is already in documentation somewhere, but as far as I can tell it seems like the AWS SDK (at least the version that I have) is somehow incompatible with Swift 3. Is there something I can do to resolve these errors?
Nevermind, it turned out XCode just wasn't showing me the option to make the changes I needed. The automatic fix implemented slightly different versions of the required functions and everything ended up working.
I am facing a weird error within my codebase currently. You can see the full ZF2s project code on my github right here. <- there's a link
I'm having a Module set up with two Entities (X and Y). Entity_X contains a reference to Entity_Y via (targetEntity="Entity_Y"). The Error persist with the FQCN or just the CN itself.
Entity_X:
id int PK,
id_Y int FK,
text varchar
Entity_Y:
id int PK,
text varchar
When loading Entity_Y first and then Entity_X everything is working fine. This remains true for both StandardAutoloader and ClassMapAutoloader. However: when loading Entity_X first with ClassMapAutoloader present, i will be seeing the following error:
Fatal error: Cannot redeclare class Kennzahlen\Entity\Referenzwert (Entity_Y)
in \module\Kennzahlen\src\Kennzahlen\Entity\Referenzwert.php
on line 13
Loading Entity_X first with StandardAutoloader works without any problems, too.
Update
The Problem appears to be within ZF2s ClassMapAutoloader (or Autoloading-Mechanism in General). My Module used the ClassMapAutoloader and using this i've gotten the above mentioned error. When removing the ClassMapAutoloader and simply using the StandardAutoloader, the error vanished into thin air. Thanks to #ocramius and all others i've botheres with this :)
I'm writing a failing test case to try and solve this in doctrine/common. The problem seems to be that silent autoloaders (as explained by #Xerkus) are not compatible with doctrine/common itself. To solve that, use a StandardAutoloader from ZF2 (or from composer) instead of using the ClassMapAutoloader. This will solve the issue until a patch is ready.
Update: patch is being suggested at doctrine/common#216
i have no knowledge of doctrine, but i browsed through source and i think i found issue:
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/ClassLoader.php#L224
here, this code expects that autoloader will return value evaluated to true, but that is not requirement of spl autoload mechanism, therefore autoloader can return NULL,
To check if i am correct, in in your project in doctrine replace line 224 in Doctrine/Common/ClassLoader.php
} else if ($loader[0]->{$loader[1]}($className)) {
with
} else if ($loader[0]->{$loader[1]}($className) && class_exists($className, false)) {
Ans see if issue is fixed, if i am correct - then report bug to doctrine project
I'm developing an Ecore model with some invariants defined in OCL, using the OCLinEcore editor. In my model, some elements have references to EClassifier; in some OCL constraints, I need to check if the EClassifier referred to is an EDataType or an EClass. Here is, in OCLinEcore, a model similar to the one I have:
import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';
package Foo : foo = 'some_namespace'
{
class EndPoint
{
attribute name : String[1];
property type : ecore::EClassifier[1];
}
class Coupling
{
invariant Compatibility:
(destination.type.oclIsKindOf(ecore::EDataType) and source.type = destination.type) or
let destinationClass : ecore::EClass = destination.type.oclAsType(ecore::EClass) in
destinationClass.isSuperTypeOf(source.type.oclAsType(ecore::EClass));
property source : EndPoint[1];
property destination : EndPoint[1];
}
}
However, when I try to validate a dynamic instance of my model, an exception occur with the following message:
An exception occured while delegating evaluation of the
'Compatibility' constraint on 'Coupling': Unknow type ([ecore,
EDataType])
When I try the expression in the OCL interactive console, I obtain the correct result. Am I doing something wrong when defining my invariant? How can I write an invariant that uses Ecore types?
Edward Willink gave me an explanation and a workaround on the OCL forum:
Naked OCL does not support the binding of ecore to something useful,
so the oclAsType(ecore::EClass) has an unresolved reference since each
ecxpression is an independent snippet in the ECore file.
The Juno release therefore adds an extension whereby a package
qualifier may be a URI, so that if you saw the above serialized it
might be
oclAsType(_'http://www.eclipse.org/emf/2002/Ecore'::ecore::EClass).
The Juno release also adds flexibility as to whether you use the new
Pivot-binding with this extended functionality. In the
Window->Preferences->OCL page make sure that the selected executor for
the default delegate is
http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot.