Name

Preprocess::Ops - Preprocess ▷ and ▶ as method dispatch operators in ANSI-C.

Synopsis

Preprocess ▷ and ▶ as method dispatch operators in ANSI-C by translating:

p = node ▶ key("a");

to:

p = node->proto->key(node, "a");

and:

p = tree ▷ root;

to:

p = tree.proto->root(tree);

Description

Preprocess ▷ and ▶ as method dispatch operators in ANSI-C.

Version 20200811.

The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.

Preprocess

Preprocess ▷ and ▶ as method dispatch operators.

c($inputFile, $cFile, $hFile, $column)

Preprocess ▷ and ▶ as method dispatch operators in ANSI-C.

   Parameter   Description
1  $inputFile  Input file
2  $cFile      C output file
3  $hFile      H output file
4  $column     Optional start column for comments (80)

Example:

  my $s = writeTempFile(<<END);
static Node setKey_node_node_string                                             // Copy a string into the key field of a node //TsetKey
 (const Tree   tree,                                                            // Tree
  const Node   node,                                                            // Node
  const string key)                                                             // Key
 {node ▷ key = t ▶ saveString(key);                                             // Set key with saved string
  return node;
 }
END


  my $c = temporaryFile.'.c';                                                   # Translated C file  # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲

  my $h = temporaryFile.'.h';                                                   # Prototypes in H file


  c($s, $c, $h);                                                                # Preprocess  # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲



  ok index(readFile($c), <<END) > -1;                                           # Generated C file. Remove first line as it contains source file name  # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲

static Node setKey_node_node_string                                             // Copy a string into the key field of a node //TsetKey
 (const Tree   tree,                                                            // Tree
  const Node   node,                                                            // Node
  const string key)                                                             // Key
 {node.proto->key(node) = t->proto->saveString(t, key);                                             // Set key with saved string
  return node;
 }
END

  ok index(readFile($h), <<END) > -1;                                            # Generated H prototypes file
static Node setKey_node_node_string
 (const Tree   tree,
  const Node   node,
  const string key);
struct ProtoTypes_Tree {
  Node  (*setKey)(                                                              // Copy a string into the key field of a node //TsetKey
    const Tree tree,                                                            // Tree
    const Node node,                                                            // Node
    const string key);                                                          // Key
 } const ProtoTypes_Tree =
{setKey_node_node_string};
END

Private Methods

trim($s)

Remove trailing white space and comment

   Parameter  Description
1  $s         String

method($line)

Check whether a line of C code defines a method, returning (return, name, flags, comment) if it is, else ()

   Parameter  Description
1  $line      Line of C code

Index

1 c - Preprocess ▷ and ▶ as method dispatch operators in ANSI-C.

2 method - Check whether a line of C code defines a method, returning (return, name, flags, comment) if it is, else ()

3 trim - Remove trailing white space and comment

Installation

This module is written in 100% Pure Perl and, thus, it is easy to read, comprehend, use, modify and install via cpan:

sudo cpan install Preprocess::Ops

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

Copyright (c) 2016-2019 Philip R Brenan.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.