Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

static/extern keyword #1

Closed
rsaill opened this issue Aug 17, 2022 · 4 comments
Closed

static/extern keyword #1

rsaill opened this issue Aug 17, 2022 · 4 comments

Comments

@rsaill
Copy link

rsaill commented Aug 17, 2022

Trying to parse (with Clang.Ast.parse_file) and immediately print (with Clang.Printer.translation_unit) the following C program:

static int g1 = 0;
int g2 = 0;
extern int g3;

int bar(int p){
	static int s;
	s++;
	int l = 42;
	return (p + s + l);
}

I get

static int g1 = 0;
int g2 = 0;
int g3;

int bar(int p){
	int s;
	s ++;
	int l = 42;
	return (p + s) + l;
};

The keyword extern is missing for the variable g3 and static is missing for the variable s.

Ronan (alias n47).

@thierry-martinez
Copy link
Owner

thierry-martinez commented Aug 17, 2022

Thank you for inaugurating github issues! This issue made me notice that storage classes worth being exposed as fields in Ast.Var and Ast.Function (they were only accessible via cursor_get_storage_class before). But, be warned that the printer is very incomplete: there is no code printer in clang as far as I know, the clangml printer is a small printer coded in OCaml mainly for internal purpose. Not that it would not worth completing it, but there will be many things to be completed in order to have a decent printer!

This should be fixed in #2: as soon as CI is happy, I will update the snapshot branch. (You may have a try to the branch fix.1.storage_class directly, but you need to bootstrap it first with ./bootstrap.sh.)

thierry-martinez added a commit that referenced this issue Aug 17, 2022
Fix #1: storage classes (functions and vars) are exposed and printed
@thierry-martinez
Copy link
Owner

#2 is now merged and snapshot is updated (I have added a new binding Clang.ext_decl_get_storage_class because clang_Cursor_getStorageClass is not available with Clang 3.4 and 3.5; even if they are quite old versions, I try to keep them supported). Thanks!

@rsaill
Copy link
Author

rsaill commented Aug 18, 2022

Thanks once again for your lightning fast answer and fix.
I have a (possibly unrelated) question though. If I opam pin git+https://github.com/thierry-martinez/clangml.git#snapshot to get your last changes, I observe changes in Clang__Attributes. For example the constructor Clang__Attributes.AlwaysInline has disappeared.
Is that expected?

thierry-martinez added a commit that referenced this issue Aug 18, 2022
rsaill reported in #1 that `AlwaysInline` has disappeared.
@thierry-martinez
Copy link
Owner

Nice catch: no, it wasn't expected. It is now fixed in snapshot. Thank you very much!

thierry-martinez added a commit to thierry-martinez/opam-repository that referenced this issue Sep 5, 2022
This commit pushes a new release of clangml.4.8.0, compatible with
the upcoming LLVM/Clang 15. Changes are:

- Support for Clang/LLVM 15.0.0

- `Ast.character_kind` and `Ast.string_kind` are now distinct
  types (aliases for `Clang.clang_ext_characterkind` and
  `Clang.clang_ext_stringkind` respectively.
  The constructor `Ordinary` replaced the former constructor `Ascii`
  for `string_kind`, to match the new convention used by
  `clang::StringLiteral::StringKind` from Clang 15.0.0.
  The constructor `Ascii` for `character_kind` is left unchanged.

- #1, #2: `Ast.Var` and `Ast.Function` constructors now have a `storage`
  field in addition to the computed `linkage`, exposing the value
  previously accessible via `cursor_get_storage_class`. The
  storage classes are now correctly printed by the printer.
  (reported by Ronan, rsaill/n47, thierry-martinez/clangml#1)

- #3, ocaml#4: fix `Clang.Expr.radix_of_integer_literal` when the literal
  comes from a macro expansion, and fix printing of unsigned/long
  integer literals with `Clang.Printer`.
  (reported by Ronan, rsaill/n47, thierry-martinez/clangml#3)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants