Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Reland "Revert "feat: Parse struct constructor initializer list using clang CLI"" #21

Merged
merged 10 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ jobs:
registry-url: "https://npm.pkg.github.com"
# Defaults to the user or organization that owns the workflow file
scope: "@agoraio-extensions"

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
version: "15.0.6"
- name: Run unit test
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export LLVM_DOWNLOAD_URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.6/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.xz

npm install
npm run test:integration
58 changes: 55 additions & 3 deletions cxx-parser/__integration_test__/cxx_parser.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import path from 'path';

import { TerraContext } from '@agoraio-extensions/terra-core';

import { dumpCXXAstJson } from '../src/cxx_parser';
import { CXXParser, dumpCXXAstJson } from '../src/cxx_parser';
import { CXXFile, Struct } from '../src/cxx_terra_node';

describe('cxx_parser', () => {
let tmpDir: string = '';
Expand All @@ -27,8 +28,8 @@ describe('cxx_parser', () => {
file1Path,
`
struct AAA {
int a;
}
int a;
};
`
);

Expand Down Expand Up @@ -85,4 +86,55 @@ struct AAA {
expect(JSON.parse(json)).toEqual(JSON.parse(expectedJson));
});
});

describe('CXXParser', () => {
it('parse Struct with constructor initializer list', () => {
let file1Name = 'file1.h';
let file1Path = path.join(tmpDir, file1Name);

fs.writeFileSync(
file1Path,
`
#pragma once

namespace ns1 {
struct AAA {
int aaa_;

AAA(): aaa_(0) {}
AAA(int aaa): aaa_(aaa) {}
};
}
`
);

let args = {
includeHeaderDirs: [],
definesMacros: [],
parseFiles: { include: [file1Name] },
customHeaders: [],
};

let parseResult = CXXParser(
new TerraContext(tmpDir, tmpDir),
args,
undefined
)!;

let s = (parseResult.nodes[0] as CXXFile).nodes[0] as Struct;
expect(s.constructors.length).toBe(2);

expect(s.constructors[0].initializerList.length).toBe(1);
expect(s.constructors[0].initializerList[0].kind).toEqual('Value');
expect(s.constructors[0].initializerList[0].name).toEqual('aaa_');
expect(s.constructors[0].initializerList[0].type).toEqual('int');
expect(s.constructors[0].initializerList[0].values).toEqual(['0']);

expect(s.constructors[1].initializerList.length).toBe(1);
expect(s.constructors[1].initializerList[0].kind).toEqual('Parameter');
expect(s.constructors[1].initializerList[0].name).toEqual('aaa_');
expect(s.constructors[1].initializerList[0].type).toEqual('int');
expect(s.constructors[1].initializerList[0].values).toEqual(['aaa']);
});
});
});
Loading