C++ : meta-data information in source code. To see through AST - c++

After parsing, I want to get a meta-data of the source code's field, or method.
The purpose of this is to collect info of the source code after parsing.
In java, I used annotation.
After parsing, I find user-defined annotation on class, field, or method.
Under code is example.
#BizObject //By this annotation I could understand this class is related with bissness.
public class biz ... {
#DI //this field needs Dependency Injection.
public Logger logger;
}
By parsing, I want to collect user-specified meta-info of the source.
How user write the meta-data on the source code?? like java annotation.
I know in C++ there is no direct attribute for this purpose.
I just wondering how to mark meta-data indirectly using other things.

Self response.
I solved this problem by using attribute specifier.
It is similar to Java's annotation.
http://en.cppreference.com/w/cpp/language/attributes
http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/
https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
By using attribute specifier and CDT parser, I could get meta data related syntax's node.
CDT parser support GNU.

Related

How to map ember object hierarchy to Haxe

I have just started to create Haxe externs (strictly typed class definitions)
based on the yuidoc output from the ember source.
Now I need help to understand how to implement the kind of mixing architecture special to Ember.
For example the Ember.Object extends the Ember.CoreObject - however I wasn't able to locate any constructor inside the latter - is there any direct call to new Something() in Ember at all?
Then Ember.Object uses Ember.Observable which in turn imports cacheFor from the ember-metal / lib / computed.js module - is this relation reflected inside the data.json output of yuidoc or will I need to parse the sources directly in order to collect all methods into my class definitions?
is there any direct call to new Something() in Ember at all?
For the most part, no. You're supposed to call Class.create() not new Class().
is this relation reflected inside the data.json output of yuidoc or will I need to parse the sources directly in order to collect all methods into my class definitions?
The data.json file should contain most of the documentation written. The problem you'll experience is that not everything is documented (mostly private API).
Where can I find the Container Class API docs?
In the source code.

How can I print a ctemplate::TemplateDictionary in JSON form?

Using the Google CTemplate library, I have built a TemplateDictionary of params. Such a dictionary is a map of string keys to a variety of value types.
Typically, one passes CTemplate a template file wherein placeholders for each key in the dictionary are found and substituted.
In one case, though, I wish to emit the entire dictionary in JSON form, and the template language syntax doesn't appear to provide reflection such that I can write placeholders to loop over an unknown number of unknown keys in any arbitrary dictionary.
Did I miss some functionality?
If so, how can I add it?
Will I have to patch the CTemplate code? Much of what I seem to need for the job appears to be marked private i.e. for internal use only...
I've ended up hacking the CTemplate source in template_dictionary.h and template_dictionary.cc, cloning class class TemplateDictionary::DictionaryPrinter to produce a new class class TemplateDictionary::DictionaryJsonPrinter, adapting its member functions to emit JSON syntax.

wsdl objects are repeated when I add webservice reference

when I add webservice reference (not a service reference), I am getting same element with renamed added suffix as 1 as shown in the image. this causes an error when I try to debug. Inner exception says
Message=Types 'service.AddressType1' and 'service.AddressType' both use the XML type name, 'AddressType', from namespace 'xxx'. Use XML attributes to specify a unique XML name and/or namespace for the type.
I understand the error and I already saw some different threads here those tell me that I should specify different namespace but I don't have AddressType1 defined anywhere in my proxy classes. I have only AddressType. where from do I get that AddressType1 or others?
Anyone else got that error? thanks for your help.
Have you looked at this answer? Inheriting Existing .Net Class Serialization Error
This answer also discusses issues with hierarchical namespacing (seems you may be doing that), so that may be your main issue: Classes in different sub-namespaces all appear at top level in WSDL
It appears that you may need to specify the XmlTypeAttribute. Can you provide your code sample for review?
I was having inherited proxy classes which I generated using xsd2code tool. Problem was that this tool generated namespaces correctly for the parent xsd classes but when I check the class in the child which is shared/common by other parent classes, It appears that namespace field was empty as below. Therefore my service reference had same properties/classes more than one time with 1 suffix as shown in the question. I have just added same namespace for those child/inherited classes, It worked fine and no repeated properties. I hope that this helps to someone else having similar problem.
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=True), _

Unable to return POCO object with navigation property from a web service?

I'm using POCO to auto generate my entities from DAL project to Entities project. I currently have no need in creating view classes manually.
However I have one problem - When I try to return a poco object that has navigation properties from a [WebMethod] I get the following error:
Cannot serialize member Entities.City.Customers of type System.Collections.Generic.ICollection1[[Entities.Customer, Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.
I tried writing context.ContextOptions.LazyLoadingEnabled = false; and
context.ContextOptions.ProxyCreationEnabled = false; to no avail.
if I add [System.Xml.Serialization.XmlIgnore] before the properties, I get no error, but then I lose those properties?
The message is clear: serialization fails because your Entities.City.Customers member is declared as an interface (ICollection).
The interface does not say anything about the implementing type, it only defines the contract that the implementation should follow. As such, the serializer does not know how to represent the implementation in a serialized format.
You might think that it's not that hard to reflect the type and serialize based on the information you get from introspection, but the problem will be when you try to deserialize from this representation. The same representation could possibly correspond to all implementation types, in which case what should the serializer choose as the concrete type?
There are a few steps to work around this limitation, as you can find in this post: XML serialization of interface property. In your particular case, the simplest way would be to make the Entities.City.Customers member of a concrete type like List<Customer> instead of ICollection<Customer>.

Is it possible to exclude Entity Framework Autogenerated Code from Code Coverage Statistics?

I have seen the [DebuggerNonUserCode] and [ExcludeFromCodeCoverage] attributes in resources and other SO questions about exlcuding code from coverage statistics, and wanted to know if it was possible to automatically add this attribute to the classes in the code generated by the Entity Framework using .NET 4.0.
Also would it need to be class level or could it be on the diagram.Designer.cs level, needing one attribute for all code generated by that diagram?
Since partial classes (which Entity Framework creates) merge attributes, extended functionality in other partial classes are also excluded if the attribute is class level in the template, it will have to be applied at the method level.
The best way that I've found to do this is using T4 (as recommended in #Craig Stuntz's answer) to:
include: using System.Diagnostics.CodeAnalysis; at the top of the file
Then apply [ExcludeFromCodeCoverage] to getters, setters and Factory methods by searching for:
#>get
#>set
Template_FactoryMethodComment
and placing them in the appropriate place.
This was made a lot easier using Tangible's T4 editor Extension for VS.
This is my first attempt and it seems to work, "your milage may vary", so complete a test run to make sure everything's working as necessary.