libclang 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 43

libclang.dart #

Pub Package

Dart FFI bindings to libclang.

The package is still under initial development. Issues and PRs are welcome.

Warning #

  • The package currently trys to call dynamic library /usr/lib/llvm-{9,10}/lib/libclang.so directly. Look at here for detail.

  • According to #41062 and #36730 from dart SDK, functions related to CXCursor are supported by a wrapper of libclang until official support of pass/return by value.

Setup Wrapper #

Make sure you have g++ installed.

make

0.1.0 #

Support Features:

  • Cursor
  • CursorKind
  • visitChildren
  • getCursorSpelling
  • getCursorKindSpelling

0.0.1 #

Support Features:

  • Index
  • TranslationUnit
  • TranslationUnitFlag
  • Parse source/header file for C/C++.
  • Load/save AST.

example/main.dart

import 'dart:ffi';

import 'package:libclang/libclang.dart';

void main(List<String> args) {
  var index = Index(0, 0);
  var unit = TranslationUnit.parse(
      index, 'example/example.h', TranslationUnitFlag.none);

  var cursor = unit.cursor;
  cursor.visitChildren((c, p, client) {
    print('Found ${c.ref.kind.value} ${c.ref.kind.spelling} ${c.spelling}');
    return ChildVisitResult.recurse;
  });

  unit.dispose();
  index.dispose();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  libclang: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:libclang/libclang.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
43
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because:

  • package:libclang/libclang.dart that imports:
  • package:libclang/src/translation_unit.dart that imports:
  • package:libclang/src/index.dart that imports:
  • package:libclang/src/common.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:libclang/libclang.dart that imports:
  • package:libclang/src/translation_unit.dart that imports:
  • package:libclang/src/index.dart that imports:
  • package:libclang/src/common.dart that imports:
  • dart:io

Health suggestions

Fix lib/src/cursor_kind.dart. (-25 points)

Analysis of lib/src/cursor_kind.dart reported 182 hints, including:

line 19 col 3: Prefer using /// for doc comments.

line 30 col 3: Prefer using /// for doc comments.

line 33 col 3: Prefer using /// for doc comments.

line 36 col 3: Prefer using /// for doc comments.

line 39 col 3: Prefer using /// for doc comments.

Fix lib/src/translation_unit_flag.dart. (-4.41 points)

Analysis of lib/src/translation_unit_flag.dart reported 9 hints, including:

line 32 col 3: Prefer using /// for doc comments.

line 48 col 3: Prefer using /// for doc comments.

line 58 col 3: Prefer using /// for doc comments.

line 67 col 3: Prefer using /// for doc comments.

line 75 col 3: Prefer using /// for doc comments.

Fix lib/src/cursor.dart. (-0.50 points)

Analysis of lib/src/cursor.dart reported 1 hint:

line 74 col 24: Don't explicitly initialize variables to null.

Fix lib/src/translation_unit.dart. (-0.50 points)

Analysis of lib/src/translation_unit.dart reported 1 hint:

line 96 col 15: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
ffi ^0.1.3 0.1.3