Where in the OpenJDK javac source should I start looking for a place to get java class metadata? - lexical-analysis

I am planning to start a project part of which requires a lexical analyzer for java source code. Simply, I need a class list with metadata. Inheritance hierarchy is enough for now, but eventually I'd like to be able to get more information on the class (such as containing class, and fields/methods with metadata).
I'd like to use OpenJDK to help with this.
Can anyone direct me where in the javac (or other) code I could best begin understanding how openjdk works so that I can fork the javac code and write something to get this information?

There's Java Compiler api for that: overview and javadoc. The corresponding OpenJDK source code (for JDK 6) is here.

Related

How to identify language using ML.NET?

Is it possible to identify language using ML.NET like fastText does it, but it is in python:
https://fasttext.cc/docs/en/language-identification.html
But I'd like to do it in SQLCLR function and in NET Core application.
SQL Server should be .NET Framework only, so I don't see a single .NET Core library being an option.
Also, while the ReadMe for the main ML.NET repository does state:
ML.NET also works on the .NET Framework 4.6.1 or later, but 4.7.2 or later is recommended.
Also, a white-paper on ML.NET stated that a portion of it is written in C++, and that could mean that one or more DLLs are mixed-mode (not pure MSIL) in which case that would not load into SQL Server under any circumstance (i.e. not even marked as UNSAFE). But you are certainly welcome to try loading the ML.NET libraries into SQL Server to see if it works. But even if it does, you likely have a lot of work ahead of you in terms of re-creating what they did with fastText.
You might be able to make use of this C# wrapper for fastText:
https://github.com/rafael-aero/fastText/tree/master/vs2015
You will still need the main fastText library, fastText.dll, as the wrapper code will call it. The wrapper code will need to be loaded as UNSAFE due to the calls to unmanaged code.
If you do try this and it does work, please let us know.

Best way to expose custom location of shared library in Linux

I am currently looking for ways to expose the location of a shared library on Linux such that it can be picked up easily by any program installed separately. I want to make this location configurable so it can point to different possible installations of the same library. Examples of similar cases I can think of would be Qt5 and Java.
To make a long story short, I am developing FreeRDS, a FreeRDP-based Remote Desktop Services stack. Server-side RDS-aware applications link to libwinpr-wtsapi, a stub library that exposes the Microsoft Windows Terminal Services API interface, but does not implement it. This enables applications to link to libwinpr-wtsapi without having to link directly to a specific RDS implementation. On the first call to any of the WTSAPI functions, the real implementation is loaded dynamically by libwinpr-wtsapi. However, the location of the dynamic library implementing the WTSAPI (here, FreeRDS) needs to be known.
Right now, I am achieving this by setting an environment variable with the full path to the library:
export WTSAPI_LIBRARY=/opt/freerds/lib/x86_64-linux-gnu/libfreerds-fdsapi.so
However, this is not very practical, as this environment variable would need to be set for every program using the WTSAPI. In this case, I have my installation of FreeRDS in /opt/freerds.
I am thinking I could probably simplify this by using a single environment variable to expose the installation prefix of FreeRDS on the system, with something similar to JAVA_HOME:
export FREERDS_HOME=/opt/freerds
However, I then need to know the proper library subdirectory. It is also important to know that it would be possible in the future to offer both a 32-bit and a 64-bit version of the library offering the FreeRDS WTSAPI. This library basically performs RPC with the FreeRDS session manager, so that would be definitely possible.
Let's say we have FREERDS_HOME properly set, or that FreeRDS is installed in the default installation prefix of the system, which files would be "standard" to offer some additional installation configuration information? Here I'm thinking I could have an equivalent of Qt5's qt.conf that would specific installation subdirectories, like the 64-bit installation subdir, the 32-bit installation subdir, etc. However, I don't know where I should be putting that file. Should it be in <prefix>/etc/freerds/freerds.conf?
Ideas, anyone? Thank you!
some (many? all?) Linux distributions today include environment-modules, which aim is exactly to make available many different versions of the same software by customizing the environment (and eventually, shell aliases/functions) with easy front-end commands.
You can find all the needed information here.
Thanks for the multiple answers, here is the solution I finally opted for that satisfies my needs:
As explained earlier, there could be more than one installation of FreeRDS on the same system, but only one of them running at once. We can also assume FreeRDS is supposed to be running before we can attempt to interact with it. Knowing this, I modified FreeRDS to write a simple configuration file in /var/run/freerds.instance with the install prefix and installation subdirectories. This is very similar to having a .pid file, except we're exposing installation paths.
The freerds.instance file is using the .ini format, which is fairly common in configuration files. All that libwinpr-wtsapi has to do is parse /var/run/freerds.instance to find the installation prefix of the current FreeRDS instance, along with the library subdir, so we can find the correct libfreerds-fdsapi.so.
Here is what a sample freerds.instance file looks like:
[FreeRDS]
prefix="/opt/freerds"
bindir="bin"
sbindir="sbin"
libdir="lib/x86_64-linux-gnu"
datarootdir="share"
localstatedir="var"
sysconfdir="etc"
I prefer this solution because it requires literally no special configuration, setting of environment variables, etc. No matter what, we always find the proper FreeRDS installation wherever it is on the system.
You can add a $ORIGIN rpath to your executable, that makes it load libraries relative to the directory the executable is in. (See "ld: Using -rpath,$ORIGIN inside a shared library (recursive)"). This probably applies to dlopen() too.?
$ gcc ... -Wl,-rpath,'$ORIGIN/../lib/dir' -lsomething
I've also found you can run the dynamic linker directly to get some debug facility:
$ /lib/ld-linux.so.2
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
...
--list list all dependencies and how they are resolved
export LD_LIBRARY_PATH=/yourso.so

Is Extendible program in C possible?

I am looking into making a C program which is divided into a Core and Extensions. These extensions should allow the program to be extended by adding new functions. so far I have found c-pluff a plugin framework which claims to do the same. if anybody has any other ideas or reference I can check out please let me know.
You're not mentioning a platform, and this is outside the support of the language itself.
For POSIX/Unix/Linux, look into dlopen() and friends.
In Windows, use LoadLibrary().
Basically, these will allow you to load code from a platform-specific file (.so and .dll, respectively), look up addresses to named symbols/functions in the loaded file, and access/run them.
I tried to limit myself to the low-level stuff, but if you want to have a wrapper for both of the above, look at glib's module API.
The traditional way on windows is with DLLs. But this kind of obselete. If you want users to actually extend your program (as opposed to your developer team releasing official plugins) you will want to embed a scripting language like Python or Lua, because they are easier to code in.
You can extend your core C/C++ program using some script language, for example - Lua
There are several C/C++ - Lua integration tools (toLua, toLua++, etc.)
Do you need to be able to add these extensions to the running program, or at least after the executable file is created? If you can re-link (or even re-compile) the program after having added an extension, perhaps simple callbacks would be enough?
If you're using Windows you could try using COM. It requires a lot of attention to detail, and is kind of painful to use from C, but it would allow you to build extension points with well-defined interfaces and an object-oriented structure.
In this usage case, extensions label themselves with a 'Component Category' defined by your app, hwich allows the Core to find and load them withough havng to know where their DLLs are. The extensions also implement interfaces that are specified using IDL and are consumed by the core.
This is old tech now, but it does work.

Using GraphViz in a WPF application

I want to use GraphViz in my WPF application without installing Graphviz.
Does AT&T (or somebody else) distribute such a DLL?
Thanks,
Kemal
You can compile the dot tool as DLL from source. That is what I did a while back. I use QuickGraph with GraphViz and render the graph with slightly modified version of the control you can get from here http://www.codeproject.com/KB/WPF/Dot2Wpf.aspx
Apparently ImageMagick can read the graphviz DOT format: http://www.imagemagick.org/script/formats.php
Perhaps you can call ImageMagick from .NET using this wrapper http://imagemagick.codeplex.com/ and get it to read DOT and output as PNG or something? I've never tried, and for all I know ImageMagick might end up spawning the command line program anyway!
(I have used graphviz from ASP classic a long time ago by spawning the graphviz executable with good results BTW.)
Just use the "GraphViz XAML Renderer" # http://www.sixpairs.com/graphviz/graphviz.aspx
Features:
No need to install GraphViz
No need to launch an external process
No need to use files
Thread safety
Regards,
Ciper
Try graphviz library .NET wrapper http://code.google.com/p/graphviznet/.
It accepts the description of a graph in the form of managed objects, runs through the graphviz layout engine and gets back the data.
If you don't want't to install complete graphviz, you can copy only required set of dll's, see readme.txt in demo project, project also contains a WPF control to display graphs.
Licensing
GraphViz is licensed under the Common Public License (see the CPL FAQ)
Also from the GraphViz site:
For more information on the Common
Public License, see the FAQ. If you
have any concerns about the what the
license means, especially if money is
involved, you should contact an
intellectual property lawyer.
Using GraphViz as a DLL
GraphViz is an executable program rather than a DLL - to use it in your app you need to spawn the executable with the correct command line parameters and pick up the resulting output.
Other ways of using GraphViz
There is a COM component available that parses the DOT language and renders it:
WinGraphViz but I've never used it and cannot vouch for how well it works.
Aside: If you are doing graph work in WPF I thoroughly recommend using QuickGraph to actually manage the graph - it will also output to GraphViz compatible text files.
Have a look at this fairly new object-oriented Graphviz wrapper for .NET: https://github.com/Rubjerg/Graphviz.NetWrapper
Since it works by doing foreign function calls to the Graphviz library it ships with, you don't have to install anything.

How to document C code in Eclipse (intellisense/javadoc like tooltips)

Is it possible to document C code in Eclipse (3.4 w/ CDT) in such a way that JavaDoc/Intellisense like documentation is auto generated and displayed?
E.g. On typing a function name followed by a '(' you get the first param with a tooltip explaining the meaning of that parameter?
Thanks.
To my knowledge: No (With CDT5.0.2).
The best you have right now is what they are calling: content assist
alt text http://help.eclipse.org/ganymede/topic/org.eclipse.cdt.doc.user/images/contentAssist_example.png
You can view this project: http://gna.org/projects/eclox
Eclox is a simple doxygen frontend plug-in for eclipse. It aims to provide a slim and sleek integration of the code documentation process into eclipse.
Features Overview
* Graphical edition of doxyfile settings,
* integrated doxygen invokation,
* doxygen outputs logging and
* optional packaged doxygen binaries (for windows and linux).
Registration Date: Monday 02/02/2004 at 09:31 CET
License: GNU General Public License V2 or later
Regards
FYI, I have started to use Doxygen to document my code. This allows documenting in a JavaDoc syntax which I really wanted, and Doxygen then parses the source to form various output formats (html/xml/chm etc..) which is working well.
The Linux Tools project started working on such a help facility. Currently it will provide help for Linux system libraries, but there are plans to extend this to e.g. doxygen generated help, too.
For a demo see:
http://www.eclipse.org/downloads/download.php?file=/technology/linuxtools/videos/libhoverdemo.ogg

Resources