Merge commit 'ad095896dd223f1c22b85ac5ec84ab11fb732b07'

pull/594/head
Wilfred Hughes 2023-07-24 21:20:05 +07:00
commit f43e91faf7
25 changed files with 108146 additions and 63041 deletions

@ -4,7 +4,7 @@
Added support for LaTeX.
Updated grammar for Java.
Updated grammar for C and Java.
Improved parsing of qualified constructors in Haskell.

@ -1,7 +1,7 @@
image: Visual Studio 2015
image: Visual Studio 2022
environment:
nodejs_version: "8"
nodejs_version: "18"
platform:
- x64

@ -0,0 +1,20 @@
module.exports = {
'env': {
'commonjs': true,
'es2021': true,
},
'extends': 'google',
'overrides': [
],
'parserOptions': {
'ecmaVersion': 'latest',
'sourceType': 'module',
},
'rules': {
'indent': ['error', 2, {'SwitchCase': 1}],
'max-len': [
'error',
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true},
],
},
};

@ -1,2 +1,6 @@
/src/** linguist-vendored
/examples/* linguist-vendored
src/grammar.json -diff
src/node-types.json -diff
src/parser.c -diff

@ -0,0 +1,30 @@
name: CI
on:
workflow_dispatch:
pull_request:
push:
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm install
- run: npm test
test_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm install
- run: npm run test-windows

@ -0,0 +1,19 @@
name: Lint
on:
push:
branches:
- master
pull_request:
branches:
- "**"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm install
- name: Run ESLint
run: npm run lint

@ -1,33 +0,0 @@
name: Publish on crates.io
on:
push:
tags:
- v*
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable
run: |
rustup toolchain install stable --profile minimal --no-self-update
- name: Verify publish crate
uses: katyo/publish-crates@v1
with:
dry-run: true
- name: Publish crate
uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

@ -0,0 +1,103 @@
name: Release
on:
workflow_run:
workflows: ["CI"]
branches:
- master
types:
- completed
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get previous commit SHA
id: get_previous_commit
run: |
LATEST_TAG=$(git describe --tags --abbrev=0)
if [[ -z "$LATEST_TAG" ]]; then
echo "No tag found. Failing..."
exit 1
fi
echo "latest_tag=${LATEST_TAG#v}" >> "$GITHUB_ENV" # Remove 'v' prefix from the tag
- name: Check if version changed and is greater than the previous
id: version_check
run: |
# Compare the current version with the version from the previous commit
PREVIOUS_NPM_VERSION=${{ env.latest_tag }}
CURRENT_NPM_VERSION=$(jq -r '.version' package.json)
CURRENT_CARGO_VERSION=$(awk -F '"' '/^version/ {print $2}' Cargo.toml)
if [[ "$CURRENT_NPM_VERSION" != "$CURRENT_CARGO_VERSION" ]]; then # Cargo.toml and package.json versions must match
echo "Mismatch: NPM version ($CURRENT_NPM_VERSION) and Cargo.toml version ($CURRENT_CARGO_VERSION)"
echo "version_changed=false" >> "$GITHUB_ENV"
else
if [[ "$PREVIOUS_NPM_VERSION" == "$CURRENT_NPM_VERSION" ]]; then
echo "version_changed=" >> "$GITHUB_ENV"
else
IFS='.' read -ra PREVIOUS_VERSION_PARTS <<< "$PREVIOUS_NPM_VERSION"
IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_NPM_VERSION"
VERSION_CHANGED=false
for i in "${!PREVIOUS_VERSION_PARTS[@]}"; do
if [[ ${CURRENT_VERSION_PARTS[i]} -gt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
VERSION_CHANGED=true
break
elif [[ ${CURRENT_VERSION_PARTS[i]} -lt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
break
fi
done
echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV"
echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV"
fi
fi
- name: Display result
run: |
echo "Version bump detected: ${{ env.version_changed }}"
- name: Fail if version is lower
if: env.version_changed == 'false'
run: exit 1
- name: Setup Node
if: env.version_changed == 'true'
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
if: env.version_changed == 'true'
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: npm publish
- name: Setup Rust
if: env.version_changed == 'true'
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Publish to Crates.io
if: env.version_changed == 'true'
uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Tag versions
if: env.version_changed == 'true'
run: |
git checkout master
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -d "v${{ env.current_version }}" || true
git push origin --delete "v${{ env.current_version }}" || true
git tag -a "v${{ env.current_version }}" -m "Version ${{ env.current_version }}"
git push origin "v${{ env.current_version }}"

@ -3,4 +3,3 @@
/build
/script
/target

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-c"
description = "C grammar for the tree-sitter parsing library"
version = "0.20.2"
version = "0.20.4"
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
license = "MIT"
readme = "bindings/rust/README.md"
@ -9,6 +9,7 @@ keywords = ["incremental", "parsing", "c"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-c"
edition = "2018"
autoexamples = false
build = "bindings/rust/build.rs"
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
@ -17,7 +18,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "0.20"
tree-sitter = "0.20.10"
[build-dependencies]
cc = "1.0"

@ -33,4 +33,4 @@ let package = Package(
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
]
)
)

@ -1,7 +1,7 @@
tree-sitter-c
==================
# tree-sitter-c
[![Build Status](https://travis-ci.org/tree-sitter/tree-sitter-c.svg?branch=master)](https://travis-ci.org/tree-sitter/tree-sitter-c)
[![Build status](https://ci.appveyor.com/api/projects/status/7u0sy6ajmxro4wfh/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter-c/branch/master)
C grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). Adapted from [this C99 grammar](http://slps.github.io/zoo/c/iso-9899-tc3.html).
C grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
Adapted from [this C99 grammar](http://slps.github.io/zoo/c/iso-9899-tc3.html).

@ -1,28 +1,30 @@
#include "nan.h"
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_c();
extern "C" TSLanguage *tree_sitter_c();
namespace {
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_c());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("c").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance =
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_c());
Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("c").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_c_binding, Init)
} // namespace
} // namespace

@ -1,19 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_c_binding");
module.exports = require('../../build/Release/tree_sitter_c_binding');
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_c_binding");
module.exports = require('../../build/Debug/tree_sitter_c_binding');
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
throw error1;
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
module.exports.nodeTypeInfo = require('../../src/node-types.json');
} catch (_) {}

@ -5,7 +5,7 @@ fn main() {
let src_dir = Path::new("src");
let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config.include(src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
{
"name": "tree-sitter-c",
"version": "0.20.2",
"version": "0.20.4",
"description": "C grammar for node-tree-sitter",
"main": "bindings/node",
"keywords": [
@ -17,10 +17,13 @@
"nan": "^2.14.0"
},
"devDependencies": {
"eslint": "^8.41.0",
"eslint-config-google": "^0.14.0",
"tree-sitter-cli": "^0.20.0"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"lint": "eslint grammar.js",
"test": "tree-sitter test && tree-sitter parse examples/* --quiet --time",
"test-windows": "tree-sitter test"
},
@ -30,6 +33,10 @@
"file-types": [
"c",
"h"
],
"injection-regex": "^(c|h)$",
"highlights": [
"queries/highlights.scm"
]
}
]

File diff suppressed because it is too large Load Diff

@ -95,6 +95,14 @@
"type": "field_expression",
"named": true
},
{
"type": "generic_expression",
"named": true
},
{
"type": "gnu_asm_expression",
"named": true
},
{
"type": "identifier",
"named": true
@ -107,6 +115,10 @@
"type": "number_literal",
"named": true
},
{
"type": "offsetof_expression",
"named": true
},
{
"type": "parenthesized_expression",
"named": true
@ -257,6 +269,10 @@
"type": "pointer_declarator",
"named": true
},
{
"type": "primitive_type",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -416,6 +432,10 @@
"type": "_expression",
"named": true
},
{
"type": "compound_statement",
"named": true
},
{
"type": "preproc_defined",
"named": true
@ -951,8 +971,12 @@
"fields": {},
"children": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "character",
"named": true
},
{
"type": "escape_sequence",
"named": true
@ -1083,6 +1107,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "string_literal",
"named": true
@ -1116,7 +1144,7 @@
},
"consequence": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "_expression",
@ -1272,6 +1300,21 @@
}
}
},
{
"type": "else_clause",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "_statement",
"named": true
}
]
}
},
{
"type": "enum_specifier",
"named": true,
@ -1295,7 +1338,27 @@
"named": true
}
]
},
"underlying_type": {
"multiple": false,
"required": false,
"types": [
{
"type": "primitive_type",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "attribute_specifier",
"named": true
}
]
}
},
{
@ -1676,6 +1739,236 @@
]
}
},
{
"type": "generic_expression",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "_expression",
"named": true
},
{
"type": "type_descriptor",
"named": true
}
]
}
},
{
"type": "gnu_asm_clobber_list",
"named": true,
"fields": {
"register": {
"multiple": true,
"required": false,
"types": [
{
"type": "string_literal",
"named": true
}
]
}
}
},
{
"type": "gnu_asm_expression",
"named": true,
"fields": {
"assembly_code": {
"multiple": false,
"required": true,
"types": [
{
"type": "concatenated_string",
"named": true
},
{
"type": "string_literal",
"named": true
}
]
},
"clobbers": {
"multiple": false,
"required": false,
"types": [
{
"type": "gnu_asm_clobber_list",
"named": true
}
]
},
"goto_labels": {
"multiple": false,
"required": false,
"types": [
{
"type": "gnu_asm_goto_list",
"named": true
}
]
},
"input_operands": {
"multiple": false,
"required": false,
"types": [
{
"type": "gnu_asm_input_operand_list",
"named": true
}
]
},
"output_operands": {
"multiple": false,
"required": false,
"types": [
{
"type": "gnu_asm_output_operand_list",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "gnu_asm_qualifier",
"named": true
}
]
}
},
{
"type": "gnu_asm_goto_list",
"named": true,
"fields": {
"label": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
{
"type": "gnu_asm_input_operand",
"named": true,
"fields": {
"constraint": {
"multiple": false,
"required": true,
"types": [
{
"type": "string_literal",
"named": true
}
]
},
"symbol": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "_expression",
"named": true
}
]
}
}
},
{
"type": "gnu_asm_input_operand_list",
"named": true,
"fields": {
"operand": {
"multiple": true,
"required": false,
"types": [
{
"type": "gnu_asm_input_operand",
"named": true
}
]
}
}
},
{
"type": "gnu_asm_output_operand",
"named": true,
"fields": {
"constraint": {
"multiple": false,
"required": true,
"types": [
{
"type": "string_literal",
"named": true
}
]
},
"symbol": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
{
"type": "gnu_asm_output_operand_list",
"named": true,
"fields": {
"operand": {
"multiple": true,
"required": false,
"types": [
{
"type": "gnu_asm_output_operand",
"named": true
}
]
}
}
},
{
"type": "gnu_asm_qualifier",
"named": true,
"fields": {}
},
{
"type": "goto_statement",
"named": true,
@ -1701,7 +1994,7 @@
"required": false,
"types": [
{
"type": "_statement",
"type": "else_clause",
"named": true
}
]
@ -1968,6 +2261,37 @@
"named": true,
"fields": {}
},
{
"type": "null",
"named": true,
"fields": {}
},
{
"type": "offsetof_expression",
"named": true,
"fields": {
"member": {
"multiple": false,
"required": true,
"types": [
{
"type": "field_identifier",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "type_descriptor",
"named": true
}
]
}
}
},
{
"type": "parameter_declaration",
"named": true,
@ -2344,6 +2668,90 @@
]
}
},
{
"type": "preproc_elifdef",
"named": true,
"fields": {
"alternative": {
"multiple": false,
"required": false,
"types": [
{
"type": "preproc_elif",
"named": true
},
{
"type": "preproc_else",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "_statement",
"named": true
},
{
"type": "_type_specifier",
"named": true
},
{
"type": "declaration",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "linkage_specification",
"named": true
},
{
"type": "preproc_call",
"named": true
},
{
"type": "preproc_def",
"named": true
},
{
"type": "preproc_function_def",
"named": true
},
{
"type": "preproc_if",
"named": true
},
{
"type": "preproc_ifdef",
"named": true
},
{
"type": "preproc_include",
"named": true
},
{
"type": "type_definition",
"named": true
}
]
}
},
{
"type": "preproc_else",
"named": true,
@ -2571,6 +2979,10 @@
"type": "preproc_elif",
"named": true
},
{
"type": "preproc_elifdef",
"named": true
},
{
"type": "preproc_else",
"named": true
@ -2771,6 +3183,10 @@
{
"type": "escape_sequence",
"named": true
},
{
"type": "string_content",
"named": true
}
]
}
@ -2801,9 +3217,13 @@
}
},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "attribute_specifier",
"named": true
},
{
"type": "ms_declspec_modifier",
"named": true
@ -2887,21 +3307,61 @@
"required": false,
"types": [
{
"type": "_statement",
"type": "_type_specifier",
"named": true
},
{
"type": "_type_specifier",
"type": "attributed_statement",
"named": true
},
{
"type": "break_statement",
"named": true
},
{
"type": "case_statement",
"named": true
},
{
"type": "compound_statement",
"named": true
},
{
"type": "continue_statement",
"named": true
},
{
"type": "declaration",
"named": true
},
{
"type": "do_statement",
"named": true
},
{
"type": "expression_statement",
"named": true
},
{
"type": "for_statement",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "goto_statement",
"named": true
},
{
"type": "if_statement",
"named": true
},
{
"type": "labeled_statement",
"named": true
},
{
"type": "linkage_specification",
"named": true
@ -2930,9 +3390,21 @@
"type": "preproc_include",
"named": true
},
{
"type": "return_statement",
"named": true
},
{
"type": "switch_statement",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "while_statement",
"named": true
}
]
}
@ -3082,9 +3554,13 @@
}
},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "attribute_specifier",
"named": true
},
{
"type": "ms_declspec_modifier",
"named": true
@ -3177,6 +3653,14 @@
"type": "#elif",
"named": false
},
{
"type": "#elifdef",
"named": false
},
{
"type": "#elifndef",
"named": false
},
{
"type": "#else",
"named": false
@ -3353,6 +3837,10 @@
"type": "L'",
"named": false
},
{
"type": "NULL",
"named": false
},
{
"type": "U\"",
"named": false
@ -3389,6 +3877,18 @@
"type": "_Atomic",
"named": false
},
{
"type": "_Generic",
"named": false
},
{
"type": "_Noreturn",
"named": false
},
{
"type": "__asm__",
"named": false
},
{
"type": "__attribute__",
"named": false
@ -3413,6 +3913,10 @@
"type": "__fastcall",
"named": false
},
{
"type": "__restrict__",
"named": false
},
{
"type": "__stdcall",
"named": false
@ -3433,6 +3937,10 @@
"type": "_unaligned",
"named": false
},
{
"type": "asm",
"named": false
},
{
"type": "auto",
"named": false
@ -3445,6 +3953,10 @@
"type": "case",
"named": false
},
{
"type": "character",
"named": true
},
{
"type": "comment",
"named": true
@ -3453,6 +3965,10 @@
"type": "const",
"named": false
},
{
"type": "constexpr",
"named": false
},
{
"type": "continue",
"named": false
@ -3530,13 +4046,21 @@
"named": true
},
{
"type": "null",
"named": true
"type": "noreturn",
"named": false
},
{
"type": "nullptr",
"named": false
},
{
"type": "number_literal",
"named": true
},
{
"type": "offsetof",
"named": false
},
{
"type": "preproc_arg",
"named": true
@ -3581,6 +4105,10 @@
"type": "static",
"named": false
},
{
"type": "string_content",
"named": true
},
{
"type": "struct",
"named": false
@ -3593,6 +4121,10 @@
"type": "system_lib_string",
"named": true
},
{
"type": "thread_local",
"named": false
},
{
"type": "true",
"named": true

File diff suppressed because it is too large Load Diff

@ -1,6 +1,10 @@
========================================================================
pointer declarations vs multiplications
========================================================================
================================================================================
pointer declarations vs expressions
================================================================================
TSLanguage *(*lang_parser)(void);
char (*ptr_to_array)[];
int main() {
// declare a function pointer
@ -11,29 +15,60 @@ int main() {
e(f * g);
}
---
--------------------------------------------------------------------------------
(translation_unit (function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(compound_statement
(comment)
(declaration
(type_identifier)
(pointer_declarator (function_declarator
(identifier)
(parameter_list (parameter_declaration (type_identifier) (identifier))))))
(comment)
(expression_statement (binary_expression
(identifier)
(call_expression (identifier) (argument_list (number_literal)))))
(expression_statement (call_expression
(translation_unit
(declaration
(type_identifier)
(pointer_declarator
(function_declarator
(parenthesized_declarator
(pointer_declarator
(identifier)))
(parameter_list
(parameter_declaration
(primitive_type))))))
(declaration
(primitive_type)
(array_declarator
(parenthesized_declarator
(pointer_declarator
(identifier)))))
(function_definition
(primitive_type)
(function_declarator
(identifier)
(argument_list (binary_expression (identifier) (identifier))))))))
========================================================================
(parameter_list))
(compound_statement
(comment)
(declaration
(type_identifier)
(pointer_declarator
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(type_identifier)
(identifier))))))
(comment)
(expression_statement
(binary_expression
(identifier)
(call_expression
(identifier)
(argument_list
(number_literal)))))
(expression_statement
(call_expression
(identifier)
(argument_list
(binary_expression
(identifier)
(identifier))))))))
================================================================================
casts vs multiplications
========================================================================
================================================================================
/*
* ambiguities
@ -47,41 +82,60 @@ int main() {
d((e * f));
}
---
--------------------------------------------------------------------------------
(translation_unit
(comment)
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(comment)
(expression_statement (call_expression
(identifier)
(argument_list (cast_expression (type_descriptor (type_identifier) (abstract_pointer_declarator)) (identifier)))))
(expression_statement
(call_expression
(identifier)
(argument_list
(cast_expression
(type_descriptor
(type_identifier)
(abstract_pointer_declarator))
(identifier)))))
(comment)
(expression_statement (call_expression
(identifier)
(argument_list (parenthesized_expression (binary_expression (identifier) (identifier)))))))))
========================================================================
(expression_statement
(call_expression
(identifier)
(argument_list
(parenthesized_expression
(binary_expression
(identifier)
(identifier)))))))))
================================================================================
function-like type macros vs function calls
========================================================================
================================================================================
// this is a macro
GIT_INLINE(int *) x = 5;
---
--------------------------------------------------------------------------------
(translation_unit
(comment)
(declaration
(macro_type_specifier (identifier) (type_descriptor (primitive_type) (abstract_pointer_declarator)))
(init_declarator (identifier) (number_literal))))
(macro_type_specifier
(identifier)
(type_descriptor
(primitive_type)
(abstract_pointer_declarator)))
(init_declarator
(identifier)
(number_literal))))
========================================================================
================================================================================
function calls vs parenthesized declarators vs macro types
========================================================================
================================================================================
int main() {
/*
@ -98,21 +152,29 @@ int main() {
efg hij;
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(comment)
(expression_statement (call_expression (identifier) (argument_list (identifier))))
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier))))
(comment)
(declaration (type_identifier) (identifier)))))
(declaration
(type_identifier)
(identifier)))))
========================================================================
================================================================================
Call expressions vs empty declarations w/ macros as types
========================================================================
================================================================================
int main() {
int a = 1;
@ -120,22 +182,34 @@ int main() {
A(A *);
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(declaration (primitive_type) (init_declarator (identifier) (number_literal)))
(expression_statement (call_expression (identifier) (argument_list (identifier))))
(declaration
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier))))
(macro_type_specifier
(identifier)
(type_descriptor (type_identifier) (abstract_pointer_declarator))))))
(type_descriptor
(type_identifier)
(abstract_pointer_declarator))))))
========================================================================
================================================================================
Comments after for loops with ambiguities
========================================================================
================================================================================
int main() {
for (a *b = c; d; e) {
@ -147,32 +221,54 @@ int main() {
g;
}
---
--------------------------------------------------------------------------------
(translation_unit (function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(compound_statement
(for_statement
(declaration (type_identifier) (init_declarator
(pointer_declarator (identifier))
(identifier)))
(identifier)
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(compound_statement
(expression_statement (identifier))))
(comment)
(expression_statement (identifier)))))
(parameter_list))
(compound_statement
(for_statement
(declaration
(type_identifier)
(init_declarator
(pointer_declarator
(identifier))
(identifier)))
(identifier)
(identifier)
(compound_statement
(expression_statement
(identifier))))
(comment)
(expression_statement
(identifier)))))
===============================================
================================================================================
Top-level macro invocations
===============================================
================================================================================
DEFINE_SOMETHING(THING_A, "this is a thing a");
DEFINE_SOMETHING(THING_B, "this is a thing b", "thanks");
---
--------------------------------------------------------------------------------
(translation_unit
(expression_statement (call_expression (identifier) (argument_list (identifier) (string_literal))))
(expression_statement (call_expression (identifier) (argument_list (identifier) (string_literal) (string_literal)))))
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier)
(string_literal
(string_content)))))
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier)
(string_literal
(string_content))
(string_literal
(string_content))))))

@ -1,6 +1,6 @@
============================================
================================================================================
Struct declarations
============================================
================================================================================
struct s1;
@ -9,7 +9,11 @@ struct s2 {
float y : 5;
};
---
struct s3 {
int x : 1, y : 2;
};
--------------------------------------------------------------------------------
(translation_unit
(struct_specifier
@ -17,17 +21,29 @@ struct s2 {
(struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier))
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause (number_literal))))))
============================================
(field_declaration
type: (primitive_type)
declarator: (field_identifier))
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause
(number_literal)))))
(struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause
(number_literal))
declarator: (field_identifier)
(bitfield_clause
(number_literal))))))
================================================================================
Union declarations
============================================
================================================================================
union u1;
@ -36,7 +52,7 @@ union s2 {
float y;
};
---
--------------------------------------------------------------------------------
(translation_unit
(union_specifier
@ -51,9 +67,9 @@ union s2 {
type: (primitive_type)
declarator: (field_identifier)))))
============================================
================================================================================
Enum declarations
============================================
================================================================================
enum e1;
@ -67,7 +83,11 @@ enum e3 {
val1,
};
---
enum e4: int {
val1,
};
--------------------------------------------------------------------------------
(translation_unit
(enum_specifier
@ -75,17 +95,28 @@ enum e3 {
(enum_specifier
name: (type_identifier)
body: (enumerator_list
(enumerator name: (identifier))
(enumerator name: (identifier) value: (number_literal))
(enumerator name: (identifier))))
(enumerator
name: (identifier))
(enumerator
name: (identifier)
value: (number_literal))
(enumerator
name: (identifier))))
(enum_specifier
name: (type_identifier)
body: (enumerator_list
(enumerator name: (identifier)))))
(enumerator
name: (identifier))))
(enum_specifier
name: (type_identifier)
underlying_type: (primitive_type)
body: (enumerator_list
(enumerator
name: (identifier)))))
======================================================
================================================================================
Struct declarations containing preprocessor directives
======================================================
================================================================================
struct s {
#define A 5
@ -93,19 +124,27 @@ struct s {
#undef A
};
---
--------------------------------------------------------------------------------
(translation_unit
(struct_specifier
(type_identifier)
(field_declaration_list
(preproc_def (identifier) (preproc_arg))
(field_declaration (primitive_type) (array_declarator (field_identifier) (identifier)))
(preproc_call (preproc_directive) (preproc_arg)))))
============================================
(preproc_def
(identifier)
(preproc_arg))
(field_declaration
(primitive_type)
(array_declarator
(field_identifier)
(identifier)))
(preproc_call
(preproc_directive)
(preproc_arg)))))
================================================================================
Primitive-typed variable declarations
============================================
================================================================================
unsigned short int a;
long int b, c = 5, d;
@ -113,14 +152,16 @@ float d, e;
unsigned f;
short g, h;
---
--------------------------------------------------------------------------------
(translation_unit
(declaration
type: (sized_type_specifier type: (primitive_type))
type: (sized_type_specifier
type: (primitive_type))
declarator: (identifier))
(declaration
type: (sized_type_specifier type: (primitive_type))
type: (sized_type_specifier
type: (primitive_type))
declarator: (identifier)
declarator: (init_declarator
declarator: (identifier)
@ -138,9 +179,9 @@ short g, h;
declarator: (identifier)
declarator: (identifier)))
============================================
================================================================================
Variable storage classes
============================================
================================================================================
int a;
extern int b, c;
@ -148,28 +189,44 @@ auto int d;
register int e;
static int f;
---
--------------------------------------------------------------------------------
(translation_unit
(declaration (primitive_type) (identifier))
(declaration (storage_class_specifier) (primitive_type) (identifier) (identifier))
(declaration (storage_class_specifier) (primitive_type) (identifier))
(declaration (storage_class_specifier) (primitive_type) (identifier))
(declaration (storage_class_specifier) (primitive_type) (identifier)))
(declaration
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier)))
============================================
================================================================================
Composite-typed variable declarations
============================================
================================================================================
struct b c;
union { int e; } f;
enum { g, h } i;
---
--------------------------------------------------------------------------------
(translation_unit
(declaration
type: (struct_specifier name: (type_identifier))
type: (struct_specifier
name: (type_identifier))
declarator: (identifier))
(declaration
type: (union_specifier
@ -179,20 +236,23 @@ enum { g, h } i;
declarator: (field_identifier))))
declarator: (identifier))
(declaration
type: (enum_specifier body: (enumerator_list
(enumerator name: (identifier))
(enumerator name: (identifier))))
type: (enum_specifier
body: (enumerator_list
(enumerator
name: (identifier))
(enumerator
name: (identifier))))
declarator: (identifier)))
============================================
================================================================================
Pointer variable declarations
============================================
================================================================================
char *the_string;
const char **the_strings;
int const * const restrict x;
---
--------------------------------------------------------------------------------
(translation_unit
(declaration
@ -213,9 +273,9 @@ int const * const restrict x;
(type_qualifier)
declarator: (identifier))))
============================================
================================================================================
Typedefs
============================================
================================================================================
typedef int my_int;
@ -229,7 +289,32 @@ typedef struct A {
int i;
} a, b;
---
typedef void const *voidpc;
typedef void volatile *voidpv;
typedef void const volatile *const voidpcv;
typedef unsigned long int;
typedef unsigned short ptrdiff_t;
typedef short charptr_t;
typedef unsigned nullptr_t;
typedef signed max_align_t;
typedef unsigned long ulong_t;
typedef long long_t;
typedef unsigned short ushort_t;
typedef short short_t;
typedef unsigned unsigned_t;
typedef signed signed_t;
typedef long long;
typedef short short;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned unsigned short;
typedef signed signed short;
typedef signed signed unsigned;
--------------------------------------------------------------------------------
(translation_unit
(type_definition
@ -261,17 +346,89 @@ typedef struct A {
type: (primitive_type)
declarator: (field_identifier))))
declarator: (type_identifier)
declarator: (type_identifier)))
declarator: (type_identifier))
(type_definition
type: (primitive_type)
(type_qualifier)
declarator: (pointer_declarator
declarator: (type_identifier)))
(type_definition
type: (primitive_type)
(type_qualifier)
declarator: (pointer_declarator
declarator: (type_identifier)))
(type_definition
type: (primitive_type)
(type_qualifier)
(type_qualifier)
declarator: (pointer_declarator
(type_qualifier)
declarator: (type_identifier)))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier
type: (primitive_type))
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type)))
============================================
================================================================================
Function declarations
============================================
================================================================================
int main(int argc, const char **argv);
static foo bar();
static baz quux(...);
---
--------------------------------------------------------------------------------
(translation_unit
(declaration
@ -285,27 +442,32 @@ static baz quux(...);
(parameter_declaration
(type_qualifier)
(primitive_type)
(pointer_declarator (pointer_declarator (identifier)))))))
(pointer_declarator
(pointer_declarator
(identifier)))))))
(declaration
(storage_class_specifier)
(type_identifier)
(function_declarator (identifier) (parameter_list)))
(function_declarator
(identifier)
(parameter_list)))
(declaration
(storage_class_specifier)
(type_identifier)
(function_declarator (identifier) (parameter_list (variadic_parameter)))))
(function_declarator
(identifier)
(parameter_list
(variadic_parameter)))))
============================================
================================================================================
Function definitions
============================================
================================================================================
void * do_stuff(int arg1) {
return 5;
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
@ -318,17 +480,18 @@ void * do_stuff(int arg1) {
type: (primitive_type)
declarator: (identifier)))))
body: (compound_statement
(return_statement (number_literal)))))
(return_statement
(number_literal)))))
============================================
================================================================================
Function specifiers after types
============================================
================================================================================
int static inline do_stuff(int arg1) {
return 5;
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
@ -337,12 +500,17 @@ int static inline do_stuff(int arg1) {
(storage_class_specifier)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (primitive_type) (identifier))))
(compound_statement (return_statement (number_literal)))))
(parameter_list
(parameter_declaration
(primitive_type)
(identifier))))
(compound_statement
(return_statement
(number_literal)))))
============================================
================================================================================
Linkage specifications
============================================
================================================================================
extern "C" int foo();
@ -353,77 +521,121 @@ extern "C" {
int baz();
}
---
--------------------------------------------------------------------------------
(translation_unit
(linkage_specification
(string_literal)
(string_literal
(string_content))
(declaration
(primitive_type)
(function_declarator (identifier) (parameter_list))))
(function_declarator
(identifier)
(parameter_list))))
(linkage_specification
(string_literal)
(string_literal
(string_content))
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(compound_statement (return_statement (number_literal)))))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(return_statement
(number_literal)))))
(linkage_specification
(string_literal)
(string_literal
(string_content))
(declaration_list
(declaration
(primitive_type)
(function_declarator (identifier) (parameter_list)))
(function_declarator
(identifier)
(parameter_list)))
(declaration
(primitive_type)
(function_declarator (identifier) (parameter_list))))))
(function_declarator
(identifier)
(parameter_list))))))
==========================
================================================================================
Type qualifiers
==========================
================================================================================
const _Atomic unsigned long int x = 5;
restrict int y = 6;
volatile int z = 7;
constexpr int a = 8;
noreturn void b() {}
---
--------------------------------------------------------------------------------
(translation_unit
(declaration
(type_qualifier)
(type_qualifier)
(sized_type_specifier (primitive_type))
(init_declarator (identifier) (number_literal)))
(sized_type_specifier
(primitive_type))
(init_declarator
(identifier)
(number_literal)))
(declaration
(type_qualifier)
(primitive_type)
(init_declarator (identifier) (number_literal)))
(init_declarator
(identifier)
(number_literal)))
(declaration
(type_qualifier)
(primitive_type)
(init_declarator (identifier) (number_literal))))
(init_declarator
(identifier)
(number_literal)))
(declaration
(type_qualifier)
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(function_definition
(type_qualifier)
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement)))
================================
================================================================================
Local array declarations
================================
================================================================================
int main() {
char the_buffer[the_size];
char the_other_buffer[*];
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(declaration (primitive_type) (array_declarator (identifier) (identifier)))
(declaration (primitive_type) (array_declarator (identifier))))))
(declaration
(primitive_type)
(array_declarator
(identifier)
(identifier)))
(declaration
(primitive_type)
(array_declarator
(identifier))))))
================================
================================================================================
Attributes
================================
================================================================================
extern __attribute__((visibility("hidden"))) int foo();
extern int bar() __attribute__((const));
@ -452,7 +664,23 @@ struct S {
typedef int MyInt [[deprecated]];
---
struct X {
int a __attribute__((aligned(4)));
} __attribute__((aligned(16)));
union Y {
int a __attribute__((aligned(4)));
} __attribute__((aligned(16)));
enum Z {
A
} __attribute__((aligned(16)));
struct __attribute__((__packed__)) foo_t {
int x;
};
--------------------------------------------------------------------------------
(translation_unit
(declaration
@ -460,71 +688,218 @@ typedef int MyInt [[deprecated]];
(attribute_specifier
(argument_list
(call_expression
(identifier) (argument_list (string_literal)))))
(identifier)
(argument_list
(string_literal
(string_content))))))
(primitive_type)
(function_declarator (identifier) (parameter_list)))
(function_declarator
(identifier)
(parameter_list)))
(declaration
(storage_class_specifier)
(primitive_type)
(function_declarator (identifier) (parameter_list) (attribute_specifier (argument_list (identifier)))))
(function_declarator
(identifier)
(parameter_list)
(attribute_specifier
(argument_list
(identifier)))))
(declaration
(primitive_type)
(function_declarator (identifier)
(parameter_list (parameter_declaration (type_qualifier) (primitive_type) (pointer_declarator (identifier))) (variadic_parameter))
(attribute_specifier (argument_list (identifier)))
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(type_qualifier)
(primitive_type)
(pointer_declarator
(identifier)))
(variadic_parameter))
(attribute_specifier
(argument_list (call_expression (identifier) (argument_list (identifier) (number_literal) (number_literal)))))))
(argument_list
(identifier)))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(identifier)
(number_literal)
(number_literal)))))))
(declaration
(storage_class_specifier)
(attribute_specifier
(argument_list (call_expression (identifier) (argument_list (string_literal))) (identifier)))
(primitive_type) (function_declarator (identifier) (parameter_list)))
(function_definition (primitive_type)
(function_declarator (identifier) (parameter_list (parameter_declaration
(attribute_declaration
(attribute (identifier) (identifier) (argument_list (identifier)))
(attribute (identifier)))
(primitive_type) (identifier)))) (compound_statement))
(declaration
(attribute_declaration (attribute (identifier) (identifier)))
(attribute_declaration (attribute (identifier) (identifier)))
(attribute_declaration (attribute (identifier) (identifier)))
(attribute_declaration (attribute (identifier)))
(argument_list
(call_expression
(identifier)
(argument_list
(string_literal
(string_content))))
(identifier)))
(primitive_type)
(function_declarator
(identifier)
(parameter_list)))
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(attribute_declaration
(attribute
(identifier)
(identifier)
(argument_list
(identifier)))
(attribute
(identifier)))
(primitive_type)
(identifier))))
(compound_statement))
(declaration
(attribute_declaration
(attribute
(identifier)
(identifier)))
(attribute_declaration
(attribute
(identifier)
(identifier)))
(attribute_declaration
(attribute
(identifier)
(identifier)))
(attribute_declaration
(attribute
(identifier)))
(primitive_type)
(function_declarator (identifier) (parameter_list (parameter_declaration (primitive_type)))))
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)))))
(declaration
(attribute_declaration
(attribute (identifier) (identifier))
(attribute (identifier) (identifier))
(attribute (identifier) (identifier))
(attribute (identifier)))
(attribute
(identifier)
(identifier))
(attribute
(identifier)
(identifier))
(attribute
(identifier)
(identifier))
(attribute
(identifier)))
(primitive_type)
(function_declarator (identifier) (parameter_list (parameter_declaration (primitive_type)))))
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)))))
(declaration
(primitive_type)
(attributed_declarator
(identifier)
(attribute_declaration (attribute (identifier)))))
(attribute_declaration
(attribute
(identifier)))))
(declaration
(primitive_type)
(function_declarator
(attributed_declarator
(identifier)
(attribute_declaration (attribute (identifier) (identifier))))
(attribute_declaration
(attribute
(identifier)
(identifier))))
(parameter_list)))
(declaration
(attribute_declaration (attribute (identifier) (argument_list (string_literal))))
(primitive_type) (identifier))
(attribute_declaration
(attribute
(identifier)
(argument_list
(string_literal
(string_content)))))
(primitive_type)
(identifier))
(attributed_statement
(attribute_declaration (attribute (identifier)))
(attribute_declaration
(attribute
(identifier)))
(expression_statement))
(struct_specifier
(type_identifier)
(field_declaration_list (field_declaration (primitive_type)
(attributed_declarator
(field_identifier)
(attribute_declaration (attribute (identifier)))))))
(type_definition (primitive_type)
(field_declaration_list
(field_declaration
(primitive_type)
(attributed_declarator
(field_identifier)
(attribute_declaration
(attribute
(identifier)))))))
(type_definition
(primitive_type)
(attributed_declarator
(type_identifier)
(attribute_declaration (attribute (identifier))))))
(attribute_declaration
(attribute
(identifier)))))
(struct_specifier
(type_identifier)
(field_declaration_list
(field_declaration
(primitive_type)
(field_identifier)
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal)))))))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(union_specifier
(type_identifier)
(field_declaration_list
(field_declaration
(primitive_type)
(field_identifier)
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal)))))))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(enum_specifier
(type_identifier)
(enumerator_list
(enumerator
(identifier)))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(struct_specifier
(attribute_specifier
(argument_list
(identifier)))
(type_identifier)
(field_declaration_list
(field_declaration
(primitive_type)
(field_identifier)))))

File diff suppressed because it is too large Load Diff

@ -1,29 +1,35 @@
============================================
================================================================================
Include directives
============================================
================================================================================
#include "some/path.h"
#include <stdint.h>
#include MACRO
#include MACRO(arg1, arg2)
---
--------------------------------------------------------------------------------
(translation_unit
(preproc_include path: (string_literal))
(preproc_include path: (system_lib_string))
(preproc_include path: (identifier))
(preproc_include path:
(call_expression
(preproc_include
path: (string_literal
(string_content)))
(preproc_include
path: (system_lib_string))
(preproc_include
path: (identifier))
(preproc_include
path: (call_expression
function: (identifier)
arguments: (argument_list (identifier) (identifier)))))
arguments: (argument_list
(identifier)
(identifier)))))
============================================
================================================================================
Object-like macro definitions
============================================
================================================================================
#define ONE
#define TWO int a = b;
#define TWO int a = b;
#define THREE \
c == d ? \
e : \
@ -34,20 +40,43 @@ Object-like macro definitions
#define SIX(a, \
b) x \
+ y
#define SEVEN 7/* seven has an
* annoying comment */
---
--------------------------------------------------------------------------------
(translation_unit
(preproc_def name: (identifier))
(preproc_def name: (identifier) value: (preproc_arg))
(preproc_def name: (identifier) value: (preproc_arg))
(preproc_def name: (identifier) value: (preproc_arg))
(preproc_function_def name: (identifier) parameters: (preproc_params (identifier) (identifier)) value: (preproc_arg))
(preproc_function_def name: (identifier) parameters: (preproc_params (identifier) (identifier)) value: (preproc_arg)))
============================================
(preproc_def
name: (identifier))
(preproc_def
name: (identifier)
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg)
(comment)))
================================================================================
Function-like macro definitions
============================================
================================================================================
#define ONE() a
#define TWO(b) c
@ -55,7 +84,7 @@ Function-like macro definitions
#define FOUR(...) g
#define FIVE(h, i, ...) j
---
--------------------------------------------------------------------------------
(translation_unit
(preproc_function_def
@ -64,11 +93,14 @@ Function-like macro definitions
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params (identifier))
parameters: (preproc_params
(identifier))
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params (identifier) (identifier))
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg))
(preproc_function_def
name: (identifier)
@ -76,12 +108,14 @@ Function-like macro definitions
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params (identifier) (identifier))
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg)))
============================================
================================================================================
Ifdefs
============================================
================================================================================
#ifndef DEFINE1
int j;
@ -103,7 +137,7 @@ int b;
# endif
#endif
---
--------------------------------------------------------------------------------
(translation_unit
(preproc_ifdef
@ -111,7 +145,6 @@ int b;
(declaration
type: (primitive_type)
declarator: (identifier)))
(preproc_ifdef
name: (identifier)
(declaration
@ -121,7 +154,8 @@ int b;
name: (identifier)
value: (preproc_arg))
alternative: (preproc_elif
condition: (preproc_defined (identifier))
condition: (preproc_defined
(identifier))
alternative: (preproc_else
(declaration
type: (primitive_type)
@ -129,7 +163,6 @@ int b;
(preproc_def
name: (identifier)
value: (preproc_arg)))))
(preproc_ifdef
name: (identifier)
alternative: (preproc_else
@ -137,9 +170,55 @@ int b;
name: (identifier)
alternative: (preproc_else)))))
===============================================================
================================================================================
Elifdefs
================================================================================
#ifndef DEFINE1
int j;
#elifndef DEFINE2
int k;
#endif
#ifdef DEFINE2
ssize_t b;
#elifdef DEFINE3
ssize_t c;
#else
int b;
#endif
--------------------------------------------------------------------------------
(translation_unit
(preproc_ifdef
(identifier)
(declaration
(primitive_type)
(identifier))
(preproc_elifdef
(identifier)
(declaration
(primitive_type)
(identifier))))
(preproc_ifdef
(identifier)
(declaration
(primitive_type)
(identifier))
(preproc_elifdef
(identifier)
(declaration
(primitive_type)
(identifier))
(preproc_else
(declaration
(primitive_type)
(identifier))))))
================================================================================
General if blocks
==========================================
================================================================================
#if defined(__GNUC__) && defined(__PIC__)
#define inline inline __attribute__((always_inline))
@ -151,31 +230,36 @@ General if blocks
#include <something>
#endif
---
--------------------------------------------------------------------------------
(translation_unit
(preproc_if
condition: (binary_expression
left: (preproc_defined (identifier))
right: (preproc_defined (identifier)))
left: (preproc_defined
(identifier))
right: (preproc_defined
(identifier)))
(preproc_def
name: (identifier)
value: (preproc_arg))
alternative: (preproc_elif
condition: (preproc_defined (identifier))
condition: (preproc_defined
(identifier))
(preproc_def
name: (identifier))
alternative: (preproc_elif
condition: (unary_expression
argument: (preproc_defined (identifier)))
argument: (preproc_defined
(identifier)))
(preproc_def
name: (identifier))
alternative: (preproc_else
(preproc_include path: (system_lib_string)))))))
(preproc_include
path: (system_lib_string)))))))
============================================
================================================================================
Preprocessor conditionals in functions
============================================
================================================================================
int main() {
#if d
@ -195,33 +279,49 @@ int main() {
#endif
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(preproc_if
(identifier)
(expression_statement (call_expression (identifier) (argument_list (string_literal))))
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))
(preproc_else
(expression_statement (call_expression (identifier) (argument_list (string_literal))))))
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))))
(preproc_if
(identifier)
(return_statement (number_literal))
(return_statement
(number_literal))
(preproc_elif
(identifier)
(return_statement (number_literal))
(return_statement
(number_literal))
(preproc_elif
(identifier)
(return_statement (number_literal))
(return_statement
(number_literal))
(preproc_else
(return_statement (number_literal)))))))))
(return_statement
(number_literal)))))))))
=================================================
================================================================================
Preprocessor conditionals in struct/union bodies
=================================================
================================================================================
struct S {
#ifdef _WIN32
@ -231,30 +331,38 @@ struct S {
#endif
};
---
--------------------------------------------------------------------------------
(translation_unit
(struct_specifier (type_identifier) (field_declaration_list
(preproc_ifdef (identifier)
(field_declaration (type_identifier) (field_identifier))
(preproc_else
(field_declaration (primitive_type) (field_identifier)))))))
(struct_specifier
(type_identifier)
(field_declaration_list
(preproc_ifdef
(identifier)
(field_declaration
(type_identifier)
(field_identifier))
(preproc_else
(field_declaration
(primitive_type)
(field_identifier)))))))
====================================
================================================================================
Unknown preprocessor directives
====================================
================================================================================
#pragma mark - UIViewController
---
--------------------------------------------------------------------------------
(translation_unit (preproc_call
directive: (preproc_directive)
argument: (preproc_arg)))
(translation_unit
(preproc_call
directive: (preproc_directive)
argument: (preproc_arg)))
======================================
================================================================================
Preprocessor expressions
======================================
================================================================================
#if A(B || C) && \
!D(F)
@ -263,12 +371,22 @@ uint32_t a;
#endif
---
--------------------------------------------------------------------------------
(translation_unit
(preproc_if
(binary_expression
(call_expression (identifier) (argument_list (binary_expression (identifier) (identifier))))
(call_expression
(identifier)
(argument_list
(binary_expression
(identifier)
(identifier))))
(unary_expression
(call_expression (identifier) (argument_list (identifier)))))
(declaration (primitive_type) (identifier))))
(call_expression
(identifier)
(argument_list
(identifier)))))
(declaration
(primitive_type)
(identifier))))

