Gnatcheck custom rules - global-variables

I'm trying to obtain a list of global variables declared in a large Ada project.
gnatcheck has a rule for that: Global_Variables, but that rule is not exhaustive:
"Flag any variable declaration that appears immediately within the specification of a library package or library generic package. Variable declarations in nested packages and inside package instantiations are not flagged"
I'd like to be able to obtain the list of variables declared in package instantiations as well.
I would try to implement my own gnatcheck custom rule, but cannot seem to find where the rules are implemented.
This doc says it's supposed to be in share/lkql, but there is no such directory in my GNAT Studio installations (I've looked at GNAT Pro 19.2, GNAT Pro 22.1 and Gnat Community 2021).
Windows cannot find any .lkql file.
Is it possible to make such a rule? If so, how/where? Are there alternatives to gnatcheck to obtain the list of global variables?

Related

Where are definitions of Rf_lang2 and Rf_lang3?

I am starting to explore source code of R interpreter itself.
I started from src/main/gram.y and src/include/Rinternals.h, and also referred information on the Web( https://marlin-na.github.io/r-api/pairlists/ ). I found it seems to be constructing abstract syntax tree using linked list like data structure.
They are using Rf_lang2, Rf_lang3 and functions begining with Rf_ prefix.
However, I cannot find those definitions of Rf_lang2, Rf_lang3 and Rf_*** functions.
Could you tell me the files of those functions' definitions?
I am browsing source tree at https://github.com/wch/r-source

How can I create a library in julia?

I need to know how to create a library in Julia and where I must keep it in order to call it later. I come from C and matlab, it seems there is no documentation about pratical programming in Julia.
Thanks
If you are new to Julia, you will find it helpful to realize that Julia has two mechanisms for loading code. Stating you "need to know how to create a library in Julia" would imply you most likely will want to create a Julia module docs and possibly a packagedocs. But the first method listed below may also be useful to you.
The two methods to load code in Julia are:
1. Code inclusion via the include("file_path_relative_to_call_or_pwd.jl")docs
The expression include("source.jl") causes the contents of the file source.jl to be evaluated in the global scope of the module where the include call occurs.
Regarding where the "source.jl" file is searched for:
The included path, source.jl, is interpreted relative to the file where the include call occurs. This makes it simple to relocate a subtree of source files. In the REPL, included paths are interpreted relative to the current working directory, pwd().
Including a file is an easy way to pull code from one file into another one. However, the variables, functions, etc. defined in the included file become part of the current namespace. On the other hand, a module provides its own distinct namespace.
2. Package loading via import X or using Xdocs
The import mechanism allows you to load a package—i.e. an independent, reusable collection of Julia code, wrapped in a module—and makes the resulting module available by the name X inside of the importing module.
Regarding the difference between these two methods of code loading:
Code inclusion is quite straightforward: it simply parses and evaluates a source file in the context of the caller. Package loading is built on top of code inclusion and is quite a bit more complex.
Regarding where Julia searches for module files, see docs summary:
The global variable LOAD_PATH contains the directories Julia searches for modules when calling require. It can be extended using push!:
push!(LOAD_PATH, "/Path/To/My/Module/")
Putting this statement in the file ~/.julia/config/startup.jl will extend LOAD_PATH on every Julia startup. Alternatively, the module load path can be extended by defining the environment variable JULIA_LOAD_PATH.
For one of the simplest examples of a Julia module, see Example.jl
module Example
export hello, domath
hello(who::String) = "Hello, $who"
domath(x::Number) = x + 5
end
and for the Example package, see here.
Side Note There is also a planned (future) library capability similar to what you may have used with other languages. See docs:
Library (future work): a compiled binary dependency (not written in Julia) packaged to be used by a Julia project. These are currently typically built in- place by a deps/build.jl script in a project’s source tree, but in the future we plan to make libraries first-class entities directly installed and upgraded by the package manager.

Atom editor: list and jump to definition(s) in project

As already mentioned I'm using the Atom text editor.
I'm currently working on a project written in c++. Of course it is desirable to jump to the definition of a function (in another project file), or other uses of this function (within the project). As far as I know this can be achieved with the packages I'll mention below. I want the package to display me the definition along with the path to the corresponding file which holds the definition and ideally the line where it occurs.
I'll welcome any comments and suggestions on how to solve the below mentioned problem(s) I have with (one of) the packages. Moreover I'm also thankful about pointers to possible solutions or posts concerning my problem(s), or how I can achieve this with another package.
Here is what I found / tried / did so far.
goto
Currently I'm using this package, although it is rather slow and does not show the arguments of the function as e.g. atom-ctags does, but it's the only package which displays me the files I need to see.
It shows me where the function is defined as well as where it is also used. However it does not show me the path to the file corresponding file it refers to.
atom-ctags
I also tried this package, building the tags is quite fast and moreover it show me the path to the file. But this package only lists the .cc files and not the .h files. It appears to me as if it only shows me the other uses but not the definition, which is obviously a problem.
I also tried generating the ctags myself and changing the command options in the settings of the package, unfortunately without any success.
Atoms built-in symbols-view
In order to get this to work, one needs to generate the symbols. This can be, for example, achieved with the symbol-gen package. However, it shows me some of the definitions, but also no .h files. Moreover, jumping to the definition results in a Selected file does not exist., therefore it is not usable at all.
goto-definition
Just for completeness, there is also this package. It does not work for me, since c++ is not supported but maybe others will find it useful.
symbols-plus
Again, for completeness, this should be a replacement for the atom built-in, but when disabling the build-in it does not show me any jump functionality nor is a short cut mentioned.
So, basically, nothing really works well. I have tried Symbol Tree View but it but barely works.

Import a module and use it in julialang

Since in http://julia.readthedocs.org/en/latest/manual/modules/ there's no much info about modules, I would like to ask the following.
I want to try two modules via ijulia. Both modules are in my working directory as
name-of-files.jul. I will call them generically module_1.jul and module_2.jul.
module_1.jul uses module_2.jul and I load it with
using module_2
On ijulia session, if I try
using module_1
gives an error. I also tried
include("module_1.jul")
This last sentence, when executed, rises an error because the module_1.jul cannot find
variable "x" that I know is contained in module_1.jul (in this case I "loaded" the module
using include("module2.jul") inside module_1.jul
Julias module system assumes some things that aren't necessarily obvious from the documenation at first.
Julia files should end with .jl extensions.
Julia looks for module files in directories defined in the LOAD_PATH variable.
Julia looks for files in those directories in the form ModuleName/src/file.jl
If using module_1 fails then I'm guessing it's because it's source files fail one of the above criteria.
Some time has passed since this question. Recently, Noah_S wrote the solution in the comments of the previous answer; this means that it is a recurrent doubt for people starting to learn the language. For their sake, I will re-write it here Noah_S' answer along with my most novel solution.
I am a mess with the julia versions and which commands work with the specific ones, so for older julia versions we have to look for the \path and then include in the julia module
push!(LOAD_PATH, "/path")
In newer versions this can be improved. Forget about looking by hand the path and just do
path = readstring(`pwd`)
push!(LOAD_PATH, chomp(path))
I hope this can be useful to many julians newcomers.

Linking multiple files while creating a package in R

I am trying to create a package in R wherein I have created lots of new custom Classes. Each class is in a different file. The Classes inherit from a parent class and inherit to other classes.
While running my codes I call each of them like this
source("package/father.R")
source("package/son.R")
source("package/grandson.R")
Definition for Some of the methods needed by the grandson Class in defined in Son class. I use package.skeleton() to call each of them and create a package and it seems to work fine. But when running R CMD Check(and when trying install into R), it throws an error because the function tries to call the files in the alphabetical order and so the file grandson.R is called before son.R and it shows and error saying that the methods has not been defined. If I change the names to zgrandson.R, R called that file the last, and everything seems to work fine, but this is evidently not a solution for the problem.
I have read tutorials for creating packages, but all of them seem to deal with simple cases where there is no inheritance/calling other files in R. Hope I have made myself clear.
As far as I understand, you can use the Collate field in the DESCRIPTION file to control this.
Quoting from the Writing R Extensions manual:
An ‘Collate’ field can be used for controlling the collation order for
the R code files in a package when these are processed for package
installation. The default is to collate according to the ‘C’ locale.
If present, the collate specification must list all R code files in
the package (taking possible OS-specific subdirectories into account,
see Package subdirectories) as a whitespace separated list of file
paths relative to the R subdirectory. Paths containing white space or
quotes need to be quoted. An OS-specific collation field
(‘Collate.unix’ or ‘Collate.windows’) will be used instead of
‘Collate’.
So, you could specify:
Collate:
father.r
son.R
grandson.r
Or simply rename the files in such a way that lexicographic sorting order will result in the correct collation order, as you indicated in your question.
But also see this answer by #DirkEddelbuettel on a similar question.

Resources