c_builder 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 35

c_builder #

Pub

An API for generating C code in Dart. Especially helpful for compiler development. Supports generating every possible unit of C code.

Example #

import 'package:c_builder/c_builder.dart';
import 'package:code_buffer/code_buffer.dart';

/// Generates a simple "Hello, world"
main() {
  var unit = new CompilationUnit()
    ..body.addAll([
      new Include.system('stdio.h'),
      new CFunction(new FunctionSignature(CType.int, 'main')
        ..parameters.addAll([
          new Parameter(CType.int, 'argc'),
          new Parameter(CType.char.pointer().pointer(), 'argv'),
        ]))
        ..comments.addAll([
          'This is the entry point.',
          'The system calls this function when starting the program.'
        ])
        ..body.addAll([
          new Expression.value(0).asReturn(),
        ]),
    ]);
  var buf = new CodeBuffer();
  unit.generate(buf);
  print(buf);
}

1.1.0 #

  • Upgrade for Dart 2.
  • Allow structs to have names.
  • Field.value is now optional.

1.0.0+5 #

  • Fixed a bug that caused Fields to generate incorrect code.
  • Added suffix, asFloat, asDouble, and asByte to Expression.
  • Expression.asThrow now returns an Expression.
  • Added CType.auto.

1.0.0+4 #

  • Added pointerType to FunctionSignature.

1.0.0+3 #

  • Add size_t, ptrdiff_t.
  • Add invoke to Expression.

1.0.0+2 #

  • Allow the creation of Enums.
  • Add extern, inline, and enum$ prefixes to CType.
  • Added to _escapeQuotes.

1.0.0+1 #

  • Fixed a tiny bug where integers would be printed with quotes.

1.0.0 #

Initial version.

example/main.dart

import 'package:c_builder/c_builder.dart';
import 'package:code_buffer/code_buffer.dart';

/// Generates a simple "Hello, world"
main() {
  var unit = new CompilationUnit()
    ..body.addAll([
      new Include.system('stdio.h'),
      new CFunction(new FunctionSignature(CType.int, 'main')
        ..parameters.addAll([
          new Parameter(CType.int, 'argc'),
          new Parameter(CType.char.pointer().pointer(), 'argv'),
        ]))
        ..comments.addAll([
          'This is the entry point.',
          'The system calls this function when starting the program.'
        ])
        ..body.addAll([
          new Field(
              CType.float, 'myFloat', new Expression.value(32.5).asFloat()),
          new Expression.value(0).asReturn(),
        ]),
    ]);
  var buf = new CodeBuffer();
  unit.generate(buf);
  print(buf);
}

Use this package as a library

1. Depend on it

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


dependencies:
  c_builder: ^1.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:c_builder/c_builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
71
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
71
Overall:
Weighted score of the above. [more]
35
Learn more about scoring.

We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:c_builder/c_builder.dart.

Health suggestions

Fix lib/c_builder.dart. (-29.24 points)

Analysis of lib/c_builder.dart reported 69 hints, including:

line 14 col 25: Unnecessary new keyword.

line 16 col 29: Unnecessary new keyword.

line 27 col 27: Unnecessary new keyword.

line 62 col 4: 'virtual' is deprecated and shouldn't be used.

line 108 col 29: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-29.32 points)

The package was last published 67 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
code_buffer ^1.0.0 1.0.1
meta ^1.0.0 1.1.8
Transitive dependencies
charcode 1.1.2
path 1.6.4
source_span 1.5.5
term_glyph 1.1.0