@ -1,6 +1,6 @@
============================================
================================================================================
If statements
============================================
================================================================================
int main() {
if (a)
@ -13,24 +13,35 @@ int main() {
}
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(if_statement (parenthesized_expression (identifier))
(expression_statement (number_literal)))
(if_statement (parenthesized_expression (unary_expression (identifier)))
(if_statement
(parenthesized_expression
(identifier))
(expression_statement
(number_literal)))
(if_statement
(parenthesized_expression
(unary_expression
(identifier)))
(compound_statement
(expression_statement (number_literal)))
(compound_statement
(expression_statement (number_literal)))))))
(expression_statement
(number_literal)))
(else_clause
(compound_statement
(expression_statement
(number_literal))))))))
============================================
================================================================================
For loops
============================================
================================================================================
int main() {
for (;;)
@ -47,35 +58,64 @@ int main() {
1;
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(for_statement
(expression_statement (number_literal)))
(expression_statement
(number_literal)))
(for_statement
(declaration (primitive_type) (init_declarator (identifier) (number_literal)))
(binary_expression (identifier) (number_literal))
(declaration
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(binary_expression
(identifier)
(number_literal))
(comma_expression
(call_expression (identifier) (argument_list))
(update_expression (identifier)))
(compound_statement (expression_statement (number_literal))))
(call_expression
(identifier)
(argument_list))
(update_expression
(identifier)))
(compound_statement
(expression_statement
(number_literal))))
(for_statement
(call_expression (identifier) (argument_list))
(call_expression (identifier) (argument_list))
(call_expression (identifier) (argument_list))
(expression_statement (number_literal)))
(call_expression
(identifier)
(argument_list))
(call_expression
(identifier)
(argument_list))
(call_expression
(identifier)
(argument_list))
(expression_statement
(number_literal)))
(for_statement
(comma_expression
(assignment_expression (identifier) (number_literal))
(assignment_expression
(identifier)
(number_literal))
(comma_expression
(assignment_expression (identifier) (number_literal))
(assignment_expression
(identifier)
(number_literal))
(comma_expression
(assignment_expression (identifier) (number_literal))
(assignment_expression (identifier) (number_literal)))))
(assignment_expression
(identifier)
(number_literal))
(assignment_expression
(identifier)
(number_literal)))))
(comma_expression
(binary_expression
(identifier)
@ -84,38 +124,50 @@ int main() {
(identifier)
(number_literal)))
(comma_expression
(update_expression (identifier))
(update_expression
(identifier))
(comma_expression
(update_expression (identifier))
(update_expression
(identifier))
(comma_expression
(update_expression (identifier))
(update_expression (identifier)))))
(expression_statement (number_literal))))))
============================================
(update_expression
(identifier))
(update_expression
(identifier)))))
(expression_statement
(number_literal))))))
================================================================================
While loops
============================================
================================================================================
int main() {
while (x)
printf("hi");
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(while_statement (parenthesized_expression (identifier))
(expression_statement (call_expression
(identifier)
(argument_list (string_literal))))))))
(while_statement
(parenthesized_expression
(identifier))
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))))))
============================================
================================================================================
Labeled statements
============================================
================================================================================
void foo(T *t) {
recur:
@ -123,23 +175,38 @@ recur:
if (t) goto recur;
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list
(parameter_declaration (type_identifier) (pointer_declarator (identifier)))))
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(type_identifier)
(pointer_declarator
(identifier)))))
(compound_statement
(labeled_statement (statement_identifier)
(expression_statement (assignment_expression
(identifier)
(call_expression (field_expression (identifier) (field_identifier)) (argument_list)))))
(if_statement (parenthesized_expression (identifier)) (goto_statement (statement_identifier))))))
============================================
(labeled_statement
(statement_identifier)
(expression_statement
(assignment_expression
(identifier)
(call_expression
(field_expression
(identifier)
(field_identifier))
(argument_list)))))
(if_statement
(parenthesized_expression
(identifier))
(goto_statement
(statement_identifier))))))
================================================================================
Switch statements
============================================
================================================================================
void foo(int a) {
switch (a) {
@ -158,31 +225,51 @@ void foo(int a) {
}
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list
(parameter_declaration (primitive_type) (identifier))))
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)
(identifier))))
(compound_statement
(switch_statement
(parenthesized_expression (identifier))
(parenthesized_expression
(identifier))
(compound_statement
(expression_statement (call_expression (identifier) (argument_list (string_literal))))
(case_statement (number_literal))
(case_statement (number_literal)
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))
(case_statement
(number_literal))
(case_statement
(number_literal)
(if_statement
(parenthesized_expression (identifier))
(compound_statement (expression_statement (call_expression (identifier) (argument_list)))))
(parenthesized_expression
(identifier))
(compound_statement
(expression_statement
(call_expression
(identifier)
(argument_list)))))
(break_statement))
(case_statement
(expression_statement (call_expression (identifier) (argument_list)))
(expression_statement
(call_expression
(identifier)
(argument_list)))
(break_statement)))))))
============================================
================================================================================
Case statements separate from switch statements
============================================
================================================================================
int main() {
switch (count % 8) {
@ -195,35 +282,59 @@ int main() {
}
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(switch_statement
(parenthesized_expression (binary_expression (identifier) (number_literal)))
(parenthesized_expression
(binary_expression
(identifier)
(number_literal)))
(compound_statement
(case_statement (number_literal)
(case_statement
(number_literal)
(do_statement
(compound_statement
(expression_statement (assignment_expression
(pointer_expression (identifier))
(pointer_expression (update_expression (identifier)))))
(case_statement (number_literal)
(expression_statement (assignment_expression
(pointer_expression (identifier))
(pointer_expression (update_expression (identifier))))))
(case_statement (number_literal)
(expression_statement (assignment_expression
(pointer_expression (identifier))
(pointer_expression (update_expression (identifier)))))))
(parenthesized_expression (binary_expression (update_expression (identifier)) (number_literal))))))))))
============================================
(expression_statement
(assignment_expression
(pointer_expression
(identifier))
(pointer_expression
(update_expression
(identifier)))))
(case_statement
(number_literal)
(expression_statement
(assignment_expression
(pointer_expression
(identifier))
(pointer_expression
(update_expression
(identifier))))))
(case_statement
(number_literal)
(expression_statement
(assignment_expression
(pointer_expression
(identifier))
(pointer_expression
(update_expression
(identifier)))))))
(parenthesized_expression
(binary_expression
(update_expression
(identifier))
(number_literal))))))))))
================================================================================
Return statements
============================================
================================================================================
void foo() {
return;
@ -231,20 +342,26 @@ void foo() {
return a, b;
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(return_statement)
(return_statement (identifier))
(return_statement (comma_expression (identifier) (identifier))))))
(return_statement
(identifier))
(return_statement
(comma_expression
(identifier)
(identifier))))))
============================================
================================================================================
Comments with asterisks
============================================
================================================================================
/*************************
* odd number of asterisks
@ -256,17 +373,38 @@ int a;
**************************/
int b;
---
--------------------------------------------------------------------------------
(translation_unit
(comment)
(declaration (primitive_type) (identifier))
(declaration
(primitive_type)
(identifier))
(comment)
(declaration (primitive_type) (identifier)))
(declaration
(primitive_type)
(identifier)))
================================================================================
Comment with multiple backslashes
================================================================================
int a = 3; // Hello \\
World
============================================
--------------------------------------------------------------------------------
(translation_unit
(declaration
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(comment))
================================================================================
Attributes
============================================
================================================================================
void f() {
[[a]] switch (b) {
@ -289,38 +427,109 @@ void f() {
do [[likely]] {} while (true);
}
---
--------------------------------------------------------------------------------
(translation_unit
(function_definition (primitive_type)
(function_declarator (identifier) (parameter_list))
(compound_statement
(attributed_statement
(attribute_declaration (attribute (identifier)))
(switch_statement
(parenthesized_expression (identifier))
(compound_statement
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(switch_statement
(parenthesized_expression
(identifier))
(compound_statement
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(case_statement
(number_literal)
(compound_statement)))
(case_statement
(number_literal)
(attributed_statement
(attribute_declaration (attribute (identifier)))
(case_statement (number_literal) (compound_statement)))
(case_statement (number_literal)
(attributed_statement
(attribute_declaration (attribute (identifier)))
(expression_statement)))
(case_statement))))
(attributed_statement (attribute_declaration (attribute (identifier))) (while_statement (parenthesized_expression (true)) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (if_statement (parenthesized_expression (true)) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (for_statement (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (return_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (expression_statement (identifier)))
(attributed_statement (attribute_declaration (attribute (identifier))) (expression_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (labeled_statement (statement_identifier) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (goto_statement (statement_identifier)))
(comment)
(attribute_declaration
(attribute
(identifier)))
(expression_statement)))
(case_statement))))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(while_statement
(parenthesized_expression
(true))
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(if_statement
(parenthesized_expression (true))
(attributed_statement (attribute_declaration (attribute (identifier))) (compound_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (compound_statement)))
(do_statement
(attributed_statement (attribute_declaration (attribute (identifier))) (compound_statement))
(parenthesized_expression (true))))))
(parenthesized_expression
(true))
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(for_statement
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(return_statement))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(expression_statement
(identifier)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(expression_statement))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(labeled_statement
(statement_identifier)
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(goto_statement
(statement_identifier)))
(comment)
(if_statement
(parenthesized_expression
(true))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(compound_statement))
(else_clause
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(compound_statement))))
(do_statement
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(compound_statement))
(parenthesized_expression
(true))))))