Skip to content

Commit

Permalink
Codecleanup type to kind (#48)
Browse files Browse the repository at this point in the history
* Reserve the word type for value types, move ast types to be called kind.

* simplify GetType to Type

* run clang-format

* fix arm64 crossbuild  by downgrading libedit b\c latest libedit has a GCC_VERS=13 dep. libstdc++-13-dev-arm64-cross  isn't available to ubuntu 22.04 apt. Second fix was for linux. need to explicitly set stdint.h.

* fix Freebsd cross build fix clang format.

* set macos version to 13
  • Loading branch information
farzonl authored Dec 6, 2023
1 parent dbacb1e commit 111bb4d
Show file tree
Hide file tree
Showing 48 changed files with 813 additions and 790 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
&& mkdir tmp \
&& cd tmp \
&& export LIBEDIT_URL="http://ports.ubuntu.com/ubuntu-ports/pool/main/libe/libedit/" \
&& curl $LIBEDIT_URL 2>&1 | grep -oh "\"libedit-dev.*arm64.deb\"" | sort -nr | head -n1 | xargs -I% wget $LIBEDIT_URL/% \
&& curl $LIBEDIT_URL 2>&1 | grep -oh "\"libedit-dev_3.1-2022.*arm64.deb\"" | sort -nr | head -n1 | xargs -I% wget $LIBEDIT_URL/% \
&& dpkg-deb -R libedit-dev*arm64.deb . \
&& rm -rf usr/share libedit-dev*arm64.deb DEBIAN \
&& export LIBBSD_URL=http://ports.ubuntu.com/ubuntu-ports/pool/main/libb/libbsd/ \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cmake-freeBSD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
TARGET_TRIPLE: x86_64-unknown-freebsd13.1
TARGET_TRIPLE: x86_64-unknown-freebsd13.2

jobs:

Expand All @@ -36,7 +36,7 @@ jobs:
ca-certificates vim xz-utils libc++-dev libc++abi-dev
- name: setup sysroot
run: |
cd /tmp && wget http://ftp.plusline.de/FreeBSD/releases/amd64/13.1-RELEASE/base.txz \
cd /tmp && wget http://ftp.plusline.de/FreeBSD/releases/amd64/13.2-RELEASE/base.txz \
&& mkdir -p /opt/cross-freebsd-13 \
&& cd /opt/cross-freebsd-13 \
&& tar -xf /tmp/base.txz ./lib/ ./usr/lib/ ./usr/include/ \
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/cmake-libfuzzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ jobs:
matrix:
# Note using windows-2019 b\c of weird compile error when vs2022 is installed
# https://github.com/llvm/llvm-project/issues/56300
os: [ubuntu-latest, macos-latest, windows-2019]
os: [ubuntu-latest, macos-13, windows-2019]
include:
- os: windows-2019
artifact_exec_ext: .exe
artifact_os_name: Windows
artifact_arch: x86_64
- os: macos-13
xcode: Xcode_15.0.1
steps:
- uses: actions/checkout@v2
- name: Install Dependencies (Linux)
Expand All @@ -42,7 +44,7 @@ jobs:
sudo apt install build-essential cmake \
ca-certificates llvm clang libedit-dev ninja-build
- name: Install Dependencies (Mac)
if: matrix.os == 'macOS-latest'
if: matrix.os == 'macOS-13'
run: |
brew install llvm ninja
- name: Install Dependencies (Windows)
Expand All @@ -64,10 +66,16 @@ jobs:
restore-keys: |
${{ runner.OS }}-c++-packages-cache-libfuzzer-Release-
- name: set Xcode and MacOS sdk Version
if: matrix.os == 'macOS-13'
run: |
sudo xcode-select --switch /Applications/${{ matrix.xcode }}.app/Contents/Developer
xcrun --show-sdk-version
- name: Configure CMake (Mac)
shell: bash
working-directory: ${{github.workspace}}/build
if: matrix.os == 'macOS-latest'
if: matrix.os == 'macOS-13'
# Mac needs brew's llvm to override AppleClang
run: |
export PATH="/usr/local/opt/llvm/bin:$PATH"
Expand All @@ -79,7 +87,7 @@ jobs:
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
if: matrix.os != 'macOS-latest'
if: matrix.os != 'macOS-13'
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
Expand All @@ -93,7 +101,7 @@ jobs:
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
- name: Set variables (Mac\Linux)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-13'
run: |
APP=$(cat $GITHUB_WORKSPACE/src/lib/Version/appName.txt)
VER=$(cat $GITHUB_WORKSPACE/src/lib/Version/version.txt)
Expand All @@ -109,7 +117,7 @@ jobs:
echo "APPNAME=$APP" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Prepare Binaries for upload (Mac\Linux)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-13'
shell: bash
run: |
mkdir ${{github.workspace}}/artifacts
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN cd \
&& mkdir tmp \
&& cd tmp \
&& export LIBEDIT_URL="http://ports.ubuntu.com/ubuntu-ports/pool/main/libe/libedit/" \
&& curl $LIBEDIT_URL 2>&1 | grep -oh "\"libedit-dev.*arm64.deb\"" | sort -nr | head -n1 | xargs -I% wget $LIBEDIT_URL% \
&& curl $LIBEDIT_URL 2>&1 | grep -oh "\"libedit-dev_3.1-2022.*arm64.deb\"" | sort -nr | head -n1 | xargs -I% wget $LIBEDIT_URL% \
&& dpkg-deb -R libedit-dev*arm64.deb . \
&& rm -rf usr/share libedit-dev*arm64.deb DEBIAN \
&& export LIBBSD_URL="http://ports.ubuntu.com/ubuntu-ports/pool/main/libb/libbsd/" \
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.freebsd-cross
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN mkdir $WORKDIR
#Set the working dir to the env variable
WORKDIR $WORKDIR

RUN cd /tmp && wget http://ftp.plusline.de/FreeBSD/releases/amd64/13.1-RELEASE/base.txz \
RUN cd /tmp && wget http://ftp.plusline.de/FreeBSD/releases/amd64/13.2-RELEASE/base.txz \
&& mkdir -p /opt/cross-freebsd-13 \
&& cd /opt/cross-freebsd-13 \
&& tar -xf /tmp/base.txz ./lib/ ./usr/lib/ ./usr/include/ \
Expand All @@ -31,7 +31,7 @@ COPY scripts scripts
COPY cli-test-cases cli-test-cases
COPY src src

ENV TARGET_TRIPLE=x86_64-unknown-freebsd13.1
ENV TARGET_TRIPLE=x86_64-unknown-freebsd13.2
RUN cmake -S . -B build \
-GNinja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
Expand Down
21 changes: 10 additions & 11 deletions src/lib/Binding/Binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Binder::BindExpression(ExpressionNode *node) {
return std::move(BindIdentifierExpression(identifierExpression));
}
std::stringstream diagmsg;
diagmsg << "Unexpected syntax " << SyntaxTokenToStrMap.at(node->Type());
diagmsg << "Unexpected syntax " << SyntaxTokenToStrMap.at(node->Kind());
throw std::runtime_error(diagmsg.str());
return nullptr;
}
Expand All @@ -62,11 +62,10 @@ std::unique_ptr<BoundExpressionNode>
Binder::BindUnaryExpression(UnaryExpressionNode *unary) {
auto boundOperand = BindExpression(unary->Operand());
const std::shared_ptr<BoundUnaryOperator> boundOperator =
BoundUnaryOperator::Bind(unary->Operator()->Type(),
boundOperand->GetType());
BoundUnaryOperator::Bind(unary->Operator()->Kind(), boundOperand->Type());
if (boundOperator == BoundUnaryOperator::GetBindFailure()) {
mRecords.ReportUndefinedUnaryOperator(unary->Operator(),
boundOperand->GetType());
boundOperand->Type());
return boundOperand;
}
return std::make_unique<BoundUnaryExpressionNode>(boundOperator,
Expand All @@ -78,11 +77,11 @@ Binder::BindBinaryExpression(BinaryExpressionNode *binary) {
auto boundLeft = BindExpression(binary->Left());
auto boundRight = BindExpression(binary->Right());
const std::shared_ptr<BoundBinaryOperator> boundOperator =
BoundBinaryOperator::Bind(binary->Operator()->Type(),
boundLeft->GetType(), boundRight->GetType());
BoundBinaryOperator::Bind(binary->Operator()->Kind(), boundLeft->Type(),
boundRight->Type());
if (boundOperator == BoundBinaryOperator::GetBindFailure()) {
mRecords.ReportUndefinedBinaryOperator(
binary->Operator(), boundLeft->GetType(), boundRight->GetType());
binary->Operator(), boundLeft->Type(), boundRight->Type());
return boundLeft;
}
return std::make_unique<BoundBinaryExpressionNode>(
Expand All @@ -94,11 +93,11 @@ Binder::BindAssignmentExpression(AssignmentExpressionNode *assignment) {
std::string name = assignment->IdentifierToken()->Text();
auto boundExpression = BindExpression(assignment->Expression());
const std::shared_ptr<BoundAssignmentOperator> boundOperator =
BoundAssignmentOperator::Bind(assignment->AssignmentToken()->Type(),
boundExpression->GetType());
if (assignment->AssignmentToken()->Type() == SyntaxType::EqualsToken) {
BoundAssignmentOperator::Bind(assignment->AssignmentToken()->Kind(),
boundExpression->Type());
if (assignment->AssignmentToken()->Kind() == SyntaxKind::EqualsToken) {
auto newVar =
std::make_shared<VariableSymbol>(name, boundExpression->GetType());
std::make_shared<VariableSymbol>(name, boundExpression->Type());
auto existingVariable = SymbolTableMgr::find(name);
if (existingVariable != VariableSymbol::failSymbol()) {
SymbolTableMgr::modify(newVar, existingVariable->GetScopeName());
Expand Down
107 changes: 55 additions & 52 deletions src/lib/Binding/BoundAssignmentExpressionNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,92 @@

const std::shared_ptr<BoundAssignmentOperator>
BoundAssignmentOperator::sOperators[] = {
std::make_shared<BoundAssignmentOperator>(SyntaxType::EqualsToken,
Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxType::EqualsToken,
Type::Boolean),
std::make_shared<BoundAssignmentOperator>(SyntaxType::PlusEqualsToken,
Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxType::MinusEqualsToken,
Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxType::StarEqualsToken,
Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxType::SlashEqualsToken,
Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::EqualsToken,
Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::EqualsToken,
Value::Type::Boolean),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::PlusEqualsToken,
Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::MinusEqualsToken,
Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::StarEqualsToken,
Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::SlashEqualsToken,
Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(
SyntaxType::AmpersandEqualsToken, Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxType::PipeEqualsToken,
Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxType::HatEqualsToken,
Type::Number),
SyntaxKind::AmpersandEqualsToken, Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::PipeEqualsToken,
Value::Type::Number),
std::make_shared<BoundAssignmentOperator>(SyntaxKind::HatEqualsToken,
Value::Type::Number),
};

const std::shared_ptr<BoundAssignmentOperator>
BoundAssignmentOperator::Bind(SyntaxType syntaxType, Type rhsOperandType) {
BoundAssignmentOperator::Bind(SyntaxKind syntaxKind,
Value::Type rhsOperandType) {
for (std::shared_ptr<BoundAssignmentOperator> op :
BoundAssignmentOperator::sOperators) {
if (op->GetSyntaxType() == syntaxType &&
if (op->GetSyntaxKind() == syntaxKind &&
op->RightHandExpressionType() == rhsOperandType) {
return op;
}
}
throw std::runtime_error("Failed to Bind AssignmentExpression");
}

BoundAssignmentOperatorType BoundAssignmentOperator::AssignmentType() {
return mAssigmentType;
BoundAssignmentOperatorKind BoundAssignmentOperator::AssignmentKind() {
return mAssigmentKind;
}

void BoundAssignmentOperator::setOperatorType() {
switch (mSyntaxType.GetValue()) {
case SyntaxType::EqualsToken:
mAssigmentType = BoundAssignmentOperatorType::Assignment;
void BoundAssignmentOperator::setOperatorKind() {
switch (mSyntaxKind.GetValue()) {
case SyntaxKind::EqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::Assignment;
break;
case SyntaxType::PlusEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::AddAndAssign;
case SyntaxKind::PlusEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::AddAndAssign;
break;
case SyntaxType::MinusEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::SubtractAndAssign;
case SyntaxKind::MinusEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::SubtractAndAssign;
break;
case SyntaxType::StarEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::MultiplyAndAssign;
case SyntaxKind::StarEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::MultiplyAndAssign;
break;
case SyntaxType::SlashEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::DivideAndAssign;
case SyntaxKind::SlashEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::DivideAndAssign;
break;
case SyntaxType::AmpersandEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::BitwiseAndAndAssign;
case SyntaxKind::AmpersandEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::BitwiseAndAndAssign;
break;
case SyntaxType::PipeEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::BitwiseOrAndAssign;
case SyntaxKind::PipeEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::BitwiseOrAndAssign;
break;
case SyntaxType::HatEqualsToken:
mAssigmentType = BoundAssignmentOperatorType::BitwiseXorAndAssign;
case SyntaxKind::HatEqualsToken:
mAssigmentKind = BoundAssignmentOperatorKind::BitwiseXorAndAssign;
break;
default:
throw std::runtime_error(
"Unexpected SyntaxType seen while processing a BoundAssignment");
"Unexpected SyntaxKind seen while processing a BoundAssignment");
}
}

BoundAssignmentOperator::BoundAssignmentOperator(SyntaxType syntaxType,
Type rhsOperandType)
: mSyntaxType(syntaxType), mRhsType(rhsOperandType) {
setOperatorType();
BoundAssignmentOperator::BoundAssignmentOperator(SyntaxKind syntaxKind,
Value::Type rhsOperandType)
: mSyntaxKind(syntaxKind), mRhsType(rhsOperandType) {
setOperatorKind();
}

SyntaxType BoundAssignmentOperator::GetSyntaxType() { return mSyntaxType; }
Type BoundAssignmentOperator::RightHandExpressionType() { return mRhsType; }
SyntaxKind BoundAssignmentOperator::GetSyntaxKind() { return mSyntaxKind; }
Value::Type BoundAssignmentOperator::RightHandExpressionType() {
return mRhsType;
}

BoundNodeType BoundAssignmentExpressionNode::NodeType() {
return BoundNodeType::AssignmentExpression;
BoundNodeKind BoundAssignmentExpressionNode::NodeKind() {
return BoundNodeKind::AssignmentExpression;
}

Type BoundAssignmentExpressionNode::GetType() {
return mBoundExpression->GetType();
Value::Type BoundAssignmentExpressionNode::Type() {
return mBoundExpression->Type();
}

BoundExpressionNode *BoundAssignmentExpressionNode::BoundExpression() {
Expand All @@ -102,8 +105,8 @@ std::shared_ptr<VariableSymbol> BoundAssignmentExpressionNode::Variable() {
return mVariable;
}

BoundAssignmentOperatorType BoundAssignmentExpressionNode::OperatorType() {
return mAssignmentOperator->AssignmentType();
BoundAssignmentOperatorKind BoundAssignmentExpressionNode::OperatorKind() {
return mAssignmentOperator->AssignmentKind();
}

BoundAssignmentExpressionNode::BoundAssignmentExpressionNode(
Expand Down
26 changes: 13 additions & 13 deletions src/lib/Binding/BoundAssignmentExpressionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "BoundExpressionNode.h"
#include "Symbol/VariableSymbol.h"

enum class BoundAssignmentOperatorType {
enum class BoundAssignmentOperatorKind {
Assignment,
AddAndAssign,
SubtractAndAssign,
Expand All @@ -25,19 +25,19 @@ enum class BoundAssignmentOperatorType {
class BoundAssignmentOperator {
public:
static const std::shared_ptr<BoundAssignmentOperator>
Bind(SyntaxType syntaxType, Type OperandType);
SyntaxType GetSyntaxType();
Type RightHandExpressionType();
BoundAssignmentOperatorType AssignmentType();
BoundAssignmentOperator(SyntaxType syntaxType, Type rhsOperandType);
Bind(SyntaxKind syntaxKind, Value::Type OperandType);
SyntaxKind GetSyntaxKind();
Value::Type RightHandExpressionType();
BoundAssignmentOperatorKind AssignmentKind();
BoundAssignmentOperator(SyntaxKind syntaxKind, Value::Type rhsOperandType);

private:
SyntaxType mSyntaxType;
Type mRhsType;
BoundAssignmentOperatorType mAssigmentType;
SyntaxKind mSyntaxKind;
Value::Type mRhsType;
BoundAssignmentOperatorKind mAssigmentKind;
static const std::shared_ptr<BoundAssignmentOperator> sOperators[];
BoundAssignmentOperator() = delete;
void setOperatorType();
void setOperatorKind();
friend class BoundAssignmentExpressionNode;
};
class BoundAssignmentExpressionNode : public BoundExpressionNode {
Expand All @@ -47,12 +47,12 @@ class BoundAssignmentExpressionNode : public BoundExpressionNode {
std::unique_ptr<BoundExpressionNode> boundExpression,
std::shared_ptr<BoundAssignmentOperator> assignmentOperator);
virtual ~BoundAssignmentExpressionNode() {}
virtual BoundNodeType NodeType() override;
virtual BoundNodeKind NodeKind() override;
BoundExpressionNode *BoundExpression();
std::string Identifier();
virtual Type GetType() override;
virtual Value::Type Type() override;
std::shared_ptr<VariableSymbol> Variable();
BoundAssignmentOperatorType OperatorType();
BoundAssignmentOperatorKind OperatorKind();

private:
std::unique_ptr<BoundExpressionNode> mBoundExpression;
Expand Down
Loading

0 comments on commit 111bb4d

Please sign in to comment.