From 9b56ec979db7aec70db3623fff7178fe1b5c71db Mon Sep 17 00:00:00 2001 From: Bastien Date: Tue, 5 Jun 2018 22:30:22 +0200 Subject: [PATCH] Add sources --- CMakeLists.txt | 11 + definitions/keywords.def | 34 + definitions/operator_precedence.def | 74 + definitions/symbols.def | 47 + definitions/types.def | 10 + include/GLSL450Lib.h | 213 +++ include/spirv.h | 1304 +++++++++++++++++ src/AST/Declaration.cpp | 17 + src/AST/Declaration.h | 40 + src/AST/Declarations/AssemblerDefinition.cpp | 18 + src/AST/Declarations/AssemblerDefinition.h | 26 + src/AST/Declarations/AttributeDeclaration.cpp | 17 + src/AST/Declarations/AttributeDeclaration.h | 26 + src/AST/Declarations/Class.cpp | 19 + src/AST/Declarations/Class.h | 43 + src/AST/Declarations/EmptyDeclaration.cpp | 17 + src/AST/Declarations/EmptyDeclaration.h | 26 + .../Declarations/ExplicitInstantiation.cpp | 18 + src/AST/Declarations/ExplicitInstantiation.h | 26 + .../Declarations/ExplicitSpecialization.cpp | 18 + src/AST/Declarations/ExplicitSpecialization.h | 26 + src/AST/Declarations/FunctionDefinition.cpp | 22 + src/AST/Declarations/FunctionDefinition.h | 54 + src/AST/Declarations/NamespaceDefinition.cpp | 20 + src/AST/Declarations/NamespaceDefinition.h | 38 + src/AST/Declarations/SimpleDeclaration.cpp | 20 + src/AST/Declarations/SimpleDeclaration.h | 33 + .../Declarations/StaticAssertDeclaration.cpp | 18 + .../Declarations/StaticAssertDeclaration.h | 28 + src/AST/Declarations/Structure.cpp | 19 + src/AST/Declarations/Structure.h | 43 + src/AST/Declarations/TemplateDeclaration.cpp | 18 + src/AST/Declarations/TemplateDeclaration.h | 26 + src/AST/Expression.cpp | 17 + src/AST/Expression.h | 31 + src/AST/Expressions/Arithmetic/Addition.cpp | 20 + src/AST/Expressions/Arithmetic/Addition.h | 20 + src/AST/Expressions/Arithmetic/Division.cpp | 20 + src/AST/Expressions/Arithmetic/Division.h | 20 + src/AST/Expressions/Arithmetic/Modulo.cpp | 20 + src/AST/Expressions/Arithmetic/Modulo.h | 20 + .../Expressions/Arithmetic/Multiplication.cpp | 20 + .../Expressions/Arithmetic/Multiplication.h | 20 + .../Expressions/Arithmetic/Subtraction.cpp | 20 + src/AST/Expressions/Arithmetic/Subtraction.h | 20 + src/AST/Expressions/Arithmetic/UnaryMinus.cpp | 20 + src/AST/Expressions/Arithmetic/UnaryMinus.h | 20 + src/AST/Expressions/Arithmetic/UnaryPlus.cpp | 19 + src/AST/Expressions/Arithmetic/UnaryPlus.h | 20 + .../Assignment/AdditionAssignment.cpp | 20 + .../Assignment/AdditionAssignment.h | 20 + .../Assignment/BasicAssignment.cpp | 20 + .../Expressions/Assignment/BasicAssignment.h | 20 + .../Assignment/DivisionAssignment.cpp | 20 + .../Assignment/DivisionAssignment.h | 20 + .../Assignment/ModuloAssignment.cpp | 20 + .../Expressions/Assignment/ModuloAssignment.h | 20 + .../Assignment/MultiplicationAssignment.cpp | 20 + .../Assignment/MultiplicationAssignment.h | 20 + .../Assignment/SubtractionAssignment.cpp | 20 + .../Assignment/SubtractionAssignment.h | 20 + src/AST/Expressions/Binary.cpp | 19 + src/AST/Expressions/Binary.h | 53 + src/AST/Expressions/Call.cpp | 19 + src/AST/Expressions/Call.h | 31 + src/AST/Expressions/Constant.cpp | 59 + src/AST/Expressions/Constant.h | 54 + src/AST/Expressions/Relational/EqualTo.cpp | 20 + src/AST/Expressions/Relational/EqualTo.h | 20 + .../Expressions/Relational/GreaterThan.cpp | 20 + src/AST/Expressions/Relational/GreaterThan.h | 20 + .../Relational/GreaterThanOrEqualTo.cpp | 20 + .../Relational/GreaterThanOrEqualTo.h | 20 + src/AST/Expressions/Relational/LessThan.cpp | 20 + src/AST/Expressions/Relational/LessThan.h | 20 + .../Relational/LessThanOrEqualTo.cpp | 20 + .../Relational/LessThanOrEqualTo.h | 20 + src/AST/Expressions/Relational/NotEqualTo.cpp | 20 + src/AST/Expressions/Relational/NotEqualTo.h | 20 + src/AST/Expressions/Unary.cpp | 18 + src/AST/Expressions/Unary.h | 33 + src/AST/Expressions/Variable.cpp | 19 + src/AST/Expressions/Variable.h | 30 + src/AST/Statement.cpp | 17 + src/AST/Statement.h | 40 + src/AST/Statements/CompoundStatement.cpp | 18 + src/AST/Statements/CompoundStatement.h | 27 + src/AST/Statements/DeclarationList.cpp | 17 + src/AST/Statements/DeclarationList.h | 29 + src/AST/Statements/ExpressionList.cpp | 17 + src/AST/Statements/ExpressionList.h | 29 + src/AST/Statements/IterationStatement.cpp | 18 + src/AST/Statements/IterationStatement.h | 30 + .../IterationStatements/DoWhile.cpp | 19 + .../Statements/IterationStatements/DoWhile.h | 29 + .../Statements/IterationStatements/For.cpp | 21 + src/AST/Statements/IterationStatements/For.h | 37 + .../Statements/IterationStatements/While.cpp | 19 + .../Statements/IterationStatements/While.h | 29 + src/AST/Statements/JumpStatement.cpp | 18 + src/AST/Statements/JumpStatement.h | 31 + src/AST/Statements/JumpStatements/Return.cpp | 18 + src/AST/Statements/JumpStatements/Return.h | 25 + src/AST/Statements/SelectionStatement.cpp | 18 + src/AST/Statements/SelectionStatement.h | 29 + src/AST/Statements/SelectionStatements/If.cpp | 19 + src/AST/Statements/SelectionStatements/If.h | 29 + src/CMakeLists.txt | 7 + src/Generator.cpp | 1 + src/Generator.h | 4 + src/IR/GLSL/generator.cpp | 553 +++++++ src/IR/GLSL/generator.h | 41 + src/IR/SPIR-V/generator.cpp | 3 + src/IR/SPIR-V/generator.h | 0 src/Lexer.cpp | 570 +++++++ src/Lexer.h | 46 + src/Node.cpp | 1 + src/Node.h | 18 + src/Parser.cpp | 1009 +++++++++++++ src/Parser.h | 199 +++ src/Parser_declarations.cpp | 518 +++++++ src/Parser_statements.cpp | 400 +++++ src/Parser_templates.cpp | 160 ++ src/SL/Endmark.cpp | 19 + src/SL/Endmark.h | 17 + src/SL/Identifier.cpp | 21 + src/SL/Identifier.h | 24 + src/SL/Keyword.cpp | 39 + src/SL/Keyword.h | 36 + src/SL/Number.cpp | 71 + src/SL/Number.h | 61 + src/SL/Separator.cpp | 32 + src/SL/Separator.h | 42 + src/SL/Symbol.cpp | 98 ++ src/SL/Symbol.h | 48 + src/SL/Token.cpp | 1 + src/SL/Token.h | 32 + src/SL/nouveau fichier | 0 src/str.cpp | 71 + src/str.h | 12 + test/CMakeLists.txt | 7 + test/compiler.cpp | 40 + test/compiler_v1.cpp | 341 +++++ 143 files changed, 8636 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 definitions/keywords.def create mode 100644 definitions/operator_precedence.def create mode 100644 definitions/symbols.def create mode 100644 definitions/types.def create mode 100644 include/GLSL450Lib.h create mode 100644 include/spirv.h create mode 100644 src/AST/Declaration.cpp create mode 100644 src/AST/Declaration.h create mode 100644 src/AST/Declarations/AssemblerDefinition.cpp create mode 100644 src/AST/Declarations/AssemblerDefinition.h create mode 100644 src/AST/Declarations/AttributeDeclaration.cpp create mode 100644 src/AST/Declarations/AttributeDeclaration.h create mode 100644 src/AST/Declarations/Class.cpp create mode 100644 src/AST/Declarations/Class.h create mode 100644 src/AST/Declarations/EmptyDeclaration.cpp create mode 100644 src/AST/Declarations/EmptyDeclaration.h create mode 100644 src/AST/Declarations/ExplicitInstantiation.cpp create mode 100644 src/AST/Declarations/ExplicitInstantiation.h create mode 100644 src/AST/Declarations/ExplicitSpecialization.cpp create mode 100644 src/AST/Declarations/ExplicitSpecialization.h create mode 100644 src/AST/Declarations/FunctionDefinition.cpp create mode 100644 src/AST/Declarations/FunctionDefinition.h create mode 100644 src/AST/Declarations/NamespaceDefinition.cpp create mode 100644 src/AST/Declarations/NamespaceDefinition.h create mode 100644 src/AST/Declarations/SimpleDeclaration.cpp create mode 100644 src/AST/Declarations/SimpleDeclaration.h create mode 100644 src/AST/Declarations/StaticAssertDeclaration.cpp create mode 100644 src/AST/Declarations/StaticAssertDeclaration.h create mode 100644 src/AST/Declarations/Structure.cpp create mode 100644 src/AST/Declarations/Structure.h create mode 100644 src/AST/Declarations/TemplateDeclaration.cpp create mode 100644 src/AST/Declarations/TemplateDeclaration.h create mode 100644 src/AST/Expression.cpp create mode 100644 src/AST/Expression.h create mode 100644 src/AST/Expressions/Arithmetic/Addition.cpp create mode 100644 src/AST/Expressions/Arithmetic/Addition.h create mode 100644 src/AST/Expressions/Arithmetic/Division.cpp create mode 100644 src/AST/Expressions/Arithmetic/Division.h create mode 100644 src/AST/Expressions/Arithmetic/Modulo.cpp create mode 100644 src/AST/Expressions/Arithmetic/Modulo.h create mode 100644 src/AST/Expressions/Arithmetic/Multiplication.cpp create mode 100644 src/AST/Expressions/Arithmetic/Multiplication.h create mode 100644 src/AST/Expressions/Arithmetic/Subtraction.cpp create mode 100644 src/AST/Expressions/Arithmetic/Subtraction.h create mode 100644 src/AST/Expressions/Arithmetic/UnaryMinus.cpp create mode 100644 src/AST/Expressions/Arithmetic/UnaryMinus.h create mode 100644 src/AST/Expressions/Arithmetic/UnaryPlus.cpp create mode 100644 src/AST/Expressions/Arithmetic/UnaryPlus.h create mode 100644 src/AST/Expressions/Assignment/AdditionAssignment.cpp create mode 100644 src/AST/Expressions/Assignment/AdditionAssignment.h create mode 100644 src/AST/Expressions/Assignment/BasicAssignment.cpp create mode 100644 src/AST/Expressions/Assignment/BasicAssignment.h create mode 100644 src/AST/Expressions/Assignment/DivisionAssignment.cpp create mode 100644 src/AST/Expressions/Assignment/DivisionAssignment.h create mode 100644 src/AST/Expressions/Assignment/ModuloAssignment.cpp create mode 100644 src/AST/Expressions/Assignment/ModuloAssignment.h create mode 100644 src/AST/Expressions/Assignment/MultiplicationAssignment.cpp create mode 100644 src/AST/Expressions/Assignment/MultiplicationAssignment.h create mode 100644 src/AST/Expressions/Assignment/SubtractionAssignment.cpp create mode 100644 src/AST/Expressions/Assignment/SubtractionAssignment.h create mode 100644 src/AST/Expressions/Binary.cpp create mode 100644 src/AST/Expressions/Binary.h create mode 100644 src/AST/Expressions/Call.cpp create mode 100644 src/AST/Expressions/Call.h create mode 100644 src/AST/Expressions/Constant.cpp create mode 100644 src/AST/Expressions/Constant.h create mode 100644 src/AST/Expressions/Relational/EqualTo.cpp create mode 100644 src/AST/Expressions/Relational/EqualTo.h create mode 100644 src/AST/Expressions/Relational/GreaterThan.cpp create mode 100644 src/AST/Expressions/Relational/GreaterThan.h create mode 100644 src/AST/Expressions/Relational/GreaterThanOrEqualTo.cpp create mode 100644 src/AST/Expressions/Relational/GreaterThanOrEqualTo.h create mode 100644 src/AST/Expressions/Relational/LessThan.cpp create mode 100644 src/AST/Expressions/Relational/LessThan.h create mode 100644 src/AST/Expressions/Relational/LessThanOrEqualTo.cpp create mode 100644 src/AST/Expressions/Relational/LessThanOrEqualTo.h create mode 100644 src/AST/Expressions/Relational/NotEqualTo.cpp create mode 100644 src/AST/Expressions/Relational/NotEqualTo.h create mode 100644 src/AST/Expressions/Unary.cpp create mode 100644 src/AST/Expressions/Unary.h create mode 100644 src/AST/Expressions/Variable.cpp create mode 100644 src/AST/Expressions/Variable.h create mode 100644 src/AST/Statement.cpp create mode 100644 src/AST/Statement.h create mode 100644 src/AST/Statements/CompoundStatement.cpp create mode 100644 src/AST/Statements/CompoundStatement.h create mode 100644 src/AST/Statements/DeclarationList.cpp create mode 100644 src/AST/Statements/DeclarationList.h create mode 100644 src/AST/Statements/ExpressionList.cpp create mode 100644 src/AST/Statements/ExpressionList.h create mode 100644 src/AST/Statements/IterationStatement.cpp create mode 100644 src/AST/Statements/IterationStatement.h create mode 100644 src/AST/Statements/IterationStatements/DoWhile.cpp create mode 100644 src/AST/Statements/IterationStatements/DoWhile.h create mode 100644 src/AST/Statements/IterationStatements/For.cpp create mode 100644 src/AST/Statements/IterationStatements/For.h create mode 100644 src/AST/Statements/IterationStatements/While.cpp create mode 100644 src/AST/Statements/IterationStatements/While.h create mode 100644 src/AST/Statements/JumpStatement.cpp create mode 100644 src/AST/Statements/JumpStatement.h create mode 100644 src/AST/Statements/JumpStatements/Return.cpp create mode 100644 src/AST/Statements/JumpStatements/Return.h create mode 100644 src/AST/Statements/SelectionStatement.cpp create mode 100644 src/AST/Statements/SelectionStatement.h create mode 100644 src/AST/Statements/SelectionStatements/If.cpp create mode 100644 src/AST/Statements/SelectionStatements/If.h create mode 100644 src/CMakeLists.txt create mode 100644 src/Generator.cpp create mode 100644 src/Generator.h create mode 100644 src/IR/GLSL/generator.cpp create mode 100644 src/IR/GLSL/generator.h create mode 100644 src/IR/SPIR-V/generator.cpp create mode 100644 src/IR/SPIR-V/generator.h create mode 100644 src/Lexer.cpp create mode 100644 src/Lexer.h create mode 100644 src/Node.cpp create mode 100644 src/Node.h create mode 100644 src/Parser.cpp create mode 100644 src/Parser.h create mode 100644 src/Parser_declarations.cpp create mode 100644 src/Parser_statements.cpp create mode 100644 src/Parser_templates.cpp create mode 100644 src/SL/Endmark.cpp create mode 100644 src/SL/Endmark.h create mode 100644 src/SL/Identifier.cpp create mode 100644 src/SL/Identifier.h create mode 100644 src/SL/Keyword.cpp create mode 100644 src/SL/Keyword.h create mode 100644 src/SL/Number.cpp create mode 100644 src/SL/Number.h create mode 100644 src/SL/Separator.cpp create mode 100644 src/SL/Separator.h create mode 100644 src/SL/Symbol.cpp create mode 100644 src/SL/Symbol.h create mode 100644 src/SL/Token.cpp create mode 100644 src/SL/Token.h create mode 100644 src/SL/nouveau fichier create mode 100644 src/str.cpp create mode 100644 src/str.h create mode 100644 test/CMakeLists.txt create mode 100644 test/compiler.cpp create mode 100644 test/compiler_v1.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a1ca4c6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +project(SL++) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") + +include_directories(include definitions) + +add_subdirectory(src) +add_subdirectory(test) diff --git a/definitions/keywords.def b/definitions/keywords.def new file mode 100644 index 0000000..3ce3f99 --- /dev/null +++ b/definitions/keywords.def @@ -0,0 +1,34 @@ +DEF("namespace", NAMESPACE) +DEF("struct", STRUCT) +DEF("class", CLASS) +DEF("union", UNION) +DEF("enum", ENUM) + +DEF("break", BREAK) +DEF("continue", CONTINUE) +DEF("return", RETURN) +DEF("goto", GOTO) + +DEF("if", IF) +DEF("else", ELSE) +DEF("switch", SWITCH) + +DEF("for", FOR) +DEF("while", WHILE) +DEF("do", DO) + +DEF("case", CASE) +DEF("default", DEFAULT) + +DEF("try", TRY) +DEF("catch", CATCH) + +DEF("template", TEMPLATE) +DEF("using", USING) + +DEF("static_assert", STATIC_ASSERT) + +DEF("typename", TYPENAME) + +DEF("extern", EXTERN) +DEF("asm", ASM) diff --git a/definitions/operator_precedence.def b/definitions/operator_precedence.def new file mode 100644 index 0000000..8c8aa69 --- /dev/null +++ b/definitions/operator_precedence.def @@ -0,0 +1,74 @@ +/** + * http://en.cppreference.com/w/cpp/language/operator_precedence + */ + +// Prefix increment and decrement +UNARY(PLUS_PLUS, 3) +UNARY(MINUS_MINUS, 3) + +// Unary plus and minus +UNARY(PLUS, 3) +UNARY(MINUS, 3) + +// Logical NOT and bitwise NOT +UNARY(TILDE, 3) +UNARY(EXCLAMATION, 3) + +// Multiplication, division, and remainder +BINARY(ASTERISK, 5) +BINARY(SLASH, 5) +BINARY(PERCENT, 5) + +// Addition and subtraction +BINARY(PLUS, 6) +BINARY(MINUS, 6) + +// Bitwise left shift and right shift +BINARY(LT_LT, 7) +BINARY(GT_GT, 7) + +// For relational operators < and ≤ respectively +BINARY(LT, 8) +BINARY(LT_EQUAL, 8) + +// For relational operators > and ≥ respectively +BINARY(GT, 8) +BINARY(GT_EQUAL, 8) + +// For relational = and ≠ respectively +BINARY(EQUAL_EQUAL, 9) +BINARY(EXCLAMATION_EQUAL, 9) + +// Bitwise AND +BINARY(AMPERSAND, 10) + +// Bitwise XOR (exclusive or) +BINARY(CIRCUMFLEX, 11) + +// Bitwise OR (inclusive or) +BINARY(PIPE, 12) + +// Logical AND +BINARY(AMPERSAND_AMPERSAND, 13) + +// Logical OR +BINARY(PIPE_PIPE, 14) + +// Assignements +BINARY(EQUAL, 15) +BINARY(PLUS_EQUAL, 15) +BINARY(MINUS_EQUAL, 15) +BINARY(ASTERISK_EQUAL, 15) +BINARY(SLASH_EQUAL, 15) +BINARY(PERCENT_EQUAL, 15) +BINARY(LT_LT_EQUAL, 15) +BINARY(GT_GT_EQUAL, 15) +BINARY(AMPERSAND_EQUAL, 15) +BINARY(CIRCUMFLEX_EQUAL, 15) +BINARY(PIPE_EQUAL, 15) + +/** + * New operators + */ + +// ... diff --git a/definitions/symbols.def b/definitions/symbols.def new file mode 100644 index 0000000..c385811 --- /dev/null +++ b/definitions/symbols.def @@ -0,0 +1,47 @@ +// relation operators +DEF("==", EQUAL_EQUAL) +DEF("!=", EXCLAMATION_EQUAL) +DEF("<", LT) +DEF("<=", LT_EQUAL) +DEF(">", GT) +DEF(">=", GT_EQUAL) + +// assignement operators +DEF("=", EQUAL) +DEF("+=", PLUS_EQUAL) +DEF("-=", MINUS_EQUAL) +DEF("*=", ASTERISK_EQUAL) +DEF("/=", SLASH_EQUAL) +DEF("%=", PERCENT_EQUAL) +DEF("<<=", LT_LT_EQUAL) +DEF(">>=", GT_GT_EQUAL) +DEF("&=", AMPERSAND_EQUAL) +DEF("^=", CIRCUMFLEX_EQUAL) +DEF("|=", PIPE_EQUAL) + +// arithmetic operators +DEF("++", PLUS_PLUS) +DEF("--", MINUS_MINUS) +DEF("+", PLUS) +DEF("-", MINUS) +DEF("*", ASTERISK) +DEF("/", SLASH) +DEF("%", PERCENT) + +// bitwise operators +DEF("~", TILDE) +DEF("&", AMPERSAND) +DEF("^", CIRCUMFLEX) +DEF("|", PIPE) +DEF("<<", LT_LT) +DEF(">>", GT_GT) + +// logical operators +DEF("!", EXCLAMATION) +DEF("&&", AMPERSAND_AMPERSAND) +DEF("||", PIPE_PIPE) + + + + + diff --git a/definitions/types.def b/definitions/types.def new file mode 100644 index 0000000..cd4861d --- /dev/null +++ b/definitions/types.def @@ -0,0 +1,10 @@ +DEF("char", CHAR) +DEF("uchar", UCHAR) +DEF("short", SHORT) +DEF("ushort", USHORT) +DEF("int", INT) +DEF("uint", UINT) +DEF("long", LONG) +DEF("ulong", ULONG) +DEF("float", FLOAT) +DEF("double", DOUBLE) diff --git a/include/GLSL450Lib.h b/include/GLSL450Lib.h new file mode 100644 index 0000000..ff030c5 --- /dev/null +++ b/include/GLSL450Lib.h @@ -0,0 +1,213 @@ +/* +** Copyright (c) 2015 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a copy +** of this software and/or associated documentation files (the "Materials"), +** to deal in the Materials without restriction, including without limitation +** the rights to use, copy, modify, merge, publish, distribute, sublicense, +** and/or sell copies of the Materials, and to permit persons to whom the +** Materials are furnished to do so, subject to the following conditions: +** +** The above copyright notice and this permission notice shall be included in +** all copies or substantial portions of the Materials. +** +** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS +** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND +** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/ +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS +** IN THE MATERIALS. +*/ + +// +// Author: John Kessenich, LunarG +// + +namespace GLSL_STD_450 { + +enum Entrypoints { + Round = 0, + RoundEven = 1, + Trunc = 2, + Abs = 3, + Sign = 4, + Floor = 5, + Ceil = 6, + Fract = 7, + + Radians = 8, + Degrees = 9, + Sin = 10, + Cos = 11, + Tan = 12, + Asin = 13, + Acos = 14, + Atan = 15, + Sinh = 16, + Cosh = 17, + Tanh = 18, + Asinh = 19, + Acosh = 20, + Atanh = 21, + Atan2 = 22, + + Pow = 23, + Exp = 24, + Log = 25, + Exp2 = 26, + Log2 = 27, + Sqrt = 28, + InverseSqrt = 29, + + Determinant = 30, + MatrixInverse = 31, + + Modf = 32, // second argument needs the OpVariable = , not an OpLoad + Min = 33, + Max = 34, + Clamp = 35, + Mix = 36, + Step = 37, + SmoothStep = 38, + + FloatBitsToInt = 39, + FloatBitsToUint = 40, + IntBitsToFloat = 41, + UintBitsToFloat = 42, + + Fma = 43, + Frexp = 44, + Ldexp = 45, + + PackSnorm4x8 = 46, + PackUnorm4x8 = 47, + PackSnorm2x16 = 48, + PackUnorm2x16 = 49, + PackHalf2x16 = 50, + PackDouble2x32 = 51, + UnpackSnorm2x16 = 52, + UnpackUnorm2x16 = 53, + UnpackHalf2x16 = 54, + UnpackSnorm4x8 = 55, + UnpackUnorm4x8 = 56, + UnpackDouble2x32 = 57, + + Length = 58, + Distance = 59, + Cross = 60, + Normalize = 61, + Ftransform = 62, + FaceForward = 63, + Reflect = 64, + Refract = 65, + + UaddCarry = 66, + UsubBorrow = 67, + UmulExtended = 68, + ImulExtended = 69, + BitfieldExtract = 70, + BitfieldInsert = 71, + BitfieldReverse = 72, + BitCount = 73, + FindLSB = 74, + FindMSB = 75, + + InterpolateAtCentroid = 76, + InterpolateAtSample = 77, + InterpolateAtOffset = 78, + + Count +}; + +inline void GetDebugNames(const char** names) +{ + for (int i = 0; i < Count; ++i) + names[i] = "Unknown"; + + names[Round] = "round"; + names[RoundEven] = "roundEven"; + names[Trunc] = "trunc"; + names[Abs] = "abs"; + names[Sign] = "sign"; + names[Floor] = "floor"; + names[Ceil] = "ceil"; + names[Fract] = "fract"; + names[Radians] = "radians"; + names[Degrees] = "degrees"; + names[Sin] = "sin"; + names[Cos] = "cos"; + names[Tan] = "tan"; + names[Asin] = "asin"; + names[Acos] = "acos"; + names[Atan] = "atan"; + names[Sinh] = "sinh"; + names[Cosh] = "cosh"; + names[Tanh] = "tanh"; + names[Asinh] = "asinh"; + names[Acosh] = "acosh"; + names[Atanh] = "atanh"; + names[Atan2] = "atan2"; + names[Pow] = "pow"; + names[Exp] = "exp"; + names[Log] = "log"; + names[Exp2] = "exp2"; + names[Log2] = "log2"; + names[Sqrt] = "sqrt"; + names[InverseSqrt] = "inverseSqrt"; + names[Determinant] = "determinant"; + names[MatrixInverse] = "matrixInverse"; + names[Modf] = "modf"; + names[Min] = "min"; + names[Max] = "max"; + names[Clamp] = "clamp"; + names[Mix] = "mix"; + names[Step] = "step"; + names[SmoothStep] = "smoothStep"; + names[FloatBitsToInt] = "floatBitsToInt"; + names[FloatBitsToUint] = "floatBitsToUint"; + names[IntBitsToFloat] = "intBitsToFloat"; + names[UintBitsToFloat] = "uintBitsToFloat"; + names[Fma] = "fma"; + names[Frexp] = "frexp"; + names[Ldexp] = "ldexp"; + names[PackSnorm4x8] = "packSnorm4x8"; + names[PackUnorm4x8] = "packUnorm4x8"; + names[PackSnorm2x16] = "packSnorm2x16"; + names[PackUnorm2x16] = "packUnorm2x16"; + names[PackHalf2x16] = "packHalf2x16"; + names[PackDouble2x32] = "packDouble2x32"; + names[UnpackSnorm2x16] = "unpackSnorm2x16"; + names[UnpackUnorm2x16] = "unpackUnorm2x16"; + names[UnpackHalf2x16] = "unpackHalf2x16"; + names[UnpackSnorm4x8] = "unpackSnorm4x8"; + names[UnpackUnorm4x8] = "unpackUnorm4x8"; + names[UnpackDouble2x32] = "unpackDouble2x32"; + names[Length] = "length"; + names[Distance] = "distance"; + names[Cross] = "cross"; + names[Normalize] = "normalize"; + names[Ftransform] = "ftransform"; + names[FaceForward] = "faceForward"; + names[Reflect] = "reflect"; + names[Refract] = "refract"; + names[UaddCarry] = "uaddCarry"; + names[UsubBorrow] = "usubBorrow"; + names[UmulExtended] = "umulExtended"; + names[ImulExtended] = "imulExtended"; + names[BitfieldExtract] = "bitfieldExtract"; + names[BitfieldInsert] = "bitfieldInsert"; + names[BitfieldReverse] = "bitfieldReverse"; + names[BitCount] = "bitCount"; + names[FindLSB] = "findLSB"; + names[FindMSB] = "findMSB"; + names[InterpolateAtCentroid] = "interpolateAtCentroid"; + names[InterpolateAtSample] = "interpolateAtSample"; + names[InterpolateAtOffset] = "interpolateAtOffset"; +} + +}; // end namespace GLSL_STD_450 diff --git a/include/spirv.h b/include/spirv.h new file mode 100644 index 0000000..dc1e579 --- /dev/null +++ b/include/spirv.h @@ -0,0 +1,1304 @@ +/* +** Copyright (c) 2015 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a copy +** of this software and/or associated documentation files (the "Materials"), +** to deal in the Materials without restriction, including without limitation +** the rights to use, copy, modify, merge, publish, distribute, sublicense, +** and/or sell copies of the Materials, and to permit persons to whom the +** Materials are furnished to do so, subject to the following conditions: +** +** The above copyright notice and this permission notice shall be included in +** all copies or substantial portions of the Materials. +** +** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS +** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND +** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/ +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS +** IN THE MATERIALS. +*/ + +/* +** This header is automatically generated by the same tool that creates +** the Binary Section of the SPIR-V specification. +*/ + +/* +** Specification revision 30. +** Enumeration tokens for SPIR-V, in three styles: C, C++, generic. +** - C++ will have the tokens in the "spv" name space, with no prefix. +** - C will have tokens with as "Spv" prefix. +** +** Some tokens act like mask values, which can be OR'd together, +** while others are mutually exclusive. The mask-like ones have +** "Mask" in their name, and a parallel enum that has the shift +** amount (1 << x) for each corresponding enumerant. +*/ + +#ifndef spirv_H +#define spirv_H + +#ifdef __cplusplus + +namespace spv { + +const int MagicNumber = 0x07230203; +const int Version = 99; + +typedef unsigned int Id; + +const unsigned int OpCodeMask = 0xFFFF; +const unsigned int WordCountShift = 16; + +enum SourceLanguage { + SourceLanguageUnknown = 0, + SourceLanguageESSL = 1, + SourceLanguageGLSL = 2, + SourceLanguageOpenCL = 3, +}; + +enum ExecutionModel { + ExecutionModelVertex = 0, + ExecutionModelTessellationControl = 1, + ExecutionModelTessellationEvaluation = 2, + ExecutionModelGeometry = 3, + ExecutionModelFragment = 4, + ExecutionModelGLCompute = 5, + ExecutionModelKernel = 6, +}; + +enum AddressingModel { + AddressingModelLogical = 0, + AddressingModelPhysical32 = 1, + AddressingModelPhysical64 = 2, +}; + +enum MemoryModel { + MemoryModelSimple = 0, + MemoryModelGLSL450 = 1, + MemoryModelOpenCL12 = 2, + MemoryModelOpenCL20 = 3, + MemoryModelOpenCL21 = 4, +}; + +enum ExecutionMode { + ExecutionModeInvocations = 0, + ExecutionModeSpacingEqual = 1, + ExecutionModeSpacingFractionalEven = 2, + ExecutionModeSpacingFractionalOdd = 3, + ExecutionModeVertexOrderCw = 4, + ExecutionModeVertexOrderCcw = 5, + ExecutionModePixelCenterInteger = 6, + ExecutionModeOriginUpperLeft = 7, + ExecutionModeEarlyFragmentTests = 8, + ExecutionModePointMode = 9, + ExecutionModeXfb = 10, + ExecutionModeDepthReplacing = 11, + ExecutionModeDepthAny = 12, + ExecutionModeDepthGreater = 13, + ExecutionModeDepthLess = 14, + ExecutionModeDepthUnchanged = 15, + ExecutionModeLocalSize = 16, + ExecutionModeLocalSizeHint = 17, + ExecutionModeInputPoints = 18, + ExecutionModeInputLines = 19, + ExecutionModeInputLinesAdjacency = 20, + ExecutionModeInputTriangles = 21, + ExecutionModeInputTrianglesAdjacency = 22, + ExecutionModeInputQuads = 23, + ExecutionModeInputIsolines = 24, + ExecutionModeOutputVertices = 25, + ExecutionModeOutputPoints = 26, + ExecutionModeOutputLineStrip = 27, + ExecutionModeOutputTriangleStrip = 28, + ExecutionModeVecTypeHint = 29, + ExecutionModeContractionOff = 30, +}; + +enum StorageClass { + StorageClassUniformConstant = 0, + StorageClassInput = 1, + StorageClassUniform = 2, + StorageClassOutput = 3, + StorageClassWorkgroupLocal = 4, + StorageClassWorkgroupGlobal = 5, + StorageClassPrivateGlobal = 6, + StorageClassFunction = 7, + StorageClassGeneric = 8, + StorageClassPrivate = 9, + StorageClassAtomicCounter = 10, +}; + +enum Dim { + Dim1D = 0, + Dim2D = 1, + Dim3D = 2, + DimCube = 3, + DimRect = 4, + DimBuffer = 5, +}; + +enum SamplerAddressingMode { + SamplerAddressingModeNone = 0, + SamplerAddressingModeClampToEdge = 1, + SamplerAddressingModeClamp = 2, + SamplerAddressingModeRepeat = 3, + SamplerAddressingModeRepeatMirrored = 4, +}; + +enum SamplerFilterMode { + SamplerFilterModeNearest = 0, + SamplerFilterModeLinear = 1, +}; + +enum FPFastMathModeShift { + FPFastMathModeNotNaNShift = 0, + FPFastMathModeNotInfShift = 1, + FPFastMathModeNSZShift = 2, + FPFastMathModeAllowRecipShift = 3, + FPFastMathModeFastShift = 4, +}; + +enum FPFastMathModeMask { + FPFastMathModeMaskNone = 0, + FPFastMathModeNotNaNMask = 0x00000001, + FPFastMathModeNotInfMask = 0x00000002, + FPFastMathModeNSZMask = 0x00000004, + FPFastMathModeAllowRecipMask = 0x00000008, + FPFastMathModeFastMask = 0x00000010, +}; + +enum FPRoundingMode { + FPRoundingModeRTE = 0, + FPRoundingModeRTZ = 1, + FPRoundingModeRTP = 2, + FPRoundingModeRTN = 3, +}; + +enum LinkageType { + LinkageTypeExport = 0, + LinkageTypeImport = 1, +}; + +enum AccessQualifier { + AccessQualifierReadOnly = 0, + AccessQualifierWriteOnly = 1, + AccessQualifierReadWrite = 2, +}; + +enum FunctionParameterAttribute { + FunctionParameterAttributeZext = 0, + FunctionParameterAttributeSext = 1, + FunctionParameterAttributeByVal = 2, + FunctionParameterAttributeSret = 3, + FunctionParameterAttributeNoAlias = 4, + FunctionParameterAttributeNoCapture = 5, + FunctionParameterAttributeSVM = 6, + FunctionParameterAttributeNoWrite = 7, + FunctionParameterAttributeNoReadWrite = 8, +}; + +enum Decoration { + DecorationPrecisionLow = 0, + DecorationPrecisionMedium = 1, + DecorationPrecisionHigh = 2, + DecorationBlock = 3, + DecorationBufferBlock = 4, + DecorationRowMajor = 5, + DecorationColMajor = 6, + DecorationGLSLShared = 7, + DecorationGLSLStd140 = 8, + DecorationGLSLStd430 = 9, + DecorationGLSLPacked = 10, + DecorationSmooth = 11, + DecorationNoperspective = 12, + DecorationFlat = 13, + DecorationPatch = 14, + DecorationCentroid = 15, + DecorationSample = 16, + DecorationInvariant = 17, + DecorationRestrict = 18, + DecorationAliased = 19, + DecorationVolatile = 20, + DecorationConstant = 21, + DecorationCoherent = 22, + DecorationNonwritable = 23, + DecorationNonreadable = 24, + DecorationUniform = 25, + DecorationNoStaticUse = 26, + DecorationCPacked = 27, + DecorationSaturatedConversion = 28, + DecorationStream = 29, + DecorationLocation = 30, + DecorationComponent = 31, + DecorationIndex = 32, + DecorationBinding = 33, + DecorationDescriptorSet = 34, + DecorationOffset = 35, + DecorationAlignment = 36, + DecorationXfbBuffer = 37, + DecorationStride = 38, + DecorationBuiltIn = 39, + DecorationFuncParamAttr = 40, + DecorationFPRoundingMode = 41, + DecorationFPFastMathMode = 42, + DecorationLinkageAttributes = 43, + DecorationSpecId = 44, +}; + +enum BuiltIn { + BuiltInPosition = 0, + BuiltInPointSize = 1, + BuiltInClipVertex = 2, + BuiltInClipDistance = 3, + BuiltInCullDistance = 4, + BuiltInVertexId = 5, + BuiltInInstanceId = 6, + BuiltInPrimitiveId = 7, + BuiltInInvocationId = 8, + BuiltInLayer = 9, + BuiltInViewportIndex = 10, + BuiltInTessLevelOuter = 11, + BuiltInTessLevelInner = 12, + BuiltInTessCoord = 13, + BuiltInPatchVertices = 14, + BuiltInFragCoord = 15, + BuiltInPointCoord = 16, + BuiltInFrontFacing = 17, + BuiltInSampleId = 18, + BuiltInSamplePosition = 19, + BuiltInSampleMask = 20, + BuiltInFragColor = 21, + BuiltInFragDepth = 22, + BuiltInHelperInvocation = 23, + BuiltInNumWorkgroups = 24, + BuiltInWorkgroupSize = 25, + BuiltInWorkgroupId = 26, + BuiltInLocalInvocationId = 27, + BuiltInGlobalInvocationId = 28, + BuiltInLocalInvocationIndex = 29, + BuiltInWorkDim = 30, + BuiltInGlobalSize = 31, + BuiltInEnqueuedWorkgroupSize = 32, + BuiltInGlobalOffset = 33, + BuiltInGlobalLinearId = 34, + BuiltInWorkgroupLinearId = 35, + BuiltInSubgroupSize = 36, + BuiltInSubgroupMaxSize = 37, + BuiltInNumSubgroups = 38, + BuiltInNumEnqueuedSubgroups = 39, + BuiltInSubgroupId = 40, + BuiltInSubgroupLocalInvocationId = 41, +}; + +enum SelectionControlShift { + SelectionControlFlattenShift = 0, + SelectionControlDontFlattenShift = 1, +}; + +enum SelectionControlMask { + SelectionControlMaskNone = 0, + SelectionControlFlattenMask = 0x00000001, + SelectionControlDontFlattenMask = 0x00000002, +}; + +enum LoopControlShift { + LoopControlUnrollShift = 0, + LoopControlDontUnrollShift = 1, +}; + +enum LoopControlMask { + LoopControlMaskNone = 0, + LoopControlUnrollMask = 0x00000001, + LoopControlDontUnrollMask = 0x00000002, +}; + +enum FunctionControlShift { + FunctionControlInlineShift = 0, + FunctionControlDontInlineShift = 1, + FunctionControlPureShift = 2, + FunctionControlConstShift = 3, +}; + +enum FunctionControlMask { + FunctionControlMaskNone = 0, + FunctionControlInlineMask = 0x00000001, + FunctionControlDontInlineMask = 0x00000002, + FunctionControlPureMask = 0x00000004, + FunctionControlConstMask = 0x00000008, +}; + +enum MemorySemanticsShift { + MemorySemanticsRelaxedShift = 0, + MemorySemanticsSequentiallyConsistentShift = 1, + MemorySemanticsAcquireShift = 2, + MemorySemanticsReleaseShift = 3, + MemorySemanticsUniformMemoryShift = 4, + MemorySemanticsSubgroupMemoryShift = 5, + MemorySemanticsWorkgroupLocalMemoryShift = 6, + MemorySemanticsWorkgroupGlobalMemoryShift = 7, + MemorySemanticsAtomicCounterMemoryShift = 8, + MemorySemanticsImageMemoryShift = 9, +}; + +enum MemorySemanticsMask { + MemorySemanticsMaskNone = 0, + MemorySemanticsRelaxedMask = 0x00000001, + MemorySemanticsSequentiallyConsistentMask = 0x00000002, + MemorySemanticsAcquireMask = 0x00000004, + MemorySemanticsReleaseMask = 0x00000008, + MemorySemanticsUniformMemoryMask = 0x00000010, + MemorySemanticsSubgroupMemoryMask = 0x00000020, + MemorySemanticsWorkgroupLocalMemoryMask = 0x00000040, + MemorySemanticsWorkgroupGlobalMemoryMask = 0x00000080, + MemorySemanticsAtomicCounterMemoryMask = 0x00000100, + MemorySemanticsImageMemoryMask = 0x00000200, +}; + +enum MemoryAccessShift { + MemoryAccessVolatileShift = 0, + MemoryAccessAlignedShift = 1, +}; + +enum MemoryAccessMask { + MemoryAccessMaskNone = 0, + MemoryAccessVolatileMask = 0x00000001, + MemoryAccessAlignedMask = 0x00000002, +}; + +enum ExecutionScope { + ExecutionScopeCrossDevice = 0, + ExecutionScopeDevice = 1, + ExecutionScopeWorkgroup = 2, + ExecutionScopeSubgroup = 3, +}; + +enum GroupOperation { + GroupOperationReduce = 0, + GroupOperationInclusiveScan = 1, + GroupOperationExclusiveScan = 2, +}; + +enum KernelEnqueueFlags { + KernelEnqueueFlagsNoWait = 0, + KernelEnqueueFlagsWaitKernel = 1, + KernelEnqueueFlagsWaitWorkGroup = 2, +}; + +enum KernelProfilingInfoShift { + KernelProfilingInfoCmdExecTimeShift = 0, +}; + +enum KernelProfilingInfoMask { + KernelProfilingInfoMaskNone = 0, + KernelProfilingInfoCmdExecTimeMask = 0x00000001, +}; + +enum Op { + OpNop = 0, + OpSource = 1, + OpSourceExtension = 2, + OpExtension = 3, + OpExtInstImport = 4, + OpMemoryModel = 5, + OpEntryPoint = 6, + OpExecutionMode = 7, + OpTypeVoid = 8, + OpTypeBool = 9, + OpTypeInt = 10, + OpTypeFloat = 11, + OpTypeVector = 12, + OpTypeMatrix = 13, + OpTypeSampler = 14, + OpTypeFilter = 15, + OpTypeArray = 16, + OpTypeRuntimeArray = 17, + OpTypeStruct = 18, + OpTypeOpaque = 19, + OpTypePointer = 20, + OpTypeFunction = 21, + OpTypeEvent = 22, + OpTypeDeviceEvent = 23, + OpTypeReserveId = 24, + OpTypeQueue = 25, + OpTypePipe = 26, + OpConstantTrue = 27, + OpConstantFalse = 28, + OpConstant = 29, + OpConstantComposite = 30, + OpConstantSampler = 31, + OpConstantNullPointer = 32, + OpConstantNullObject = 33, + OpSpecConstantTrue = 34, + OpSpecConstantFalse = 35, + OpSpecConstant = 36, + OpSpecConstantComposite = 37, + OpVariable = 38, + OpVariableArray = 39, + OpFunction = 40, + OpFunctionParameter = 41, + OpFunctionEnd = 42, + OpFunctionCall = 43, + OpExtInst = 44, + OpUndef = 45, + OpLoad = 46, + OpStore = 47, + OpPhi = 48, + OpDecorationGroup = 49, + OpDecorate = 50, + OpMemberDecorate = 51, + OpGroupDecorate = 52, + OpGroupMemberDecorate = 53, + OpName = 54, + OpMemberName = 55, + OpString = 56, + OpLine = 57, + OpVectorExtractDynamic = 58, + OpVectorInsertDynamic = 59, + OpVectorShuffle = 60, + OpCompositeConstruct = 61, + OpCompositeExtract = 62, + OpCompositeInsert = 63, + OpCopyObject = 64, + OpCopyMemory = 65, + OpCopyMemorySized = 66, + OpSampler = 67, + OpTextureSample = 68, + OpTextureSampleDref = 69, + OpTextureSampleLod = 70, + OpTextureSampleProj = 71, + OpTextureSampleGrad = 72, + OpTextureSampleOffset = 73, + OpTextureSampleProjLod = 74, + OpTextureSampleProjGrad = 75, + OpTextureSampleLodOffset = 76, + OpTextureSampleProjOffset = 77, + OpTextureSampleGradOffset = 78, + OpTextureSampleProjLodOffset = 79, + OpTextureSampleProjGradOffset = 80, + OpTextureFetchTexelLod = 81, + OpTextureFetchTexelOffset = 82, + OpTextureFetchSample = 83, + OpTextureFetchTexel = 84, + OpTextureGather = 85, + OpTextureGatherOffset = 86, + OpTextureGatherOffsets = 87, + OpTextureQuerySizeLod = 88, + OpTextureQuerySize = 89, + OpTextureQueryLod = 90, + OpTextureQueryLevels = 91, + OpTextureQuerySamples = 92, + OpAccessChain = 93, + OpInBoundsAccessChain = 94, + OpSNegate = 95, + OpFNegate = 96, + OpNot = 97, + OpAny = 98, + OpAll = 99, + OpConvertFToU = 100, + OpConvertFToS = 101, + OpConvertSToF = 102, + OpConvertUToF = 103, + OpUConvert = 104, + OpSConvert = 105, + OpFConvert = 106, + OpConvertPtrToU = 107, + OpConvertUToPtr = 108, + OpPtrCastToGeneric = 109, + OpGenericCastToPtr = 110, + OpBitcast = 111, + OpTranspose = 112, + OpIsNan = 113, + OpIsInf = 114, + OpIsFinite = 115, + OpIsNormal = 116, + OpSignBitSet = 117, + OpLessOrGreater = 118, + OpOrdered = 119, + OpUnordered = 120, + OpArrayLength = 121, + OpIAdd = 122, + OpFAdd = 123, + OpISub = 124, + OpFSub = 125, + OpIMul = 126, + OpFMul = 127, + OpUDiv = 128, + OpSDiv = 129, + OpFDiv = 130, + OpUMod = 131, + OpSRem = 132, + OpSMod = 133, + OpFRem = 134, + OpFMod = 135, + OpVectorTimesScalar = 136, + OpMatrixTimesScalar = 137, + OpVectorTimesMatrix = 138, + OpMatrixTimesVector = 139, + OpMatrixTimesMatrix = 140, + OpOuterProduct = 141, + OpDot = 142, + OpShiftRightLogical = 143, + OpShiftRightArithmetic = 144, + OpShiftLeftLogical = 145, + OpLogicalOr = 146, + OpLogicalXor = 147, + OpLogicalAnd = 148, + OpBitwiseOr = 149, + OpBitwiseXor = 150, + OpBitwiseAnd = 151, + OpSelect = 152, + OpIEqual = 153, + OpFOrdEqual = 154, + OpFUnordEqual = 155, + OpINotEqual = 156, + OpFOrdNotEqual = 157, + OpFUnordNotEqual = 158, + OpULessThan = 159, + OpSLessThan = 160, + OpFOrdLessThan = 161, + OpFUnordLessThan = 162, + OpUGreaterThan = 163, + OpSGreaterThan = 164, + OpFOrdGreaterThan = 165, + OpFUnordGreaterThan = 166, + OpULessThanEqual = 167, + OpSLessThanEqual = 168, + OpFOrdLessThanEqual = 169, + OpFUnordLessThanEqual = 170, + OpUGreaterThanEqual = 171, + OpSGreaterThanEqual = 172, + OpFOrdGreaterThanEqual = 173, + OpFUnordGreaterThanEqual = 174, + OpDPdx = 175, + OpDPdy = 176, + OpFwidth = 177, + OpDPdxFine = 178, + OpDPdyFine = 179, + OpFwidthFine = 180, + OpDPdxCoarse = 181, + OpDPdyCoarse = 182, + OpFwidthCoarse = 183, + OpEmitVertex = 184, + OpEndPrimitive = 185, + OpEmitStreamVertex = 186, + OpEndStreamPrimitive = 187, + OpControlBarrier = 188, + OpMemoryBarrier = 189, + OpImagePointer = 190, + OpAtomicInit = 191, + OpAtomicLoad = 192, + OpAtomicStore = 193, + OpAtomicExchange = 194, + OpAtomicCompareExchange = 195, + OpAtomicCompareExchangeWeak = 196, + OpAtomicIIncrement = 197, + OpAtomicIDecrement = 198, + OpAtomicIAdd = 199, + OpAtomicISub = 200, + OpAtomicUMin = 201, + OpAtomicUMax = 202, + OpAtomicAnd = 203, + OpAtomicOr = 204, + OpAtomicXor = 205, + OpLoopMerge = 206, + OpSelectionMerge = 207, + OpLabel = 208, + OpBranch = 209, + OpBranchConditional = 210, + OpSwitch = 211, + OpKill = 212, + OpReturn = 213, + OpReturnValue = 214, + OpUnreachable = 215, + OpLifetimeStart = 216, + OpLifetimeStop = 217, + OpCompileFlag = 218, + OpAsyncGroupCopy = 219, + OpWaitGroupEvents = 220, + OpGroupAll = 221, + OpGroupAny = 222, + OpGroupBroadcast = 223, + OpGroupIAdd = 224, + OpGroupFAdd = 225, + OpGroupFMin = 226, + OpGroupUMin = 227, + OpGroupSMin = 228, + OpGroupFMax = 229, + OpGroupUMax = 230, + OpGroupSMax = 231, + OpGenericCastToPtrExplicit = 232, + OpGenericPtrMemSemantics = 233, + OpReadPipe = 234, + OpWritePipe = 235, + OpReservedReadPipe = 236, + OpReservedWritePipe = 237, + OpReserveReadPipePackets = 238, + OpReserveWritePipePackets = 239, + OpCommitReadPipe = 240, + OpCommitWritePipe = 241, + OpIsValidReserveId = 242, + OpGetNumPipePackets = 243, + OpGetMaxPipePackets = 244, + OpGroupReserveReadPipePackets = 245, + OpGroupReserveWritePipePackets = 246, + OpGroupCommitReadPipe = 247, + OpGroupCommitWritePipe = 248, + OpEnqueueMarker = 249, + OpEnqueueKernel = 250, + OpGetKernelNDrangeSubGroupCount = 251, + OpGetKernelNDrangeMaxSubGroupSize = 252, + OpGetKernelWorkGroupSize = 253, + OpGetKernelPreferredWorkGroupSizeMultiple = 254, + OpRetainEvent = 255, + OpReleaseEvent = 256, + OpCreateUserEvent = 257, + OpIsValidEvent = 258, + OpSetUserEventStatus = 259, + OpCaptureEventProfilingInfo = 260, + OpGetDefaultQueue = 261, + OpBuildNDRange = 262, + OpSatConvertSToU = 263, + OpSatConvertUToS = 264, + OpAtomicIMin = 265, + OpAtomicIMax = 266, +}; + +}; // end namespace spv + +#endif // #ifdef __cplusplus + + +#ifndef __cplusplus + +const int SpvMagicNumber = 0x07230203; +const int SpvVersion = 99; + +typedef unsigned int SpvId; + +const unsigned int SpvOpCodeMask = 0xFFFF; +const unsigned int SpvWordCountShift = 16; + +typedef enum SpvSourceLanguage_ { + SpvSourceLanguageUnknown = 0, + SpvSourceLanguageESSL = 1, + SpvSourceLanguageGLSL = 2, + SpvSourceLanguageOpenCL = 3, +} SpvSourceLanguage; + +typedef enum SpvExecutionModel_ { + SpvExecutionModelVertex = 0, + SpvExecutionModelTessellationControl = 1, + SpvExecutionModelTessellationEvaluation = 2, + SpvExecutionModelGeometry = 3, + SpvExecutionModelFragment = 4, + SpvExecutionModelGLCompute = 5, + SpvExecutionModelKernel = 6, +} SpvExecutionModel; + +typedef enum SpvAddressingModel_ { + SpvAddressingModelLogical = 0, + SpvAddressingModelPhysical32 = 1, + SpvAddressingModelPhysical64 = 2, +} SpvAddressingModel; + +typedef enum SpvMemoryModel_ { + SpvMemoryModelSimple = 0, + SpvMemoryModelGLSL450 = 1, + SpvMemoryModelOpenCL12 = 2, + SpvMemoryModelOpenCL20 = 3, + SpvMemoryModelOpenCL21 = 4, +} SpvMemoryModel; + +typedef enum SpvExecutionMode_ { + SpvExecutionModeInvocations = 0, + SpvExecutionModeSpacingEqual = 1, + SpvExecutionModeSpacingFractionalEven = 2, + SpvExecutionModeSpacingFractionalOdd = 3, + SpvExecutionModeVertexOrderCw = 4, + SpvExecutionModeVertexOrderCcw = 5, + SpvExecutionModePixelCenterInteger = 6, + SpvExecutionModeOriginUpperLeft = 7, + SpvExecutionModeEarlyFragmentTests = 8, + SpvExecutionModePointMode = 9, + SpvExecutionModeXfb = 10, + SpvExecutionModeDepthReplacing = 11, + SpvExecutionModeDepthAny = 12, + SpvExecutionModeDepthGreater = 13, + SpvExecutionModeDepthLess = 14, + SpvExecutionModeDepthUnchanged = 15, + SpvExecutionModeLocalSize = 16, + SpvExecutionModeLocalSizeHint = 17, + SpvExecutionModeInputPoints = 18, + SpvExecutionModeInputLines = 19, + SpvExecutionModeInputLinesAdjacency = 20, + SpvExecutionModeInputTriangles = 21, + SpvExecutionModeInputTrianglesAdjacency = 22, + SpvExecutionModeInputQuads = 23, + SpvExecutionModeInputIsolines = 24, + SpvExecutionModeOutputVertices = 25, + SpvExecutionModeOutputPoints = 26, + SpvExecutionModeOutputLineStrip = 27, + SpvExecutionModeOutputTriangleStrip = 28, + SpvExecutionModeVecTypeHint = 29, + SpvExecutionModeContractionOff = 30, +} SpvExecutionMode; + +typedef enum SpvStorageClass_ { + SpvStorageClassUniformConstant = 0, + SpvStorageClassInput = 1, + SpvStorageClassUniform = 2, + SpvStorageClassOutput = 3, + SpvStorageClassWorkgroupLocal = 4, + SpvStorageClassWorkgroupGlobal = 5, + SpvStorageClassPrivateGlobal = 6, + SpvStorageClassFunction = 7, + SpvStorageClassGeneric = 8, + SpvStorageClassPrivate = 9, + SpvStorageClassAtomicCounter = 10, +} SpvStorageClass; + +typedef enum SpvDim_ { + SpvDim1D = 0, + SpvDim2D = 1, + SpvDim3D = 2, + SpvDimCube = 3, + SpvDimRect = 4, + SpvDimBuffer = 5, +} SpvDim; + +typedef enum SpvSamplerAddressingMode_ { + SpvSamplerAddressingModeNone = 0, + SpvSamplerAddressingModeClampToEdge = 1, + SpvSamplerAddressingModeClamp = 2, + SpvSamplerAddressingModeRepeat = 3, + SpvSamplerAddressingModeRepeatMirrored = 4, +} SpvSamplerAddressingMode; + +typedef enum SpvSamplerFilterMode_ { + SpvSamplerFilterModeNearest = 0, + SpvSamplerFilterModeLinear = 1, +} SpvSamplerFilterMode; + +typedef enum SpvFPFastMathModeShift_ { + SpvFPFastMathModeNotNaNShift = 0, + SpvFPFastMathModeNotInfShift = 1, + SpvFPFastMathModeNSZShift = 2, + SpvFPFastMathModeAllowRecipShift = 3, + SpvFPFastMathModeFastShift = 4, +} SpvFPFastMathModeShift; + +typedef enum SpvFPFastMathModeMask_ { + SpvFPFastMathModeMaskNone = 0, + SpvFPFastMathModeNotNaNMask = 0x00000001, + SpvFPFastMathModeNotInfMask = 0x00000002, + SpvFPFastMathModeNSZMask = 0x00000004, + SpvFPFastMathModeAllowRecipMask = 0x00000008, + SpvFPFastMathModeFastMask = 0x00000010, +} SpvFPFastMathModeMask; + +typedef enum SpvFPRoundingMode_ { + SpvFPRoundingModeRTE = 0, + SpvFPRoundingModeRTZ = 1, + SpvFPRoundingModeRTP = 2, + SpvFPRoundingModeRTN = 3, +} SpvFPRoundingMode; + +typedef enum SpvLinkageType_ { + SpvLinkageTypeExport = 0, + SpvLinkageTypeImport = 1, +} SpvLinkageType; + +typedef enum SpvAccessQualifier_ { + SpvAccessQualifierReadOnly = 0, + SpvAccessQualifierWriteOnly = 1, + SpvAccessQualifierReadWrite = 2, +} SpvAccessQualifier; + +typedef enum SpvFunctionParameterAttribute_ { + SpvFunctionParameterAttributeZext = 0, + SpvFunctionParameterAttributeSext = 1, + SpvFunctionParameterAttributeByVal = 2, + SpvFunctionParameterAttributeSret = 3, + SpvFunctionParameterAttributeNoAlias = 4, + SpvFunctionParameterAttributeNoCapture = 5, + SpvFunctionParameterAttributeSVM = 6, + SpvFunctionParameterAttributeNoWrite = 7, + SpvFunctionParameterAttributeNoReadWrite = 8, +} SpvFunctionParameterAttribute; + +typedef enum SpvDecoration_ { + SpvDecorationPrecisionLow = 0, + SpvDecorationPrecisionMedium = 1, + SpvDecorationPrecisionHigh = 2, + SpvDecorationBlock = 3, + SpvDecorationBufferBlock = 4, + SpvDecorationRowMajor = 5, + SpvDecorationColMajor = 6, + SpvDecorationGLSLShared = 7, + SpvDecorationGLSLStd140 = 8, + SpvDecorationGLSLStd430 = 9, + SpvDecorationGLSLPacked = 10, + SpvDecorationSmooth = 11, + SpvDecorationNoperspective = 12, + SpvDecorationFlat = 13, + SpvDecorationPatch = 14, + SpvDecorationCentroid = 15, + SpvDecorationSample = 16, + SpvDecorationInvariant = 17, + SpvDecorationRestrict = 18, + SpvDecorationAliased = 19, + SpvDecorationVolatile = 20, + SpvDecorationConstant = 21, + SpvDecorationCoherent = 22, + SpvDecorationNonwritable = 23, + SpvDecorationNonreadable = 24, + SpvDecorationUniform = 25, + SpvDecorationNoStaticUse = 26, + SpvDecorationCPacked = 27, + SpvDecorationSaturatedConversion = 28, + SpvDecorationStream = 29, + SpvDecorationLocation = 30, + SpvDecorationComponent = 31, + SpvDecorationIndex = 32, + SpvDecorationBinding = 33, + SpvDecorationDescriptorSet = 34, + SpvDecorationOffset = 35, + SpvDecorationAlignment = 36, + SpvDecorationXfbBuffer = 37, + SpvDecorationStride = 38, + SpvDecorationBuiltIn = 39, + SpvDecorationFuncParamAttr = 40, + SpvDecorationFPRoundingMode = 41, + SpvDecorationFPFastMathMode = 42, + SpvDecorationLinkageAttributes = 43, + SpvDecorationSpecId = 44, +} SpvDecoration; + +typedef enum SpvBuiltIn_ { + SpvBuiltInPosition = 0, + SpvBuiltInPointSize = 1, + SpvBuiltInClipVertex = 2, + SpvBuiltInClipDistance = 3, + SpvBuiltInCullDistance = 4, + SpvBuiltInVertexId = 5, + SpvBuiltInInstanceId = 6, + SpvBuiltInPrimitiveId = 7, + SpvBuiltInInvocationId = 8, + SpvBuiltInLayer = 9, + SpvBuiltInViewportIndex = 10, + SpvBuiltInTessLevelOuter = 11, + SpvBuiltInTessLevelInner = 12, + SpvBuiltInTessCoord = 13, + SpvBuiltInPatchVertices = 14, + SpvBuiltInFragCoord = 15, + SpvBuiltInPointCoord = 16, + SpvBuiltInFrontFacing = 17, + SpvBuiltInSampleId = 18, + SpvBuiltInSamplePosition = 19, + SpvBuiltInSampleMask = 20, + SpvBuiltInFragColor = 21, + SpvBuiltInFragDepth = 22, + SpvBuiltInHelperInvocation = 23, + SpvBuiltInNumWorkgroups = 24, + SpvBuiltInWorkgroupSize = 25, + SpvBuiltInWorkgroupId = 26, + SpvBuiltInLocalInvocationId = 27, + SpvBuiltInGlobalInvocationId = 28, + SpvBuiltInLocalInvocationIndex = 29, + SpvBuiltInWorkDim = 30, + SpvBuiltInGlobalSize = 31, + SpvBuiltInEnqueuedWorkgroupSize = 32, + SpvBuiltInGlobalOffset = 33, + SpvBuiltInGlobalLinearId = 34, + SpvBuiltInWorkgroupLinearId = 35, + SpvBuiltInSubgroupSize = 36, + SpvBuiltInSubgroupMaxSize = 37, + SpvBuiltInNumSubgroups = 38, + SpvBuiltInNumEnqueuedSubgroups = 39, + SpvBuiltInSubgroupId = 40, + SpvBuiltInSubgroupLocalInvocationId = 41, +} SpvBuiltIn; + +typedef enum SpvSelectionControlShift_ { + SpvSelectionControlFlattenShift = 0, + SpvSelectionControlDontFlattenShift = 1, +} SpvSelectionControlShift; + +typedef enum SpvSelectionControlMask_ { + SpvSelectionControlMaskNone = 0, + SpvSelectionControlFlattenMask = 0x00000001, + SpvSelectionControlDontFlattenMask = 0x00000002, +} SpvSelectionControlMask; + +typedef enum SpvLoopControlShift_ { + SpvLoopControlUnrollShift = 0, + SpvLoopControlDontUnrollShift = 1, +} SpvLoopControlShift; + +typedef enum SpvLoopControlMask_ { + SpvLoopControlMaskNone = 0, + SpvLoopControlUnrollMask = 0x00000001, + SpvLoopControlDontUnrollMask = 0x00000002, +} SpvLoopControlMask; + +typedef enum SpvFunctionControlShift_ { + SpvFunctionControlInlineShift = 0, + SpvFunctionControlDontInlineShift = 1, + SpvFunctionControlPureShift = 2, + SpvFunctionControlConstShift = 3, +} SpvFunctionControlShift; + +typedef enum SpvFunctionControlMask_ { + SpvFunctionControlMaskNone = 0, + SpvFunctionControlInlineMask = 0x00000001, + SpvFunctionControlDontInlineMask = 0x00000002, + SpvFunctionControlPureMask = 0x00000004, + SpvFunctionControlConstMask = 0x00000008, +} SpvFunctionControlMask; + +typedef enum SpvMemorySemanticsShift_ { + SpvMemorySemanticsRelaxedShift = 0, + SpvMemorySemanticsSequentiallyConsistentShift = 1, + SpvMemorySemanticsAcquireShift = 2, + SpvMemorySemanticsReleaseShift = 3, + SpvMemorySemanticsUniformMemoryShift = 4, + SpvMemorySemanticsSubgroupMemoryShift = 5, + SpvMemorySemanticsWorkgroupLocalMemoryShift = 6, + SpvMemorySemanticsWorkgroupGlobalMemoryShift = 7, + SpvMemorySemanticsAtomicCounterMemoryShift = 8, + SpvMemorySemanticsImageMemoryShift = 9, +} SpvMemorySemanticsShift; + +typedef enum SpvMemorySemanticsMask_ { + SpvMemorySemanticsMaskNone = 0, + SpvMemorySemanticsRelaxedMask = 0x00000001, + SpvMemorySemanticsSequentiallyConsistentMask = 0x00000002, + SpvMemorySemanticsAcquireMask = 0x00000004, + SpvMemorySemanticsReleaseMask = 0x00000008, + SpvMemorySemanticsUniformMemoryMask = 0x00000010, + SpvMemorySemanticsSubgroupMemoryMask = 0x00000020, + SpvMemorySemanticsWorkgroupLocalMemoryMask = 0x00000040, + SpvMemorySemanticsWorkgroupGlobalMemoryMask = 0x00000080, + SpvMemorySemanticsAtomicCounterMemoryMask = 0x00000100, + SpvMemorySemanticsImageMemoryMask = 0x00000200, +} SpvMemorySemanticsMask; + +typedef enum SpvMemoryAccessShift_ { + SpvMemoryAccessVolatileShift = 0, + SpvMemoryAccessAlignedShift = 1, +} SpvMemoryAccessShift; + +typedef enum SpvMemoryAccessMask_ { + SpvMemoryAccessMaskNone = 0, + SpvMemoryAccessVolatileMask = 0x00000001, + SpvMemoryAccessAlignedMask = 0x00000002, +} SpvMemoryAccessMask; + +typedef enum SpvExecutionScope_ { + SpvExecutionScopeCrossDevice = 0, + SpvExecutionScopeDevice = 1, + SpvExecutionScopeWorkgroup = 2, + SpvExecutionScopeSubgroup = 3, +} SpvExecutionScope; + +typedef enum SpvGroupOperation_ { + SpvGroupOperationReduce = 0, + SpvGroupOperationInclusiveScan = 1, + SpvGroupOperationExclusiveScan = 2, +} SpvGroupOperation; + +typedef enum SpvKernelEnqueueFlags_ { + SpvKernelEnqueueFlagsNoWait = 0, + SpvKernelEnqueueFlagsWaitKernel = 1, + SpvKernelEnqueueFlagsWaitWorkGroup = 2, +} SpvKernelEnqueueFlags; + +typedef enum SpvKernelProfilingInfoShift_ { + SpvKernelProfilingInfoCmdExecTimeShift = 0, +} SpvKernelProfilingInfoShift; + +typedef enum SpvKernelProfilingInfoMask_ { + SpvKernelProfilingInfoMaskNone = 0, + SpvKernelProfilingInfoCmdExecTimeMask = 0x00000001, +} SpvKernelProfilingInfoMask; + +typedef enum SpvOp_ { + SpvOpNop = 0, + SpvOpSource = 1, + SpvOpSourceExtension = 2, + SpvOpExtension = 3, + SpvOpExtInstImport = 4, + SpvOpMemoryModel = 5, + SpvOpEntryPoint = 6, + SpvOpExecutionMode = 7, + SpvOpTypeVoid = 8, + SpvOpTypeBool = 9, + SpvOpTypeInt = 10, + SpvOpTypeFloat = 11, + SpvOpTypeVector = 12, + SpvOpTypeMatrix = 13, + SpvOpTypeSampler = 14, + SpvOpTypeFilter = 15, + SpvOpTypeArray = 16, + SpvOpTypeRuntimeArray = 17, + SpvOpTypeStruct = 18, + SpvOpTypeOpaque = 19, + SpvOpTypePointer = 20, + SpvOpTypeFunction = 21, + SpvOpTypeEvent = 22, + SpvOpTypeDeviceEvent = 23, + SpvOpTypeReserveId = 24, + SpvOpTypeQueue = 25, + SpvOpTypePipe = 26, + SpvOpConstantTrue = 27, + SpvOpConstantFalse = 28, + SpvOpConstant = 29, + SpvOpConstantComposite = 30, + SpvOpConstantSampler = 31, + SpvOpConstantNullPointer = 32, + SpvOpConstantNullObject = 33, + SpvOpSpecConstantTrue = 34, + SpvOpSpecConstantFalse = 35, + SpvOpSpecConstant = 36, + SpvOpSpecConstantComposite = 37, + SpvOpVariable = 38, + SpvOpVariableArray = 39, + SpvOpFunction = 40, + SpvOpFunctionParameter = 41, + SpvOpFunctionEnd = 42, + SpvOpFunctionCall = 43, + SpvOpExtInst = 44, + SpvOpUndef = 45, + SpvOpLoad = 46, + SpvOpStore = 47, + SpvOpPhi = 48, + SpvOpDecorationGroup = 49, + SpvOpDecorate = 50, + SpvOpMemberDecorate = 51, + SpvOpGroupDecorate = 52, + SpvOpGroupMemberDecorate = 53, + SpvOpName = 54, + SpvOpMemberName = 55, + SpvOpString = 56, + SpvOpLine = 57, + SpvOpVectorExtractDynamic = 58, + SpvOpVectorInsertDynamic = 59, + SpvOpVectorShuffle = 60, + SpvOpCompositeConstruct = 61, + SpvOpCompositeExtract = 62, + SpvOpCompositeInsert = 63, + SpvOpCopyObject = 64, + SpvOpCopyMemory = 65, + SpvOpCopyMemorySized = 66, + SpvOpSampler = 67, + SpvOpTextureSample = 68, + SpvOpTextureSampleDref = 69, + SpvOpTextureSampleLod = 70, + SpvOpTextureSampleProj = 71, + SpvOpTextureSampleGrad = 72, + SpvOpTextureSampleOffset = 73, + SpvOpTextureSampleProjLod = 74, + SpvOpTextureSampleProjGrad = 75, + SpvOpTextureSampleLodOffset = 76, + SpvOpTextureSampleProjOffset = 77, + SpvOpTextureSampleGradOffset = 78, + SpvOpTextureSampleProjLodOffset = 79, + SpvOpTextureSampleProjGradOffset = 80, + SpvOpTextureFetchTexelLod = 81, + SpvOpTextureFetchTexelOffset = 82, + SpvOpTextureFetchSample = 83, + SpvOpTextureFetchTexel = 84, + SpvOpTextureGather = 85, + SpvOpTextureGatherOffset = 86, + SpvOpTextureGatherOffsets = 87, + SpvOpTextureQuerySizeLod = 88, + SpvOpTextureQuerySize = 89, + SpvOpTextureQueryLod = 90, + SpvOpTextureQueryLevels = 91, + SpvOpTextureQuerySamples = 92, + SpvOpAccessChain = 93, + SpvOpInBoundsAccessChain = 94, + SpvOpSNegate = 95, + SpvOpFNegate = 96, + SpvOpNot = 97, + SpvOpAny = 98, + SpvOpAll = 99, + SpvOpConvertFToU = 100, + SpvOpConvertFToS = 101, + SpvOpConvertSToF = 102, + SpvOpConvertUToF = 103, + SpvOpUConvert = 104, + SpvOpSConvert = 105, + SpvOpFConvert = 106, + SpvOpConvertPtrToU = 107, + SpvOpConvertUToPtr = 108, + SpvOpPtrCastToGeneric = 109, + SpvOpGenericCastToPtr = 110, + SpvOpBitcast = 111, + SpvOpTranspose = 112, + SpvOpIsNan = 113, + SpvOpIsInf = 114, + SpvOpIsFinite = 115, + SpvOpIsNormal = 116, + SpvOpSignBitSet = 117, + SpvOpLessOrGreater = 118, + SpvOpOrdered = 119, + SpvOpUnordered = 120, + SpvOpArrayLength = 121, + SpvOpIAdd = 122, + SpvOpFAdd = 123, + SpvOpISub = 124, + SpvOpFSub = 125, + SpvOpIMul = 126, + SpvOpFMul = 127, + SpvOpUDiv = 128, + SpvOpSDiv = 129, + SpvOpFDiv = 130, + SpvOpUMod = 131, + SpvOpSRem = 132, + SpvOpSMod = 133, + SpvOpFRem = 134, + SpvOpFMod = 135, + SpvOpVectorTimesScalar = 136, + SpvOpMatrixTimesScalar = 137, + SpvOpVectorTimesMatrix = 138, + SpvOpMatrixTimesVector = 139, + SpvOpMatrixTimesMatrix = 140, + SpvOpOuterProduct = 141, + SpvOpDot = 142, + SpvOpShiftRightLogical = 143, + SpvOpShiftRightArithmetic = 144, + SpvOpShiftLeftLogical = 145, + SpvOpLogicalOr = 146, + SpvOpLogicalXor = 147, + SpvOpLogicalAnd = 148, + SpvOpBitwiseOr = 149, + SpvOpBitwiseXor = 150, + SpvOpBitwiseAnd = 151, + SpvOpSelect = 152, + SpvOpIEqual = 153, + SpvOpFOrdEqual = 154, + SpvOpFUnordEqual = 155, + SpvOpINotEqual = 156, + SpvOpFOrdNotEqual = 157, + SpvOpFUnordNotEqual = 158, + SpvOpULessThan = 159, + SpvOpSLessThan = 160, + SpvOpFOrdLessThan = 161, + SpvOpFUnordLessThan = 162, + SpvOpUGreaterThan = 163, + SpvOpSGreaterThan = 164, + SpvOpFOrdGreaterThan = 165, + SpvOpFUnordGreaterThan = 166, + SpvOpULessThanEqual = 167, + SpvOpSLessThanEqual = 168, + SpvOpFOrdLessThanEqual = 169, + SpvOpFUnordLessThanEqual = 170, + SpvOpUGreaterThanEqual = 171, + SpvOpSGreaterThanEqual = 172, + SpvOpFOrdGreaterThanEqual = 173, + SpvOpFUnordGreaterThanEqual = 174, + SpvOpDPdx = 175, + SpvOpDPdy = 176, + SpvOpFwidth = 177, + SpvOpDPdxFine = 178, + SpvOpDPdyFine = 179, + SpvOpFwidthFine = 180, + SpvOpDPdxCoarse = 181, + SpvOpDPdyCoarse = 182, + SpvOpFwidthCoarse = 183, + SpvOpEmitVertex = 184, + SpvOpEndPrimitive = 185, + SpvOpEmitStreamVertex = 186, + SpvOpEndStreamPrimitive = 187, + SpvOpControlBarrier = 188, + SpvOpMemoryBarrier = 189, + SpvOpImagePointer = 190, + SpvOpAtomicInit = 191, + SpvOpAtomicLoad = 192, + SpvOpAtomicStore = 193, + SpvOpAtomicExchange = 194, + SpvOpAtomicCompareExchange = 195, + SpvOpAtomicCompareExchangeWeak = 196, + SpvOpAtomicIIncrement = 197, + SpvOpAtomicIDecrement = 198, + SpvOpAtomicIAdd = 199, + SpvOpAtomicISub = 200, + SpvOpAtomicUMin = 201, + SpvOpAtomicUMax = 202, + SpvOpAtomicAnd = 203, + SpvOpAtomicOr = 204, + SpvOpAtomicXor = 205, + SpvOpLoopMerge = 206, + SpvOpSelectionMerge = 207, + SpvOpLabel = 208, + SpvOpBranch = 209, + SpvOpBranchConditional = 210, + SpvOpSwitch = 211, + SpvOpKill = 212, + SpvOpReturn = 213, + SpvOpReturnValue = 214, + SpvOpUnreachable = 215, + SpvOpLifetimeStart = 216, + SpvOpLifetimeStop = 217, + SpvOpCompileFlag = 218, + SpvOpAsyncGroupCopy = 219, + SpvOpWaitGroupEvents = 220, + SpvOpGroupAll = 221, + SpvOpGroupAny = 222, + SpvOpGroupBroadcast = 223, + SpvOpGroupIAdd = 224, + SpvOpGroupFAdd = 225, + SpvOpGroupFMin = 226, + SpvOpGroupUMin = 227, + SpvOpGroupSMin = 228, + SpvOpGroupFMax = 229, + SpvOpGroupUMax = 230, + SpvOpGroupSMax = 231, + SpvOpGenericCastToPtrExplicit = 232, + SpvOpGenericPtrMemSemantics = 233, + SpvOpReadPipe = 234, + SpvOpWritePipe = 235, + SpvOpReservedReadPipe = 236, + SpvOpReservedWritePipe = 237, + SpvOpReserveReadPipePackets = 238, + SpvOpReserveWritePipePackets = 239, + SpvOpCommitReadPipe = 240, + SpvOpCommitWritePipe = 241, + SpvOpIsValidReserveId = 242, + SpvOpGetNumPipePackets = 243, + SpvOpGetMaxPipePackets = 244, + SpvOpGroupReserveReadPipePackets = 245, + SpvOpGroupReserveWritePipePackets = 246, + SpvOpGroupCommitReadPipe = 247, + SpvOpGroupCommitWritePipe = 248, + SpvOpEnqueueMarker = 249, + SpvOpEnqueueKernel = 250, + SpvOpGetKernelNDrangeSubGroupCount = 251, + SpvOpGetKernelNDrangeMaxSubGroupSize = 252, + SpvOpGetKernelWorkGroupSize = 253, + SpvOpGetKernelPreferredWorkGroupSizeMultiple = 254, + SpvOpRetainEvent = 255, + SpvOpReleaseEvent = 256, + SpvOpCreateUserEvent = 257, + SpvOpIsValidEvent = 258, + SpvOpSetUserEventStatus = 259, + SpvOpCaptureEventProfilingInfo = 260, + SpvOpGetDefaultQueue = 261, + SpvOpBuildNDRange = 262, + SpvOpSatConvertSToU = 263, + SpvOpSatConvertUToS = 264, + SpvOpAtomicIMin = 265, + SpvOpAtomicIMax = 266, +} SpvOp; + +#endif // #ifndef __cplusplus + +#endif // #ifndef spirv_H diff --git a/src/AST/Declaration.cpp b/src/AST/Declaration.cpp new file mode 100644 index 0000000..8ebbdf3 --- /dev/null +++ b/src/AST/Declaration.cpp @@ -0,0 +1,17 @@ +#include "Declaration.h" + +/** + * @brief AST::Declaration::Declaration + */ +AST::Declaration::Declaration(void) +{ + // ... +} + +/** + * @brief AST::Declaration::~Declaration + */ +AST::Declaration::~Declaration(void) +{ + // ... +} diff --git a/src/AST/Declaration.h b/src/AST/Declaration.h new file mode 100644 index 0000000..0d35671 --- /dev/null +++ b/src/AST/Declaration.h @@ -0,0 +1,40 @@ +#pragma once + +#include "../Node.h" + +namespace AST +{ + +class Declaration : public Node +{ + +public: + + enum EDeclarationType + { + SIMPLE, + NAMESPACE, + STRUCTURE, + CLASS, + FUNCTION, + EMPTY, // created by empty-declaration + ATTRIBUTE, // created be attribute-declaration + ASM, // created by asm-definition + TEMPLATE, // created by template-declaration + EXPLICIT_INSTANTIATION, // created by explicit-instantiation + EXPLICIT_SPECIALIZATION, // created by explicit-specialization + }; + + explicit Declaration (void); + virtual ~Declaration (void); + + virtual ENodeType getNodeType (void) const { return(DECLARATION); } + + virtual EDeclarationType getDeclarationType (void) const = 0; + +private: + + // ... +}; + +} diff --git a/src/AST/Declarations/AssemblerDefinition.cpp b/src/AST/Declarations/AssemblerDefinition.cpp new file mode 100644 index 0000000..0b53aec --- /dev/null +++ b/src/AST/Declarations/AssemblerDefinition.cpp @@ -0,0 +1,18 @@ +#include "AssemblerDefinition.h" + +/** + * @brief AST::AssemblerDefinition::AssemblerDefinition + */ +AST::AssemblerDefinition::AssemblerDefinition(const char * instructions) +: m_strInstructions(instructions) +{ + // ... +} + +/** + * @brief AST::AssemblerDefinition::~AssemblerDefinition + */ +AST::AssemblerDefinition::~AssemblerDefinition() +{ + // ... +} diff --git a/src/AST/Declarations/AssemblerDefinition.h b/src/AST/Declarations/AssemblerDefinition.h new file mode 100644 index 0000000..4006970 --- /dev/null +++ b/src/AST/Declarations/AssemblerDefinition.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class AssemblerDefinition : public Declaration +{ + +public: + + explicit AssemblerDefinition (const char * instructions); + virtual ~AssemblerDefinition (void); + + virtual EDeclarationType getDeclarationType (void) const { return(ASM); } + +private: + + std::string m_strInstructions; + +}; + +} diff --git a/src/AST/Declarations/AttributeDeclaration.cpp b/src/AST/Declarations/AttributeDeclaration.cpp new file mode 100644 index 0000000..b7d0430 --- /dev/null +++ b/src/AST/Declarations/AttributeDeclaration.cpp @@ -0,0 +1,17 @@ +#include "AttributeDeclaration.h" + +/** + * @brief AST::AttributeDeclaration::AttributeDeclaration + */ +AST::AttributeDeclaration::AttributeDeclaration(void) +{ + // ... +} + +/** + * @brief AST::AttributeDeclaration::~AttributeDeclaration + */ +AST::AttributeDeclaration::~AttributeDeclaration() +{ + // ... +} diff --git a/src/AST/Declarations/AttributeDeclaration.h b/src/AST/Declarations/AttributeDeclaration.h new file mode 100644 index 0000000..9915918 --- /dev/null +++ b/src/AST/Declarations/AttributeDeclaration.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class AttributeDeclaration : public Declaration +{ + +public: + + explicit AttributeDeclaration (void); + virtual ~AttributeDeclaration (void); + + virtual EDeclarationType getDeclarationType (void) const { return(ATTRIBUTE); } + +private: + + // ... + +}; + +} diff --git a/src/AST/Declarations/Class.cpp b/src/AST/Declarations/Class.cpp new file mode 100644 index 0000000..140d063 --- /dev/null +++ b/src/AST/Declarations/Class.cpp @@ -0,0 +1,19 @@ +#include "Class.h" + +/** + * @brief AST::Class::Class + * @param pName + */ +AST::Class::Class(const char * pName) +: m_strName(pName) +{ + // ... +} + +/** + * @brief AST::Class::~Class + */ +AST::Class::~Class() +{ + // ... +} diff --git a/src/AST/Declarations/Class.h b/src/AST/Declarations/Class.h new file mode 100644 index 0000000..bf96f01 --- /dev/null +++ b/src/AST/Declarations/Class.h @@ -0,0 +1,43 @@ +#pragma once + +#include "../Declaration.h" + +#include +#include + +namespace AST +{ + +class Class : public Declaration +{ + +public: + + explicit Class (const char * pName); + virtual ~Class (void); + + virtual EDeclarationType getDeclarationType (void) const { return(CLASS); } + + void addNode (const Node * pNode) + { + m_aNodes.push_back(pNode); + } + + const std::vector & getNodes (void) const + { + return(m_aNodes); + } + + const std::string & getName(void) const + { + return(m_strName); + } + +private: + + std::string m_strName; + + std::vector m_aNodes; +}; + +} diff --git a/src/AST/Declarations/EmptyDeclaration.cpp b/src/AST/Declarations/EmptyDeclaration.cpp new file mode 100644 index 0000000..b95d805 --- /dev/null +++ b/src/AST/Declarations/EmptyDeclaration.cpp @@ -0,0 +1,17 @@ +#include "EmptyDeclaration.h" + +/** + * @brief AST::EmptyDeclaration::EmptyDeclaration + */ +AST::EmptyDeclaration::EmptyDeclaration(void) +{ + // ... +} + +/** + * @brief AST::EmptyDeclaration::~EmptyDeclaration + */ +AST::EmptyDeclaration::~EmptyDeclaration() +{ + // ... +} diff --git a/src/AST/Declarations/EmptyDeclaration.h b/src/AST/Declarations/EmptyDeclaration.h new file mode 100644 index 0000000..0a38c48 --- /dev/null +++ b/src/AST/Declarations/EmptyDeclaration.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class EmptyDeclaration : public Declaration +{ + +public: + + explicit EmptyDeclaration (void); + virtual ~EmptyDeclaration (void); + + virtual EDeclarationType getDeclarationType (void) const { return(EMPTY); } + +private: + + // ... + +}; + +} diff --git a/src/AST/Declarations/ExplicitInstantiation.cpp b/src/AST/Declarations/ExplicitInstantiation.cpp new file mode 100644 index 0000000..a5d8ea9 --- /dev/null +++ b/src/AST/Declarations/ExplicitInstantiation.cpp @@ -0,0 +1,18 @@ +#include "ExplicitInstantiation.h" + +/** + * @brief AST::ExplicitInstantiation::ExplicitInstantiation + */ +AST::ExplicitInstantiation::ExplicitInstantiation(const Declaration * pDeclaration) +: m_pDeclaration(pDeclaration) +{ + // ... +} + +/** + * @brief AST::ExplicitInstantiation::~ExplicitInstantiation + */ +AST::ExplicitInstantiation::~ExplicitInstantiation() +{ + // ... +} diff --git a/src/AST/Declarations/ExplicitInstantiation.h b/src/AST/Declarations/ExplicitInstantiation.h new file mode 100644 index 0000000..d3ad622 --- /dev/null +++ b/src/AST/Declarations/ExplicitInstantiation.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class ExplicitInstantiation : public Declaration +{ + +public: + + explicit ExplicitInstantiation (const Declaration * pDeclaration); + virtual ~ExplicitInstantiation (void); + + virtual EDeclarationType getDeclarationType (void) const { return(EXPLICIT_INSTANTIATION); } + +private: + + const Declaration * m_pDeclaration; + +}; + +} diff --git a/src/AST/Declarations/ExplicitSpecialization.cpp b/src/AST/Declarations/ExplicitSpecialization.cpp new file mode 100644 index 0000000..c66546b --- /dev/null +++ b/src/AST/Declarations/ExplicitSpecialization.cpp @@ -0,0 +1,18 @@ +#include "ExplicitSpecialization.h" + +/** + * @brief AST::ExplicitSpecialization::ExplicitSpecialization + */ +AST::ExplicitSpecialization::ExplicitSpecialization(const Declaration * pDeclaration) +: m_pDeclaration(pDeclaration) +{ + // ... +} + +/** + * @brief AST::ExplicitSpecialization::~ExplicitSpecialization + */ +AST::ExplicitSpecialization::~ExplicitSpecialization() +{ + // ... +} diff --git a/src/AST/Declarations/ExplicitSpecialization.h b/src/AST/Declarations/ExplicitSpecialization.h new file mode 100644 index 0000000..6c036e5 --- /dev/null +++ b/src/AST/Declarations/ExplicitSpecialization.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class ExplicitSpecialization : public Declaration +{ + +public: + + explicit ExplicitSpecialization (const Declaration * pDeclaration); + virtual ~ExplicitSpecialization (void); + + virtual EDeclarationType getDeclarationType (void) const { return(EXPLICIT_SPECIALIZATION); } + +private: + + const Declaration * m_pDeclaration; + +}; + +} diff --git a/src/AST/Declarations/FunctionDefinition.cpp b/src/AST/Declarations/FunctionDefinition.cpp new file mode 100644 index 0000000..b732e80 --- /dev/null +++ b/src/AST/Declarations/FunctionDefinition.cpp @@ -0,0 +1,22 @@ +#include "FunctionDefinition.h" + +/** + * @brief AST::Function::Function + * @param pName + * @param pReturnType + */ +AST::FunctionDefinition::FunctionDefinition(const char * pName, const char * pReturnType, const std::vector & params) +: m_strName(pName) +, m_strReturnType(pReturnType) +, m_aParameters(params) +{ + // ... +} + +/** + * @brief AST::Function::~Function + */ +AST::FunctionDefinition::~FunctionDefinition(void) +{ + // ... +} diff --git a/src/AST/Declarations/FunctionDefinition.h b/src/AST/Declarations/FunctionDefinition.h new file mode 100644 index 0000000..d93f571 --- /dev/null +++ b/src/AST/Declarations/FunctionDefinition.h @@ -0,0 +1,54 @@ +#pragma once + +#include "../Declaration.h" + +#include +#include + +namespace AST +{ + +class FunctionDefinition : public Declaration +{ + +public: + + explicit FunctionDefinition (const char * pName, const char * pReturnType, const std::vector & params); + virtual ~FunctionDefinition (void); + + virtual EDeclarationType getDeclarationType (void) const { return(FUNCTION); } + + const std::string & getReturnType (void) const + { + return(m_strReturnType); + } + + const std::vector & getParameters (void) const + { + return(m_aParameters); + } + + void addNode (const Node * pNode) + { + m_aNodes.push_back(pNode); + } + + const std::vector & getNodes (void) const + { + return(m_aNodes); + } + + const std::string & getName(void) const + { + return(m_strName); + } + +private: + + std::string m_strName; + std::string m_strReturnType; + std::vector m_aParameters; + std::vector m_aNodes; +}; + +} diff --git a/src/AST/Declarations/NamespaceDefinition.cpp b/src/AST/Declarations/NamespaceDefinition.cpp new file mode 100644 index 0000000..7fe3b8a --- /dev/null +++ b/src/AST/Declarations/NamespaceDefinition.cpp @@ -0,0 +1,20 @@ +#include "NamespaceDefinition.h" + +/** + * @brief AST::Namespace::Namespace + * @param pName + */ +AST::NamespaceDefinition::NamespaceDefinition(const char * pName, const std::vector & children) +: m_strName(pName) +, m_aNodes(children) +{ + // ... +} + +/** + * @brief AST::Namespace::~Namespace + */ +AST::NamespaceDefinition::~NamespaceDefinition() +{ + // ... +} diff --git a/src/AST/Declarations/NamespaceDefinition.h b/src/AST/Declarations/NamespaceDefinition.h new file mode 100644 index 0000000..a946c93 --- /dev/null +++ b/src/AST/Declarations/NamespaceDefinition.h @@ -0,0 +1,38 @@ +#pragma once + +#include "../Declaration.h" + +#include +#include + +namespace AST +{ + +class NamespaceDefinition : public Declaration +{ + +public: + + explicit NamespaceDefinition (const char * pName, const std::vector & children); + virtual ~NamespaceDefinition (void); + + virtual EDeclarationType getDeclarationType (void) const { return(NAMESPACE); } + + const std::vector & getNodes (void) const + { + return(m_aNodes); + } + + const std::string & getName(void) const + { + return(m_strName); + } + +private: + + std::string m_strName; + + std::vector m_aNodes; +}; + +} diff --git a/src/AST/Declarations/SimpleDeclaration.cpp b/src/AST/Declarations/SimpleDeclaration.cpp new file mode 100644 index 0000000..3048b04 --- /dev/null +++ b/src/AST/Declarations/SimpleDeclaration.cpp @@ -0,0 +1,20 @@ +#include "SimpleDeclaration.h" + +/** + * @brief AST::SimpleDeclaration::SimpleDeclaration + */ +AST::SimpleDeclaration::SimpleDeclaration(const char * pType, const char * pName, const Expression * pExpression) +: m_strType(pType) +, m_strName(pName) +, m_pExpression(pExpression) +{ + // ... +} + +/** + * @brief AST::SimpleDeclaration::~SimpleDeclaration + */ +AST::SimpleDeclaration::~SimpleDeclaration() +{ + // ... +} diff --git a/src/AST/Declarations/SimpleDeclaration.h b/src/AST/Declarations/SimpleDeclaration.h new file mode 100644 index 0000000..fd7e3e2 --- /dev/null +++ b/src/AST/Declarations/SimpleDeclaration.h @@ -0,0 +1,33 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class Expression; + +class SimpleDeclaration : public Declaration +{ + +public: + + explicit SimpleDeclaration (const char * pType, const char * pName, const Expression * pExpression = nullptr); + virtual ~SimpleDeclaration (void); + + virtual EDeclarationType getDeclarationType (void) const { return(SIMPLE); } + + const std::string & getVariableType (void) const { return(m_strType); } + const std::string & getVariableName (void) const { return(m_strName); } + const Expression * getExpression (void) const { return(m_pExpression); } + +private: + + std::string m_strType; + std::string m_strName; + const Expression * m_pExpression; +}; + +} diff --git a/src/AST/Declarations/StaticAssertDeclaration.cpp b/src/AST/Declarations/StaticAssertDeclaration.cpp new file mode 100644 index 0000000..a561c55 --- /dev/null +++ b/src/AST/Declarations/StaticAssertDeclaration.cpp @@ -0,0 +1,18 @@ +#include "StaticAssertDeclaration.h" + +/** + * @brief AST::StaticAssertDeclaration::StaticAssertDeclaration + */ +AST::StaticAssertDeclaration::StaticAssertDeclaration(const Expression * pExpression) +: m_pExpression(pExpression) +{ + // ... +} + +/** + * @brief AST::StaticAssertDeclaration::~StaticAssertDeclaration + */ +AST::StaticAssertDeclaration::~StaticAssertDeclaration(void) +{ + // ... +} diff --git a/src/AST/Declarations/StaticAssertDeclaration.h b/src/AST/Declarations/StaticAssertDeclaration.h new file mode 100644 index 0000000..40a2e0a --- /dev/null +++ b/src/AST/Declarations/StaticAssertDeclaration.h @@ -0,0 +1,28 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class Expression; + +class StaticAssertDeclaration : public Declaration +{ + +public: + + explicit StaticAssertDeclaration (const Expression * pExpression); + virtual ~StaticAssertDeclaration (void); + + virtual EDeclarationType getDeclarationType (void) const { return(EMPTY); } + +private: + + const Expression * m_pExpression; + +}; + +} diff --git a/src/AST/Declarations/Structure.cpp b/src/AST/Declarations/Structure.cpp new file mode 100644 index 0000000..8516eb8 --- /dev/null +++ b/src/AST/Declarations/Structure.cpp @@ -0,0 +1,19 @@ +#include "Structure.h" + +/** + * @brief AST::Structure::Structure + * @param pName + */ +AST::Structure::Structure(const char * pName) +: m_strName(pName) +{ + // ... +} + +/** + * @brief AST::Structure::~Structure + */ +AST::Structure::~Structure() +{ + // ... +} diff --git a/src/AST/Declarations/Structure.h b/src/AST/Declarations/Structure.h new file mode 100644 index 0000000..7e7f6d3 --- /dev/null +++ b/src/AST/Declarations/Structure.h @@ -0,0 +1,43 @@ +#pragma once + +#include "../Declaration.h" + +#include +#include + +namespace AST +{ + +class Structure : public Declaration +{ + +public: + + explicit Structure (const char * pName); + virtual ~Structure (void); + + virtual EDeclarationType getDeclarationType (void) const { return(STRUCTURE); } + + void addNode (const Node * pNode) + { + m_aNodes.push_back(pNode); + } + + const std::vector & getNodes (void) const + { + return(m_aNodes); + } + + const std::string & getName(void) const + { + return(m_strName); + } + +private: + + std::string m_strName; + + std::vector m_aNodes; +}; + +} diff --git a/src/AST/Declarations/TemplateDeclaration.cpp b/src/AST/Declarations/TemplateDeclaration.cpp new file mode 100644 index 0000000..1bba733 --- /dev/null +++ b/src/AST/Declarations/TemplateDeclaration.cpp @@ -0,0 +1,18 @@ +#include "TemplateDeclaration.h" + +/** + * @brief AST::TemplateDeclaration::TemplateDeclaration + */ +AST::TemplateDeclaration::TemplateDeclaration(const Declaration * pDeclaration) +: m_pDeclaration(pDeclaration) +{ + // ... +} + +/** + * @brief AST::TemplateDeclaration::~TemplateDeclaration + */ +AST::TemplateDeclaration::~TemplateDeclaration() +{ + // ... +} diff --git a/src/AST/Declarations/TemplateDeclaration.h b/src/AST/Declarations/TemplateDeclaration.h new file mode 100644 index 0000000..64996a4 --- /dev/null +++ b/src/AST/Declarations/TemplateDeclaration.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Declaration.h" + +#include + +namespace AST +{ + +class TemplateDeclaration : public Declaration +{ + +public: + + explicit TemplateDeclaration (const Declaration * pDeclaration); + virtual ~TemplateDeclaration (void); + + virtual EDeclarationType getDeclarationType (void) const { return(TEMPLATE); } + +private: + + const Declaration * m_pDeclaration; + +}; + +} diff --git a/src/AST/Expression.cpp b/src/AST/Expression.cpp new file mode 100644 index 0000000..8cf81f2 --- /dev/null +++ b/src/AST/Expression.cpp @@ -0,0 +1,17 @@ +#include "Expression.h" + +/** + * @brief AST::Expression::Expression + */ +AST::Expression::Expression(void) +{ + // ... +} + +/** + * @brief AST::Expression::~Expression + */ +AST::Expression::~Expression(void) +{ + // ... +} diff --git a/src/AST/Expression.h b/src/AST/Expression.h new file mode 100644 index 0000000..eba3eb8 --- /dev/null +++ b/src/AST/Expression.h @@ -0,0 +1,31 @@ +#pragma once + +#include "../Node.h" + +namespace AST +{ + +class Expression : public Node +{ + +public: + + enum EExpressionType + { + VARIABLE, + CONSTANT, + CALL, + UNARY, + BINARY + }; + + explicit Expression (void); + virtual ~Expression (void); + + virtual ENodeType getNodeType (void) const { return(EXPRESSION); } + + virtual EExpressionType getExpressionType (void) const = 0; + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/Addition.cpp b/src/AST/Expressions/Arithmetic/Addition.cpp new file mode 100644 index 0000000..0165e68 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Addition.cpp @@ -0,0 +1,20 @@ +#include "Addition.h" + +/** + * @brief AST::Addition::Addition + * @param lhs + * @param rhs + */ +AST::Addition::Addition(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::Addition::~Addition + */ +AST::Addition::~Addition(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/Addition.h b/src/AST/Expressions/Arithmetic/Addition.h new file mode 100644 index 0000000..115db4b --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Addition.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class Addition : public Binary +{ + +public: + + explicit Addition (const Expression * lhs, const Expression * rhs); + virtual ~Addition (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::ADDITION); } + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/Division.cpp b/src/AST/Expressions/Arithmetic/Division.cpp new file mode 100644 index 0000000..5f5e143 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Division.cpp @@ -0,0 +1,20 @@ +#include "Division.h" + +/** + * @brief AST::Division::Division + * @param lhs + * @param rhs + */ +AST::Division::Division(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::Division::~Division + */ +AST::Division::~Division(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/Division.h b/src/AST/Expressions/Arithmetic/Division.h new file mode 100644 index 0000000..b869460 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Division.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class Division : public Binary +{ + +public: + + explicit Division (const Expression * lhs, const Expression * rhs); + virtual ~Division (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::DIVISION); } + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/Modulo.cpp b/src/AST/Expressions/Arithmetic/Modulo.cpp new file mode 100644 index 0000000..518eee2 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Modulo.cpp @@ -0,0 +1,20 @@ +#include "Modulo.h" + +/** + * @brief AST::Modulo::Modulo + * @param lhs + * @param rhs + */ +AST::Modulo::Modulo(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::Modulo::~Modulo + */ +AST::Modulo::~Modulo(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/Modulo.h b/src/AST/Expressions/Arithmetic/Modulo.h new file mode 100644 index 0000000..207ee9f --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Modulo.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class Modulo : public Binary +{ + +public: + + explicit Modulo (const Expression * lhs, const Expression * rhs); + virtual ~Modulo (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::MODULO); } + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/Multiplication.cpp b/src/AST/Expressions/Arithmetic/Multiplication.cpp new file mode 100644 index 0000000..a045823 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Multiplication.cpp @@ -0,0 +1,20 @@ +#include "Multiplication.h" + +/** + * @brief AST::Multiplication::Multiplication + * @param lhs + * @param rhs + */ +AST::Multiplication::Multiplication(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::Multiplication::~Multiplication + */ +AST::Multiplication::~Multiplication(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/Multiplication.h b/src/AST/Expressions/Arithmetic/Multiplication.h new file mode 100644 index 0000000..5ec63d3 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Multiplication.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class Multiplication : public Binary +{ + +public: + + explicit Multiplication (const Expression * lhs, const Expression * rhs); + virtual ~Multiplication (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::MULTIPLICATON); } + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/Subtraction.cpp b/src/AST/Expressions/Arithmetic/Subtraction.cpp new file mode 100644 index 0000000..4f8a8bc --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Subtraction.cpp @@ -0,0 +1,20 @@ +#include "Subtraction.h" + +/** + * @brief AST::Subtraction::Subtraction + * @param lhs + * @param rhs + */ +AST::Subtraction::Subtraction(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::Subtraction::~Subtraction + */ +AST::Subtraction::~Subtraction(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/Subtraction.h b/src/AST/Expressions/Arithmetic/Subtraction.h new file mode 100644 index 0000000..46b5c37 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/Subtraction.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class Subtraction : public Binary +{ + +public: + + explicit Subtraction (const Expression * lhs, const Expression * rhs); + virtual ~Subtraction (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::SUBTRACTION); } + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/UnaryMinus.cpp b/src/AST/Expressions/Arithmetic/UnaryMinus.cpp new file mode 100644 index 0000000..864bf35 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/UnaryMinus.cpp @@ -0,0 +1,20 @@ +#include "UnaryMinus.h" + + +/** + * @brief AST::UnaryMinus::UnaryMinus + * @param pExpr + */ +AST::UnaryMinus::UnaryMinus(const AST::Expression * pExpr) +: Unary(pExpr) +{ + // ... +} + +/** + * @brief AST::UnaryMinus::~UnaryMinus + */ +AST::UnaryMinus::~UnaryMinus(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/UnaryMinus.h b/src/AST/Expressions/Arithmetic/UnaryMinus.h new file mode 100644 index 0000000..0a9dfd2 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/UnaryMinus.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Unary.h" + +namespace AST +{ + +class UnaryMinus : public Unary +{ + +public: + + explicit UnaryMinus (const Expression * pExpr); + virtual ~UnaryMinus (void); + + virtual EUnaryType getUnaryType (void) const { return(Unary::MINUS); } + +}; + +} diff --git a/src/AST/Expressions/Arithmetic/UnaryPlus.cpp b/src/AST/Expressions/Arithmetic/UnaryPlus.cpp new file mode 100644 index 0000000..7025c65 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/UnaryPlus.cpp @@ -0,0 +1,19 @@ +#include "UnaryPlus.h" + +/** + * @brief AST::UnaryPlus::UnaryPlus + * @param pExpr + */ +AST::UnaryPlus::UnaryPlus(const AST::Expression * pExpr) +: Unary(pExpr) +{ + // ... +} + +/** + * @brief AST::UnaryPlus::~UnaryPlus + */ +AST::UnaryPlus::~UnaryPlus(void) +{ + // ... +} diff --git a/src/AST/Expressions/Arithmetic/UnaryPlus.h b/src/AST/Expressions/Arithmetic/UnaryPlus.h new file mode 100644 index 0000000..468a946 --- /dev/null +++ b/src/AST/Expressions/Arithmetic/UnaryPlus.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Unary.h" + +namespace AST +{ + +class UnaryPlus : public Unary +{ + +public: + + explicit UnaryPlus (const Expression * pExpr); + virtual ~UnaryPlus (void); + + virtual EUnaryType getUnaryType (void) const { return(Unary::PLUS); } + +}; + +} diff --git a/src/AST/Expressions/Assignment/AdditionAssignment.cpp b/src/AST/Expressions/Assignment/AdditionAssignment.cpp new file mode 100644 index 0000000..b2346e2 --- /dev/null +++ b/src/AST/Expressions/Assignment/AdditionAssignment.cpp @@ -0,0 +1,20 @@ +#include "AdditionAssignment.h" + +/** + * @brief AST::AdditionAssignment::AdditionAssignment + * @param lhs + * @param rhs + */ +AST::AdditionAssignment::AdditionAssignment(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::AdditionAssignment::~AdditionAssignment + */ +AST::AdditionAssignment::~AdditionAssignment(void) +{ + // ... +} diff --git a/src/AST/Expressions/Assignment/AdditionAssignment.h b/src/AST/Expressions/Assignment/AdditionAssignment.h new file mode 100644 index 0000000..5695ed0 --- /dev/null +++ b/src/AST/Expressions/Assignment/AdditionAssignment.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class AdditionAssignment : public Binary +{ + +public: + + explicit AdditionAssignment (const Expression * lhs, const Expression * rhs); + virtual ~AdditionAssignment (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::ADDITION_ASSIGNMENT); } + +}; + +} diff --git a/src/AST/Expressions/Assignment/BasicAssignment.cpp b/src/AST/Expressions/Assignment/BasicAssignment.cpp new file mode 100644 index 0000000..1382b96 --- /dev/null +++ b/src/AST/Expressions/Assignment/BasicAssignment.cpp @@ -0,0 +1,20 @@ +#include "BasicAssignment.h" + +/** + * @brief AST::BasicAssignment::BasicAssignment + * @param lhs + * @param rhs + */ +AST::BasicAssignment::BasicAssignment(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::BasicAssignment::~BasicAssignment + */ +AST::BasicAssignment::~BasicAssignment(void) +{ + // ... +} diff --git a/src/AST/Expressions/Assignment/BasicAssignment.h b/src/AST/Expressions/Assignment/BasicAssignment.h new file mode 100644 index 0000000..0da448d --- /dev/null +++ b/src/AST/Expressions/Assignment/BasicAssignment.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class BasicAssignment : public Binary +{ + +public: + + explicit BasicAssignment (const Expression * lhs, const Expression * rhs); + virtual ~BasicAssignment (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::BASIC_ASSIGNMENT); } + +}; + +} diff --git a/src/AST/Expressions/Assignment/DivisionAssignment.cpp b/src/AST/Expressions/Assignment/DivisionAssignment.cpp new file mode 100644 index 0000000..077c06b --- /dev/null +++ b/src/AST/Expressions/Assignment/DivisionAssignment.cpp @@ -0,0 +1,20 @@ +#include "DivisionAssignment.h" + +/** + * @brief AST::DivisionAssignment::DivisionAssignment + * @param lhs + * @param rhs + */ +AST::DivisionAssignment::DivisionAssignment(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::DivisionAssignment::~DivisionAssignment + */ +AST::DivisionAssignment::~DivisionAssignment(void) +{ + // ... +} diff --git a/src/AST/Expressions/Assignment/DivisionAssignment.h b/src/AST/Expressions/Assignment/DivisionAssignment.h new file mode 100644 index 0000000..82fee70 --- /dev/null +++ b/src/AST/Expressions/Assignment/DivisionAssignment.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class DivisionAssignment : public Binary +{ + +public: + + explicit DivisionAssignment (const Expression * lhs, const Expression * rhs); + virtual ~DivisionAssignment (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::DIVISION_ASSIGNMENT); } + +}; + +} diff --git a/src/AST/Expressions/Assignment/ModuloAssignment.cpp b/src/AST/Expressions/Assignment/ModuloAssignment.cpp new file mode 100644 index 0000000..caa4e23 --- /dev/null +++ b/src/AST/Expressions/Assignment/ModuloAssignment.cpp @@ -0,0 +1,20 @@ +#include "ModuloAssignment.h" + +/** + * @brief AST::ModuloAssignment::ModuloAssignment + * @param lhs + * @param rhs + */ +AST::ModuloAssignment::ModuloAssignment(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::ModuloAssignment::~ModuloAssignment + */ +AST::ModuloAssignment::~ModuloAssignment(void) +{ + // ... +} diff --git a/src/AST/Expressions/Assignment/ModuloAssignment.h b/src/AST/Expressions/Assignment/ModuloAssignment.h new file mode 100644 index 0000000..95253d8 --- /dev/null +++ b/src/AST/Expressions/Assignment/ModuloAssignment.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class ModuloAssignment : public Binary +{ + +public: + + explicit ModuloAssignment (const Expression * lhs, const Expression * rhs); + virtual ~ModuloAssignment (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::MODULO_ASSIGNMENT); } + +}; + +} diff --git a/src/AST/Expressions/Assignment/MultiplicationAssignment.cpp b/src/AST/Expressions/Assignment/MultiplicationAssignment.cpp new file mode 100644 index 0000000..a17bec4 --- /dev/null +++ b/src/AST/Expressions/Assignment/MultiplicationAssignment.cpp @@ -0,0 +1,20 @@ +#include "MultiplicationAssignment.h" + +/** + * @brief AST::MultiplicationAssignment::MultiplicationAssignment + * @param lhs + * @param rhs + */ +AST::MultiplicationAssignment::MultiplicationAssignment(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::MultiplicationAssignment::~MultiplicationAssignment + */ +AST::MultiplicationAssignment::~MultiplicationAssignment(void) +{ + // ... +} diff --git a/src/AST/Expressions/Assignment/MultiplicationAssignment.h b/src/AST/Expressions/Assignment/MultiplicationAssignment.h new file mode 100644 index 0000000..14a0dcc --- /dev/null +++ b/src/AST/Expressions/Assignment/MultiplicationAssignment.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class MultiplicationAssignment : public Binary +{ + +public: + + explicit MultiplicationAssignment (const Expression * lhs, const Expression * rhs); + virtual ~MultiplicationAssignment (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::MULTIPLICATION_ASSIGNMENT); } + +}; + +} diff --git a/src/AST/Expressions/Assignment/SubtractionAssignment.cpp b/src/AST/Expressions/Assignment/SubtractionAssignment.cpp new file mode 100644 index 0000000..51354d4 --- /dev/null +++ b/src/AST/Expressions/Assignment/SubtractionAssignment.cpp @@ -0,0 +1,20 @@ +#include "SubtractionAssignment.h" + +/** + * @brief AST::SubtractionAssignment::SubtractionAssignment + * @param lhs + * @param rhs + */ +AST::SubtractionAssignment::SubtractionAssignment(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::SubtractionAssignment::~SubtractionAssignment + */ +AST::SubtractionAssignment::~SubtractionAssignment(void) +{ + // ... +} diff --git a/src/AST/Expressions/Assignment/SubtractionAssignment.h b/src/AST/Expressions/Assignment/SubtractionAssignment.h new file mode 100644 index 0000000..9b2d69f --- /dev/null +++ b/src/AST/Expressions/Assignment/SubtractionAssignment.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class SubtractionAssignment : public Binary +{ + +public: + + explicit SubtractionAssignment (const Expression * lhs, const Expression * rhs); + virtual ~SubtractionAssignment (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::SUBTRACTION_ASSIGNMENT); } + +}; + +} diff --git a/src/AST/Expressions/Binary.cpp b/src/AST/Expressions/Binary.cpp new file mode 100644 index 0000000..0f431ca --- /dev/null +++ b/src/AST/Expressions/Binary.cpp @@ -0,0 +1,19 @@ +#include "Binary.h" + +/** + * @brief AST::Binary::Binary + */ +AST::Binary::Binary(const Expression * pLeftExpr, const Expression * pRightExpr) +: m_pLeftExpr(pLeftExpr) +, m_pRightExpr(pRightExpr) +{ + // ... +} + +/** + * @brief AST::Binary::~Binary + */ +AST::Binary::~Binary(void) +{ + // ... +} diff --git a/src/AST/Expressions/Binary.h b/src/AST/Expressions/Binary.h new file mode 100644 index 0000000..b25d6b1 --- /dev/null +++ b/src/AST/Expressions/Binary.h @@ -0,0 +1,53 @@ +#pragma once + +#include "../Expression.h" + +namespace AST +{ + +class Binary : public Expression +{ + +public: + + enum EBinaryType + { + // Arithmetic + ADDITION, + SUBTRACTION, + MULTIPLICATON, + DIVISION, + MODULO, + // Relational + EQ, + NEQ, + GT, + GEQ, + LT, + LEQ, + // Assignment + BASIC_ASSIGNMENT, + ADDITION_ASSIGNMENT, + SUBTRACTION_ASSIGNMENT, + MULTIPLICATION_ASSIGNMENT, + DIVISION_ASSIGNMENT, + MODULO_ASSIGNMENT, + }; + + explicit Binary (const Expression * pLeftExpr, const Expression * pRightExpr); + virtual ~Binary (void); + + virtual EExpressionType getExpressionType (void) const { return(BINARY); } + + const Expression * getLeftExpression() const { return(m_pLeftExpr); } + const Expression * getRightExpression() const { return(m_pRightExpr); } + + virtual EBinaryType getBinaryType (void) const = 0; + +private: + + const Expression * m_pLeftExpr; + const Expression * m_pRightExpr; +}; + +} diff --git a/src/AST/Expressions/Call.cpp b/src/AST/Expressions/Call.cpp new file mode 100644 index 0000000..91d2316 --- /dev/null +++ b/src/AST/Expressions/Call.cpp @@ -0,0 +1,19 @@ +#include "Call.h" + +/** + * @brief AST::Call::Call + */ +AST::Call::Call(const char * pName, const std::vector & arguments) +: m_strFunctionName(pName) +, m_aArguments(arguments) +{ + // ... +} + +/** + * @brief AST::Call::~Call + */ +AST::Call::~Call(void) +{ + // ... +} diff --git a/src/AST/Expressions/Call.h b/src/AST/Expressions/Call.h new file mode 100644 index 0000000..ce1d2c0 --- /dev/null +++ b/src/AST/Expressions/Call.h @@ -0,0 +1,31 @@ +#pragma once + +#include "../Expression.h" + +#include +#include + +namespace AST +{ + +class Call : public Expression +{ + +public: + + explicit Call (const char * pName, const std::vector & arguments); + virtual ~Call (void); + + virtual EExpressionType getExpressionType (void) const { return(CALL); } + + const std::string & getFunctionName(void) const { return(m_strFunctionName); } + + const std::vector & getArguments(void) const { return(m_aArguments); } + +private: + + std::string m_strFunctionName; + std::vector m_aArguments; +}; + +} diff --git a/src/AST/Expressions/Constant.cpp b/src/AST/Expressions/Constant.cpp new file mode 100644 index 0000000..08c1363 --- /dev/null +++ b/src/AST/Expressions/Constant.cpp @@ -0,0 +1,59 @@ +#include "Constant.h" + +/** + * @brief AST::Constant::Constant + * @param c + */ +AST::Constant::Constant(char c) +: m_eType(CHAR) +{ + m_nValue.as_char = c; +} + +/** + * @brief AST::Constant::Constant + * @param s + */ +AST::Constant::Constant(short s) +: m_eType(SHORT) +{ + m_nValue.as_short = s; +} + +/** + * @brief AST::Constant::Constant + * @param i + */ +AST::Constant::Constant(int i) +: m_eType(INTEGER) +{ + m_nValue.as_int = i; +} + +/** + * @brief AST::Constant::Constant + * @param f + */ +AST::Constant::Constant(float f) +: m_eType(FLOAT) +{ + m_nValue.as_float = f; +} + +/** + * @brief AST::Constant::Constant + * @param d + */ +AST::Constant::Constant(double d) +: m_eType(DOUBLE) +{ + m_nValue.as_double = d; +} + +/** + * @brief AST::Constant::~Constant + */ +AST::Constant::~Constant(void) +{ + // ... +} diff --git a/src/AST/Expressions/Constant.h b/src/AST/Expressions/Constant.h new file mode 100644 index 0000000..07fabd8 --- /dev/null +++ b/src/AST/Expressions/Constant.h @@ -0,0 +1,54 @@ +#pragma once + +#include "../Expression.h" + +namespace AST +{ + +class Constant : public Expression +{ + +public: + + enum ENumberType + { + CHAR, + SHORT, + INTEGER, + FLOAT, + DOUBLE + }; + + explicit Constant (char c); + explicit Constant (short s); + explicit Constant (int i); + explicit Constant (float f); + explicit Constant (double d); + virtual ~Constant (void); + + virtual EExpressionType getExpressionType (void) const { return(CONSTANT); } + + ENumberType getNumberType(void) const { return(m_eType); } + + char getValueAsChar (void) const { return(m_nValue.as_char); } + short getValueAsShort (void) const { return(m_nValue.as_short); } + int getValueAsInt (void) const { return(m_nValue.as_int); } + float getValueAsFloat (void) const { return(m_nValue.as_float); } + double getValueAsDouble(void) const { return(m_nValue.as_double); } + +private: + + union Number + { + char as_char; + short as_short; + int as_int; + float as_float; + double as_double; + }; + + ENumberType m_eType; + Number m_nValue; +}; + +} diff --git a/src/AST/Expressions/Relational/EqualTo.cpp b/src/AST/Expressions/Relational/EqualTo.cpp new file mode 100644 index 0000000..3f0e8f8 --- /dev/null +++ b/src/AST/Expressions/Relational/EqualTo.cpp @@ -0,0 +1,20 @@ +#include "EqualTo.h" + +/** + * @brief AST::EqualTo::EqualTo + * @param lhs + * @param rhs + */ +AST::EqualTo::EqualTo(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::EqualTo::~EqualTo + */ +AST::EqualTo::~EqualTo(void) +{ + // ... +} diff --git a/src/AST/Expressions/Relational/EqualTo.h b/src/AST/Expressions/Relational/EqualTo.h new file mode 100644 index 0000000..7e5e866 --- /dev/null +++ b/src/AST/Expressions/Relational/EqualTo.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class EqualTo : public Binary +{ + +public: + + explicit EqualTo (const Expression * lhs, const Expression * rhs); + virtual ~EqualTo (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::EQ); } + +}; + +} diff --git a/src/AST/Expressions/Relational/GreaterThan.cpp b/src/AST/Expressions/Relational/GreaterThan.cpp new file mode 100644 index 0000000..acb9826 --- /dev/null +++ b/src/AST/Expressions/Relational/GreaterThan.cpp @@ -0,0 +1,20 @@ +#include "GreaterThan.h" + +/** + * @brief AST::GreaterThan::GreaterThan + * @param lhs + * @param rhs + */ +AST::GreaterThan::GreaterThan(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::GreaterThan::~GreaterThan + */ +AST::GreaterThan::~GreaterThan(void) +{ + // ... +} diff --git a/src/AST/Expressions/Relational/GreaterThan.h b/src/AST/Expressions/Relational/GreaterThan.h new file mode 100644 index 0000000..425adce --- /dev/null +++ b/src/AST/Expressions/Relational/GreaterThan.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class GreaterThan : public Binary +{ + +public: + + explicit GreaterThan (const Expression * lhs, const Expression * rhs); + virtual ~GreaterThan (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::GT); } + +}; + +} diff --git a/src/AST/Expressions/Relational/GreaterThanOrEqualTo.cpp b/src/AST/Expressions/Relational/GreaterThanOrEqualTo.cpp new file mode 100644 index 0000000..b81a8cb --- /dev/null +++ b/src/AST/Expressions/Relational/GreaterThanOrEqualTo.cpp @@ -0,0 +1,20 @@ +#include "GreaterThanOrEqualTo.h" + +/** + * @brief AST::GreaterThanOrEqualTo::GreaterThanOrEqualTo + * @param lhs + * @param rhs + */ +AST::GreaterThanOrEqualTo::GreaterThanOrEqualTo(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::GreaterThanOrEqualTo::~GreaterThanOrEqualTo + */ +AST::GreaterThanOrEqualTo::~GreaterThanOrEqualTo(void) +{ + // ... +} diff --git a/src/AST/Expressions/Relational/GreaterThanOrEqualTo.h b/src/AST/Expressions/Relational/GreaterThanOrEqualTo.h new file mode 100644 index 0000000..c9e6349 --- /dev/null +++ b/src/AST/Expressions/Relational/GreaterThanOrEqualTo.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class GreaterThanOrEqualTo : public Binary +{ + +public: + + explicit GreaterThanOrEqualTo (const Expression * lhs, const Expression * rhs); + virtual ~GreaterThanOrEqualTo (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::GEQ); } + +}; + +} diff --git a/src/AST/Expressions/Relational/LessThan.cpp b/src/AST/Expressions/Relational/LessThan.cpp new file mode 100644 index 0000000..0e01022 --- /dev/null +++ b/src/AST/Expressions/Relational/LessThan.cpp @@ -0,0 +1,20 @@ +#include "LessThan.h" + +/** + * @brief AST::LessThan::LessThan + * @param lhs + * @param rhs + */ +AST::LessThan::LessThan(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::LessThan::~LessThan + */ +AST::LessThan::~LessThan(void) +{ + // ... +} diff --git a/src/AST/Expressions/Relational/LessThan.h b/src/AST/Expressions/Relational/LessThan.h new file mode 100644 index 0000000..32d4d9f --- /dev/null +++ b/src/AST/Expressions/Relational/LessThan.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class LessThan : public Binary +{ + +public: + + explicit LessThan (const Expression * lhs, const Expression * rhs); + virtual ~LessThan (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::LT); } + +}; + +} diff --git a/src/AST/Expressions/Relational/LessThanOrEqualTo.cpp b/src/AST/Expressions/Relational/LessThanOrEqualTo.cpp new file mode 100644 index 0000000..38b4ec7 --- /dev/null +++ b/src/AST/Expressions/Relational/LessThanOrEqualTo.cpp @@ -0,0 +1,20 @@ +#include "LessThanOrEqualTo.h" + +/** + * @brief AST::LessThanOrEqualTo::LessThanOrEqualTo + * @param lhs + * @param rhs + */ +AST::LessThanOrEqualTo::LessThanOrEqualTo(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::LessThanOrEqualTo::~LessThanOrEqualTo + */ +AST::LessThanOrEqualTo::~LessThanOrEqualTo(void) +{ + // ... +} diff --git a/src/AST/Expressions/Relational/LessThanOrEqualTo.h b/src/AST/Expressions/Relational/LessThanOrEqualTo.h new file mode 100644 index 0000000..a58c445 --- /dev/null +++ b/src/AST/Expressions/Relational/LessThanOrEqualTo.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class LessThanOrEqualTo : public Binary +{ + +public: + + explicit LessThanOrEqualTo (const Expression * lhs, const Expression * rhs); + virtual ~LessThanOrEqualTo (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::LEQ); } + +}; + +} diff --git a/src/AST/Expressions/Relational/NotEqualTo.cpp b/src/AST/Expressions/Relational/NotEqualTo.cpp new file mode 100644 index 0000000..98ac234 --- /dev/null +++ b/src/AST/Expressions/Relational/NotEqualTo.cpp @@ -0,0 +1,20 @@ +#include "NotEqualTo.h" + +/** + * @brief AST::NotEqualTo::NotEqualTo + * @param lhs + * @param rhs + */ +AST::NotEqualTo::NotEqualTo(const Expression * lhs, const Expression * rhs) +: Binary(lhs, rhs) +{ + // ... +} + +/** + * @brief AST::NotEqualTo::~NotEqualTo + */ +AST::NotEqualTo::~NotEqualTo(void) +{ + // ... +} diff --git a/src/AST/Expressions/Relational/NotEqualTo.h b/src/AST/Expressions/Relational/NotEqualTo.h new file mode 100644 index 0000000..ed55100 --- /dev/null +++ b/src/AST/Expressions/Relational/NotEqualTo.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../Binary.h" + +namespace AST +{ + +class NotEqualTo : public Binary +{ + +public: + + explicit NotEqualTo (const Expression * lhs, const Expression * rhs); + virtual ~NotEqualTo (void); + + virtual EBinaryType getBinaryType (void) const { return(Binary::NEQ); } + +}; + +} diff --git a/src/AST/Expressions/Unary.cpp b/src/AST/Expressions/Unary.cpp new file mode 100644 index 0000000..1b19d4d --- /dev/null +++ b/src/AST/Expressions/Unary.cpp @@ -0,0 +1,18 @@ +#include "Unary.h" + +/** + * @brief AST::Unary::Unary + */ +AST::Unary::Unary(const Expression * pExpr) +: m_pExpr(pExpr) +{ + // ... +} + +/** + * @brief AST::Call::~Call + */ +AST::Unary::~Unary(void) +{ + // ... +} diff --git a/src/AST/Expressions/Unary.h b/src/AST/Expressions/Unary.h new file mode 100644 index 0000000..5ef8145 --- /dev/null +++ b/src/AST/Expressions/Unary.h @@ -0,0 +1,33 @@ +#pragma once + +#include "../Expression.h" + +namespace AST +{ + +class Unary : public Expression +{ + +public: + + enum EUnaryType + { + PLUS, + MINUS + }; + + explicit Unary (const Expression * pExpr); + virtual ~Unary (void); + + virtual EExpressionType getExpressionType (void) const { return(UNARY); } + + const Expression * getExpression() const { return(m_pExpr); } + + virtual EUnaryType getUnaryType (void) const = 0; + +private: + + const Expression * m_pExpr; +}; + +} diff --git a/src/AST/Expressions/Variable.cpp b/src/AST/Expressions/Variable.cpp new file mode 100644 index 0000000..630d129 --- /dev/null +++ b/src/AST/Expressions/Variable.cpp @@ -0,0 +1,19 @@ +#include "Variable.h" + +/** + * @brief AST::Variable::Variable + * @param pName + */ +AST::Variable::Variable(const char * pName) +: m_strName(pName) +{ + // ... +} + +/** + * @brief AST::Variable::~Variable + */ +AST::Variable::~Variable(void) +{ + // ... +} diff --git a/src/AST/Expressions/Variable.h b/src/AST/Expressions/Variable.h new file mode 100644 index 0000000..a6e0b35 --- /dev/null +++ b/src/AST/Expressions/Variable.h @@ -0,0 +1,30 @@ +#pragma once + +#include "../Expression.h" + +#include + +namespace AST +{ + +class Variable : public Expression +{ + +public: + + explicit Variable (const char * pName); + virtual ~Variable (void); + + virtual EExpressionType getExpressionType (void) const { return(VARIABLE); } + + const std::string & getName (void) const + { + return(m_strName); + } + +private: + + std::string m_strName; +}; + +} diff --git a/src/AST/Statement.cpp b/src/AST/Statement.cpp new file mode 100644 index 0000000..37ccc9f --- /dev/null +++ b/src/AST/Statement.cpp @@ -0,0 +1,17 @@ +#include "Statement.h" + +/** + * @brief AST::Statement::Statement + */ +AST::Statement::Statement(void) +{ + // ... +} + +/** + * @brief AST::Statement::~Statement + */ +AST::Statement::~Statement() +{ + // ... +} diff --git a/src/AST/Statement.h b/src/AST/Statement.h new file mode 100644 index 0000000..99bbb63 --- /dev/null +++ b/src/AST/Statement.h @@ -0,0 +1,40 @@ +#pragma once + +#include "../Node.h" + +namespace AST +{ + +class Statement : public Node +{ + +public: + + enum EStatementType + { + BLOCK, + IF, + WHILE, + DO, + FOR, + EXPRESSION_LIST, + DECLARATION_LIST, + RETURN, + SELECTION, + ITERATION, + JUMP, + }; + + explicit Statement (void); + virtual ~Statement (void); + + virtual ENodeType getNodeType (void) const { return(STATEMENT); } + + virtual EStatementType getStatementType (void) const = 0; + +private: + + // ... +}; + +} diff --git a/src/AST/Statements/CompoundStatement.cpp b/src/AST/Statements/CompoundStatement.cpp new file mode 100644 index 0000000..4716563 --- /dev/null +++ b/src/AST/Statements/CompoundStatement.cpp @@ -0,0 +1,18 @@ +#include "CompoundStatement.h" + +/** + * @brief AST::Block::Block + */ +AST::CompoundStatement::CompoundStatement(const std::vector & children) +: m_aChild(children) +{ + // ... +} + +/** + * @brief AST::Block::~Block + */ +AST::CompoundStatement::~CompoundStatement(void) +{ + // ... +} diff --git a/src/AST/Statements/CompoundStatement.h b/src/AST/Statements/CompoundStatement.h new file mode 100644 index 0000000..724da42 --- /dev/null +++ b/src/AST/Statements/CompoundStatement.h @@ -0,0 +1,27 @@ +#pragma once + +#include "../Statement.h" + +#include + +namespace AST +{ + +class CompoundStatement : public Statement +{ + +public: + + explicit CompoundStatement (const std::vector & children); + virtual ~CompoundStatement (void); + + virtual EStatementType getStatementType (void) const { return(BLOCK); } + + const std::vector & getChildren (void) const { return(m_aChild); } + +private: + + std::vector m_aChild; +}; + +} diff --git a/src/AST/Statements/DeclarationList.cpp b/src/AST/Statements/DeclarationList.cpp new file mode 100644 index 0000000..a22b6f0 --- /dev/null +++ b/src/AST/Statements/DeclarationList.cpp @@ -0,0 +1,17 @@ +#include "DeclarationList.h" + +/** + * @brief AST::DeclarationList::DeclarationList + */ +AST::DeclarationList::DeclarationList(const Declaration * pDecl) +{ + m_aDeclarations.push_back(pDecl); +} + +/** + * @brief AST::DeclarationList::~DeclarationList + */ +AST::DeclarationList::~DeclarationList(void) +{ + // ... +} diff --git a/src/AST/Statements/DeclarationList.h b/src/AST/Statements/DeclarationList.h new file mode 100644 index 0000000..b307b32 --- /dev/null +++ b/src/AST/Statements/DeclarationList.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../Statement.h" + +#include + +namespace AST +{ + +class Declaration; + +class DeclarationList : public Statement +{ + +public: + + explicit DeclarationList (const Declaration * pExpr); + virtual ~DeclarationList (void); + + virtual EStatementType getStatementType (void) const { return(DECLARATION_LIST); } + + const std::vector & getDeclaration(void) const { return(m_aDeclarations); } + +private: + + std::vector m_aDeclarations; +}; + +} diff --git a/src/AST/Statements/ExpressionList.cpp b/src/AST/Statements/ExpressionList.cpp new file mode 100644 index 0000000..1b08be3 --- /dev/null +++ b/src/AST/Statements/ExpressionList.cpp @@ -0,0 +1,17 @@ +#include "ExpressionList.h" + +/** + * @brief AST::ExpressionList::ExpressionList + */ +AST::ExpressionList::ExpressionList(const Expression * pExpr) +{ + m_aExpressions.push_back(pExpr); +} + +/** + * @brief AST::ExpressionList::~ExpressionList + */ +AST::ExpressionList::~ExpressionList(void) +{ + // ... +} diff --git a/src/AST/Statements/ExpressionList.h b/src/AST/Statements/ExpressionList.h new file mode 100644 index 0000000..5fc9bea --- /dev/null +++ b/src/AST/Statements/ExpressionList.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../Statement.h" + +#include + +namespace AST +{ + +class Expression; + +class ExpressionList : public Statement +{ + +public: + + explicit ExpressionList (const Expression * pExpr); + virtual ~ExpressionList (void); + + virtual EStatementType getStatementType (void) const { return(EXPRESSION_LIST); } + + const std::vector & getExpressions(void) const { return(m_aExpressions); } + +private: + + std::vector m_aExpressions; +}; + +} diff --git a/src/AST/Statements/IterationStatement.cpp b/src/AST/Statements/IterationStatement.cpp new file mode 100644 index 0000000..90d5487 --- /dev/null +++ b/src/AST/Statements/IterationStatement.cpp @@ -0,0 +1,18 @@ +#include "IterationStatement.h" + +/** + * @brief AST::IterationStatement::IterationStatement + */ +AST::IterationStatement::IterationStatement(EIterationStatementType type) +: m_eType(type) +{ + // ... +} + +/** + * @brief AST::IterationStatement::~IterationStatement + */ +AST::IterationStatement::~IterationStatement(void) +{ + // ... +} diff --git a/src/AST/Statements/IterationStatement.h b/src/AST/Statements/IterationStatement.h new file mode 100644 index 0000000..f5270a2 --- /dev/null +++ b/src/AST/Statements/IterationStatement.h @@ -0,0 +1,30 @@ +#pragma once + +#include "../Statement.h" + +namespace AST +{ + +class IterationStatement : public Statement +{ + +public: + + enum EIterationStatementType + { + WHILE, + DO, + FOR, + }; + + explicit IterationStatement (EIterationStatementType type); + virtual ~IterationStatement (void); + + virtual EStatementType getStatementType (void) const { return(ITERATION); } + +private: + + EIterationStatementType m_eType; +}; + +} diff --git a/src/AST/Statements/IterationStatements/DoWhile.cpp b/src/AST/Statements/IterationStatements/DoWhile.cpp new file mode 100644 index 0000000..87cf298 --- /dev/null +++ b/src/AST/Statements/IterationStatements/DoWhile.cpp @@ -0,0 +1,19 @@ +#include "DoWhile.h" + +/** + * @brief AST::DoWhile::DoWhile + */ +AST::DoWhile::DoWhile(const Expression * pCondition, const Statement * stmt) +: m_pCondition(pCondition) +, m_pChild(stmt) +{ + // ... +} + +/** + * @brief AST::DoWhile::~DoWhile + */ +AST::DoWhile::~DoWhile() +{ + // ... +} diff --git a/src/AST/Statements/IterationStatements/DoWhile.h b/src/AST/Statements/IterationStatements/DoWhile.h new file mode 100644 index 0000000..0189fdb --- /dev/null +++ b/src/AST/Statements/IterationStatements/DoWhile.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../IterationStatement.h" + +namespace AST +{ + +class Expression; + +class DoWhile : public Statement +{ + +public: + + explicit DoWhile (const Expression * pCondition, const Statement * stmt); + virtual ~DoWhile (void); + + virtual EStatementType getStatementType (void) const { return(DO); } + + const Expression * getCondition (void) const { return(m_pCondition); } + const Statement * getChild (void) const { return(m_pChild); } + +private: + + const Expression * m_pCondition; + const Statement * m_pChild; +}; + +} diff --git a/src/AST/Statements/IterationStatements/For.cpp b/src/AST/Statements/IterationStatements/For.cpp new file mode 100644 index 0000000..24c0dc3 --- /dev/null +++ b/src/AST/Statements/IterationStatements/For.cpp @@ -0,0 +1,21 @@ +#include "For.h" + +/** + * @brief AST::For::For + */ +AST::For::For(const Node * pInit, const Expression * pCondition, const Expression * pUpdate, const Statement * stmt) +: m_pInit(pInit) +, m_pCondition(pCondition) +, m_pUpdate(pUpdate) +, m_pChild(stmt) +{ + // ... +} + +/** + * @brief AST::For::~For + */ +AST::For::~For() +{ + // ... +} diff --git a/src/AST/Statements/IterationStatements/For.h b/src/AST/Statements/IterationStatements/For.h new file mode 100644 index 0000000..ccdf0cd --- /dev/null +++ b/src/AST/Statements/IterationStatements/For.h @@ -0,0 +1,37 @@ +#pragma once + +#include "../IterationStatement.h" + +#include + +namespace AST +{ + +class Expression; + +class For : public Statement +{ + +public: + + explicit For (const Node * pInit, const Expression * pCondition, const Expression * pUpdate, const Statement * stmt); + virtual ~For (void); + + virtual EStatementType getStatementType (void) const { return(FOR); } + + const Node * getInit (void) const { return(m_pInit); } + const Expression * getCondition (void) const { return(m_pCondition); } + const Expression * getUpdate (void) const { return(m_pUpdate); } + + const Statement * getChild (void) const { return(m_pChild); } + +private: + + const Node * m_pInit; + const Expression * m_pCondition; + const Expression * m_pUpdate; // ExpressionList + + const Statement * m_pChild; +}; + +} diff --git a/src/AST/Statements/IterationStatements/While.cpp b/src/AST/Statements/IterationStatements/While.cpp new file mode 100644 index 0000000..8ea8be8 --- /dev/null +++ b/src/AST/Statements/IterationStatements/While.cpp @@ -0,0 +1,19 @@ +#include "While.h" + +/** + * @brief AST::While::While + */ +AST::While::While(const Expression * pCondition, const Statement * stmt) +: m_pCondition(pCondition) +, m_pChild(stmt) +{ + // ... +} + +/** + * @brief AST::While::~While + */ +AST::While::~While() +{ + // ... +} diff --git a/src/AST/Statements/IterationStatements/While.h b/src/AST/Statements/IterationStatements/While.h new file mode 100644 index 0000000..20f725d --- /dev/null +++ b/src/AST/Statements/IterationStatements/While.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../IterationStatement.h" + +namespace AST +{ + +class Expression; + +class While : public Statement +{ + +public: + + explicit While (const Expression * pCondition, const Statement * stmt); + virtual ~While (void); + + virtual EStatementType getStatementType (void) const { return(WHILE); } + + const Expression * getCondition (void) const { return(m_pCondition); } + const Statement * getChild (void) const { return(m_pChild); } + +private: + + const Expression * m_pCondition; + const Statement * m_pChild; +}; + +} diff --git a/src/AST/Statements/JumpStatement.cpp b/src/AST/Statements/JumpStatement.cpp new file mode 100644 index 0000000..17723f2 --- /dev/null +++ b/src/AST/Statements/JumpStatement.cpp @@ -0,0 +1,18 @@ +#include "JumpStatement.h" + +/** + * @brief AST::JumpStatement::JumpStatement + */ +AST::JumpStatement::JumpStatement(EJumpStatementType type) +: m_eType(type) +{ + // ... +} + +/** + * @brief AST::JumpStatement::~JumpStatement + */ +AST::JumpStatement::~JumpStatement(void) +{ + // ... +} diff --git a/src/AST/Statements/JumpStatement.h b/src/AST/Statements/JumpStatement.h new file mode 100644 index 0000000..f6afe16 --- /dev/null +++ b/src/AST/Statements/JumpStatement.h @@ -0,0 +1,31 @@ +#pragma once + +#include "../Statement.h" + +namespace AST +{ + +class JumpStatement : public Statement +{ + +public: + + enum EJumpStatementType + { + BREAK, + CONTINUE, + RETURN, + GOTO + }; + + explicit JumpStatement (EJumpStatementType type); + virtual ~JumpStatement (void); + + virtual EStatementType getStatementType (void) const { return(JUMP); } + +private: + + EJumpStatementType m_eType; +}; + +} diff --git a/src/AST/Statements/JumpStatements/Return.cpp b/src/AST/Statements/JumpStatements/Return.cpp new file mode 100644 index 0000000..e890b33 --- /dev/null +++ b/src/AST/Statements/JumpStatements/Return.cpp @@ -0,0 +1,18 @@ +#include "Return.h" + +/** + * @brief AST::Return::Return + */ +AST::Return::Return(const AST::Expression * pReturnExpr) +: m_pReturnExpression(pReturnExpr) +{ + // ... +} + +/** + * @brief AST::Return::~Return + */ +AST::Return::~Return(void) +{ + // ... +} diff --git a/src/AST/Statements/JumpStatements/Return.h b/src/AST/Statements/JumpStatements/Return.h new file mode 100644 index 0000000..bb66fcc --- /dev/null +++ b/src/AST/Statements/JumpStatements/Return.h @@ -0,0 +1,25 @@ +#pragma once + +#include "../JumpStatement.h" + +namespace AST +{ + +class Expression; + +class Return : public Statement +{ + +public: + + explicit Return (const AST::Expression * pReturnExpr); + virtual ~Return (void); + + virtual EStatementType getStatementType (void) const { return(RETURN); } + +private: + + const AST::Expression * m_pReturnExpression; +}; + +} diff --git a/src/AST/Statements/SelectionStatement.cpp b/src/AST/Statements/SelectionStatement.cpp new file mode 100644 index 0000000..a65a29d --- /dev/null +++ b/src/AST/Statements/SelectionStatement.cpp @@ -0,0 +1,18 @@ +#include "SelectionStatement.h" + +/** + * @brief AST::SelectionStatement::SelectionStatement + */ +AST::SelectionStatement::SelectionStatement(ESelectionStatementType type) +: m_eType(type) +{ + // ... +} + +/** + * @brief AST::SelectionStatement::~SelectionStatement + */ +AST::SelectionStatement::~SelectionStatement(void) +{ + // ... +} diff --git a/src/AST/Statements/SelectionStatement.h b/src/AST/Statements/SelectionStatement.h new file mode 100644 index 0000000..da99d74 --- /dev/null +++ b/src/AST/Statements/SelectionStatement.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../Statement.h" + +namespace AST +{ + +class SelectionStatement : public Statement +{ + +public: + + enum ESelectionStatementType + { + IF, + SWITCH, + }; + + explicit SelectionStatement (ESelectionStatementType type); + virtual ~SelectionStatement (void); + + virtual EStatementType getStatementType (void) const { return(ITERATION); } + +private: + + ESelectionStatementType m_eType; +}; + +} diff --git a/src/AST/Statements/SelectionStatements/If.cpp b/src/AST/Statements/SelectionStatements/If.cpp new file mode 100644 index 0000000..9343094 --- /dev/null +++ b/src/AST/Statements/SelectionStatements/If.cpp @@ -0,0 +1,19 @@ +#include "If.h" + +/** + * @brief AST::If::If + */ +AST::If::If(const Expression * pCondition, const Statement * stmt) +: m_pCondition(pCondition) +, m_pChild(stmt) +{ + // ... +} + +/** + * @brief AST::If::~If + */ +AST::If::~If() +{ + // ... +} diff --git a/src/AST/Statements/SelectionStatements/If.h b/src/AST/Statements/SelectionStatements/If.h new file mode 100644 index 0000000..f0e9acc --- /dev/null +++ b/src/AST/Statements/SelectionStatements/If.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../SelectionStatement.h" + +namespace AST +{ + +class Expression; + +class If : public Statement +{ + +public: + + explicit If (const Expression * pCondition, const Statement * stmt); + virtual ~If (void); + + virtual EStatementType getStatementType (void) const { return(IF); } + + const Expression * getCondition (void) const { return(m_pCondition); } + const Statement * getChild (void) const { return(m_pChild); } + +private: + + const Expression * m_pCondition; + const Statement * m_pChild; +}; + +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..a831be3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) + +file(GLOB_RECURSE sl_files SL/*.cpp SL/*.h) +file(GLOB_RECURSE ast_files AST/*.cpp AST/*.h) +file(GLOB_RECURSE ir_files IR/*.cpp IR/*.h) + +add_library(SL++ Lexer.cpp Lexer.h Parser.cpp Parser_declarations.cpp Parser_statements.cpp Parser_templates.cpp Parser.h Node.cpp Node.h Generator.cpp Generator.h str.cpp str.h ${sl_files} ${ast_files} ${ir_files}) diff --git a/src/Generator.cpp b/src/Generator.cpp new file mode 100644 index 0000000..3b6de84 --- /dev/null +++ b/src/Generator.cpp @@ -0,0 +1 @@ +#include "Generator.h" \ No newline at end of file diff --git a/src/Generator.h b/src/Generator.h new file mode 100644 index 0000000..8e0465f --- /dev/null +++ b/src/Generator.h @@ -0,0 +1,4 @@ +#pragma once + +#include "IR/GLSL/generator.h" +#include "IR/SPIR-V/generator.h" diff --git a/src/IR/GLSL/generator.cpp b/src/IR/GLSL/generator.cpp new file mode 100644 index 0000000..e7b9256 --- /dev/null +++ b/src/IR/GLSL/generator.cpp @@ -0,0 +1,553 @@ +#include "generator.h" + +#include "../../Parser.h" + +#if 1 // this should be disabled in prod +#define LINE_BREAK "\n" +#else +#define LINE_BREAK +#endif + +namespace Generator +{ + +void GLSL::print(const AST::Unary * pExpr) +{ + switch (pExpr->getUnaryType()) + { + case AST::Unary::PLUS: + { + printf("+ "); + print_expression(pExpr->getExpression()); + } + break; + + case AST::Unary::MINUS: + { + printf("- "); + print_expression(pExpr->getExpression()); + } + break; + } +} + +void GLSL::print(const AST::Binary * pExpr) +{ + switch (pExpr->getBinaryType()) + { + case AST::Binary::ADDITION: + { + print_expression(pExpr->getLeftExpression()); + printf(" + "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::SUBTRACTION: + { + print_expression(pExpr->getLeftExpression()); + printf(" - "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::MULTIPLICATON: + { + print_expression(pExpr->getLeftExpression()); + printf(" * "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::DIVISION: + { + print_expression(pExpr->getLeftExpression()); + printf(" / "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::MODULO: + { + print_expression(pExpr->getLeftExpression()); + printf(" % "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::EQ: + { + print_expression(pExpr->getLeftExpression()); + printf(" == "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::NEQ: + { + print_expression(pExpr->getLeftExpression()); + printf(" != "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::GT: + { + print_expression(pExpr->getLeftExpression()); + printf(" > "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::GEQ: + { + print_expression(pExpr->getLeftExpression()); + printf(" >= "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::LT: + { + print_expression(pExpr->getLeftExpression()); + printf(" < "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::LEQ: + { + print_expression(pExpr->getLeftExpression()); + printf(" <= "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::BASIC_ASSIGNMENT: + { + print_expression(pExpr->getLeftExpression()); + printf(" = "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::ADDITION_ASSIGNMENT: + { + print_expression(pExpr->getLeftExpression()); + printf(" += "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::SUBTRACTION_ASSIGNMENT: + { + print_expression(pExpr->getLeftExpression()); + printf(" -= "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::MULTIPLICATION_ASSIGNMENT: + { + print_expression(pExpr->getLeftExpression()); + printf(" *= "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::DIVISION_ASSIGNMENT: + { + print_expression(pExpr->getLeftExpression()); + printf(" /= "); + print_expression(pExpr->getRightExpression()); + } + break; + + case AST::Binary::MODULO_ASSIGNMENT: + { + print_expression(pExpr->getLeftExpression()); + printf(" %= "); + print_expression(pExpr->getRightExpression()); + } + break; + } +} + +void GLSL::print_constant(const AST::Constant * pConstant) +{ + switch(pConstant->getNumberType()) + { + case AST::Constant::CHAR: + { + printf("%i", pConstant->getValueAsChar()); + } + break; + + case AST::Constant::SHORT: + { + printf("%i", pConstant->getValueAsChar()); + } + break; + + case AST::Constant::INTEGER: + { + printf("%i", pConstant->getValueAsInt()); + } + break; + + case AST::Constant::FLOAT: + { + printf("%f", pConstant->getValueAsFloat()); + } + break; + + case AST::Constant::DOUBLE: + { + printf("%f", pConstant->getValueAsDouble()); + } + break; + } +} + +void GLSL::print_variable(const AST::Variable * pVariable) +{ + printf("%s", pVariable->getName().c_str()); +} + +void GLSL::print_call(const AST::Call * pCall) +{ + printf("%s(", pCall->getFunctionName().c_str()); + + int i = 0; + for (const AST::Expression * pExpr : pCall->getArguments()) + { + if (i > 0) + { + printf(", "); + } + + print_expression(pExpr); + ++i; + } + + printf(")"); +} + +void GLSL::print_expression(const AST::Expression * pExpr) +{ + if (nullptr != pExpr) + { + switch (pExpr->getExpressionType()) + { + case AST::Expression::CALL: + { + const AST::Call * pCall = static_cast(pExpr); + + print_call(pCall); + } + break; + + case AST::Expression::VARIABLE: + { + const AST::Variable * pVariable = static_cast(pExpr); + + print_variable(pVariable); + } + break; + + case AST::Expression::CONSTANT: + { + const AST::Constant * pConstant = static_cast(pExpr); + + print_constant(pConstant); + } + break; + + case AST::Expression::UNARY: + { + const AST::Unary * pUnaryExpr = static_cast(pExpr); + + print(pUnaryExpr); + } + break; + + case AST::Expression::BINARY: + { + const AST::Binary * pBinaryExpr = static_cast(pExpr); + + print(pBinaryExpr); + } + break; + } + } + else + { + printf(" nullexpr"); + } +} + +void GLSL::print_statement(const AST::Statement * pStatement) +{ + if (nullptr == pStatement) return; // should be an assert !!! + + switch (pStatement->getStatementType()) + { + case AST::Statement::DECLARATION_LIST: + { + const AST::DeclarationList * pAssignement = static_cast(pStatement); + + for (const AST::Declaration * pDeclaration : pAssignement->getDeclaration()) + { + print_definition(pDeclaration); + } + } + break; + + case AST::Statement::BLOCK: + { + const AST::CompoundStatement * pBlock = static_cast(pStatement); + + printf("{" LINE_BREAK); + + for (const AST::Statement * pChild : pBlock->getChildren()) + { + print_statement(pChild); + } + + printf("}" LINE_BREAK); + } + break; + + case AST::Statement::EXPRESSION_LIST: + { + const AST::ExpressionList * pExprList = static_cast(pStatement); + + for (const AST::Expression * pExpr : pExprList->getExpressions()) + { + print_expression(pExpr); + printf(";" LINE_BREAK); + } + } + break; + + case AST::Statement::RETURN: + { + //const AST::Return * pReturn = static_cast(pStatement); + + printf("return;" LINE_BREAK); + } + break; + + case AST::Statement::JUMP: + { + //const AST::Return * pReturn = static_cast(pStatement); + + printf("break;" LINE_BREAK); + } + break; + + case AST::Statement::IF: + { + const AST::If * pIf = static_cast(pStatement); + + printf("if ("); + print_expression(pIf->getCondition()); + printf(") " LINE_BREAK); + + printf("{" LINE_BREAK); + print_statement(pIf->getChild()); + printf("}" LINE_BREAK); + } + break; + + case AST::Statement::WHILE: + { + const AST::While * pWhile = static_cast(pStatement); + + printf("while ("); + print_expression(pWhile->getCondition()); + printf(") " LINE_BREAK); + + printf("{" LINE_BREAK); + print_statement(pWhile->getChild()); + printf("}" LINE_BREAK); + } + break; + + case AST::Statement::DO: + { + const AST::DoWhile * pDoWhile = static_cast(pStatement); + + printf("do" LINE_BREAK); + + printf("{" LINE_BREAK); + print_statement(pDoWhile->getChild()); + printf("}"); // NO LINE_BREAK HERE + + printf("while ("); + print_expression(pDoWhile->getCondition()); + printf(");" LINE_BREAK); + } + break; + + case AST::Statement::FOR: + { + const AST::For * pFor = static_cast(pStatement); + + printf("for ("); + print_recurse(pFor->getInit()); + printf("; "); + print_expression(pFor->getCondition()); + printf("; "); + print_expression(pFor->getUpdate()); + printf(")" LINE_BREAK); + + printf("{" LINE_BREAK); + print_statement(pFor->getChild()); + printf("}" LINE_BREAK); + } + break; + } +} + +void GLSL::print_definition(const AST::Declaration * pDefinition) +{ + if (nullptr == pDefinition) return; // should be an assert !!! + + switch (pDefinition->getDeclarationType()) + { + case AST::Declaration::NAMESPACE: + { + const AST::NamespaceDefinition * pNamespace = static_cast(pDefinition); + + printf("namespace %s" LINE_BREAK, pNamespace->getName().c_str()); + + printf("{" LINE_BREAK); + + for (const AST::Node * pNode : pNamespace->getNodes()) + { + print_recurse(pNode); + } + + printf("}" LINE_BREAK); + } + break; + + case AST::Declaration::STRUCTURE: + { + const AST::Structure * pStruct = static_cast(pDefinition); + + printf("struct %s" LINE_BREAK, pStruct->getName().c_str()); + + printf("{" LINE_BREAK); + + for (const AST::Node * pNode : pStruct->getNodes()) + { + print_recurse(pNode); + } + + printf("};" LINE_BREAK); + } + break; + + case AST::Declaration::CLASS: + { + const AST::Class * pClass = static_cast(pDefinition); + + printf("class %s" LINE_BREAK, pClass->getName().c_str()); + + printf("{" LINE_BREAK); + + for (const AST::Node * pNode : pClass->getNodes()) + { + print_recurse(pNode); + } + + printf("};" LINE_BREAK); + } + break; + + case AST::Declaration::FUNCTION: + { + const AST::FunctionDefinition * pFun = static_cast(pDefinition); + + printf("%s %s(", pFun->getReturnType().c_str(), pFun->getName().c_str()); + + int i = 0; + for (const AST::Declaration * pDecl : pFun->getParameters()) + { + if (i > 0) + { + printf(", "); + } + + print_definition(pDecl); + ++i; + } + + printf(")" LINE_BREAK); + + printf("{" LINE_BREAK); + + for (const AST::Node * pNode : pFun->getNodes()) + { + print_recurse(pNode); + } + + printf("}" LINE_BREAK); + } + break; + + case AST::Declaration::SIMPLE: + { + const AST::SimpleDeclaration * pVar = static_cast(pDefinition); + + printf("%s %s", pVar->getVariableType().c_str(), pVar->getVariableName().c_str()); + + if (nullptr != pVar->getExpression()) + { + printf(" = "); + print_expression(pVar->getExpression()); + } + + printf(";" LINE_BREAK); + } + break; + } +} + +void GLSL::print_recurse(const AST::Node * pNode) +{ + switch (pNode->getNodeType()) + { + case AST::Node::DECLARATION: + { + print_definition(static_cast(pNode)); + } + break; + + case AST::Node::EXPRESSION: + { + print_expression(static_cast(pNode)); + } + break; + + case AST::Node::STATEMENT: + { + print_statement(static_cast(pNode)); + } + break; + } +} + +void GLSL::print_ast(const std::vector & aNodes) +{ + for (const AST::Node * pNode : aNodes) + { + print_recurse(pNode); + } + + printf("\n"); +} + +} diff --git a/src/IR/GLSL/generator.h b/src/IR/GLSL/generator.h new file mode 100644 index 0000000..21d32c7 --- /dev/null +++ b/src/IR/GLSL/generator.h @@ -0,0 +1,41 @@ +#pragma once + +namespace AST +{ + class Node; + + class Statement; + class Declaration; + + class Expression; + class Constant; + class Variable; + class Call; + class Unary; + class Binary; +} + +#include + +namespace Generator +{ + + struct GLSL + { + static void print (const AST::Unary * pExpr); + static void print (const AST::Binary * pExpr); + + static void print_constant (const AST::Constant * pConstant); + static void print_variable (const AST::Variable * pVariable); + static void print_call (const AST::Call * pCall); + + static void print_expression (const AST::Expression * pExpr); + + static void print_statement (const AST::Statement * pStatement); + static void print_definition (const AST::Declaration * pDefinition); + + static void print_recurse(const AST::Node * pCurrentNode); + static void print_ast(const std::vector & aNodes); + }; + +} diff --git a/src/IR/SPIR-V/generator.cpp b/src/IR/SPIR-V/generator.cpp new file mode 100644 index 0000000..32ec67f --- /dev/null +++ b/src/IR/SPIR-V/generator.cpp @@ -0,0 +1,3 @@ +#include "generator.h" + +#include diff --git a/src/IR/SPIR-V/generator.h b/src/IR/SPIR-V/generator.h new file mode 100644 index 0000000..e69de29 diff --git a/src/Lexer.cpp b/src/Lexer.cpp new file mode 100644 index 0000000..a5e28b1 --- /dev/null +++ b/src/Lexer.cpp @@ -0,0 +1,570 @@ +#include "Lexer.h" + +#include "SL/Identifier.h" +#include "SL/Keyword.h" +#include "SL/Number.h" +#include "SL/Separator.h" +#include "SL/Symbol.h" +#include "SL/Endmark.h" + +#include +#include +#include + +#include "str.h" + +/** + * @brief Lexer::Lexer + * @param buffer + */ +Lexer::Lexer(const char * buffer) +: m_pBuffer(buffer) +, m_pCurrent(buffer) +, m_uiCurrentLine(1) +, m_uiCurrentColumn(1) +, m_pLast(nullptr) +{ + // ... +} + +/** + * @brief Lexer::~Lexer + */ +Lexer::~Lexer(void) +{ + // ... +} + +/** + * @brief Lexer::next + * @return + */ +SL::Token * Lexer::next(void) +{ + if (nullptr != m_pLast) + { + ///delete m_pLast; + m_pLast = nullptr; + } + + skipWhiteSpaces(); + + if (*m_pCurrent == '\0') + { + // do not increment m_pCurrent ! + m_pLast = new SL::Endmark; + return(m_pLast); + } + + if (isNumber(*m_pCurrent)) + { + m_pLast = parseNumber(); + return(m_pLast); + } + + if (isLetter(*m_pCurrent)) + { + m_pLast = parseWord(); + return(m_pLast); + } + + m_pLast = parseOther(); + return(m_pLast); +} + +/** + * @brief Lexer::skip + * @param c + * @return + */ +bool Lexer::skip(const char c) +{ + if (c != *m_pCurrent) + { + return(false); + } + + read(); + return(true); +} + +/** + * @brief Lexer::skipNumbers + */ +void Lexer::skipNumbers(void) +{ + while (isNumber(*m_pCurrent)) + { + read(); + } +} + +/** + * @brief Lexer::skipLetters + */ +void Lexer::skipLetters(void) +{ + while (isLetter(*m_pCurrent)) + { + read(); + } +} + +/** + * @brief Lexer::skipAlphaNum + */ +void Lexer::skipAlphaNum(void) +{ + while (isNumber(*m_pCurrent) || isLetter(*m_pCurrent)) + { + read(); + } +} + +/** + * @brief Lexer::skipWhiteSpaces + */ +void Lexer::skipWhiteSpaces(void) +{ + while (isWhiteSpace(*m_pCurrent) || isLineBreak(*m_pCurrent)) + { + if (isLineBreak(*m_pCurrent)) + { + m_uiCurrentLine++; + m_uiCurrentColumn = 0; + } + + read(); + } +} + +/** + * @brief Lexer::parseNumber + */ +SL::Token * Lexer::parseNumber(void) +{ + const char * pStart = m_pCurrent; + + int base = 10; + + if (skip('0')) + { + if (skip('b')) + { + if (!isBinaryNumber(*m_pCurrent)) + { + assert(false); + return(nullptr); // ERR + } + + base = 2; + parseBinary(); + } + else if (skip('x') || skip('X')) + { + if (!isHexaNumber(*m_pCurrent)) + { + assert(false); + return(nullptr); // ERR + } + + base = 16; + parseHexa(); + } + else + { + base = 8; + parseOctal(); // 0 is 0 in Octal + } + } + else + { + skipNumbers(); + } + + if (isLetter(*m_pCurrent)) + { + // TODO + // - parse ALL remaining digit and compare with u, l, ul, ll, ull etc ... + // - if comparison fail => "invalid suffix" + + if (skip('u') || skip('U')) + { + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + unsigned int v = strtoul(tmp, NULL, base); + return(new SL::Number(v)); // UNSIGNED INT + } + + if (skip('l') || skip('L')) + { + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + long v = strtoul(tmp, NULL, base); + return(new SL::Number(v)); // LONG + } + + if (skip('e') || skip('E')) + { + if (!skip('-')) + { + skip('+'); + } + + if (!isNumber(*m_pCurrent)) + { + assert(false); + return(nullptr); // ERR + } + + skipNumbers(); + + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + float v = strtof(tmp, NULL); + return(new SL::Number(v)); + } + + assert(false); + return(nullptr); // ERR invalid suffix + } + + if (skip('.')) + { + skipNumbers(); + + if (skip('e') || skip('E')) + { + if (!skip('-')) + { + skip('+'); + } + + if (!isNumber(*m_pCurrent)) + { + assert(false); + return(nullptr); // ERR + } + + skipNumbers(); + } + + if (isLetter(*m_pCurrent)) + { + if (skip('f') || skip('F')) + { + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + float v = strtof(tmp, NULL); + return(new SL::Number(v)); // FLOAT + } + + if (skip('d') || skip('D')) + { + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + double v = strtod(tmp, NULL); + return(new SL::Number(v)); // DOUBLE + } + + assert(false); + return(nullptr); // ERR invalid suffix + } + + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + double v = strtod(tmp, NULL); + return(new SL::Number(v)); // DOUBLE + } + + char tmp [256]; + memset(tmp, 0, 256*sizeof(char)); + strncpy(tmp, pStart, (m_pCurrent - pStart)); + int v = strtol(tmp, NULL, base); + return(new SL::Number(v)); // INT +} + +/** + * @brief Lexer::parseWord + * @return + */ +SL::Token * Lexer::parseWord(void) +{ + const char * pStart = m_pCurrent; + + skipAlphaNum(); + + size_t s = (m_pCurrent - pStart); + + for (unsigned int i = 0; i < SL::Keyword::Count; ++i) + { + if (strlen(SL::Keyword::Strings[i]) == s && !strncmp(pStart, SL::Keyword::Strings[i], s)) + { + return(new SL::Keyword(SL::Keyword::EKeyword(i))); + } + } + + char name [256]; + memset(name, 0, 256*sizeof(char)); + strncpy(name, pStart, s); + return(new SL::Identifier(name)); +} + +/** + * @brief Lexer::parseOperator + * @return + */ +SL::Token * Lexer::parseOther(void) +{ + switch (*m_pCurrent) + { + case '(': + { + read(); + return(new SL::Separator(SL::Separator::LEFT_PARENTHESIS)); + } + break; + + case ')': + { + read(); + return(new SL::Separator(SL::Separator::RIGHT_PARENTHESIS)); + } + break; + + case '{': + { + read(); + return(new SL::Separator(SL::Separator::LEFT_CURLY_BRACKET)); + } + break; + + case '}': + { + read(); + return(new SL::Separator(SL::Separator::RIGHT_CURLY_BRACKET)); + } + break; + + case '[': + { + read(); + return(new SL::Separator(SL::Separator::LEFT_SQUARE_BRACKET)); + } + break; + + case ']': + { + read(); + return(new SL::Separator(SL::Separator::RIGHT_SQUARE_BRACKET)); + } + break; + + case '.': + { + read(); + return(new SL::Separator(SL::Separator::DOT)); + } + break; + + case ',': + { + read(); + return(new SL::Separator(SL::Separator::COMMA)); + } + break; + + case ';': + { + read(); + return(new SL::Separator(SL::Separator::SEMICOLON)); + } + break; + + case '+': + { + read(); +#if 0 + if (skip('+')) + { + return(new SL::AssignementOperator(SL::AssignementOperator::INCREMENT)); + } +#endif + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::PLUS)); + } + break; + + case '-': + { + read(); +#if 0 + if (skip('-')) + { + return(new SL::AssignementOperator(SL::AssignementOperator::DECREMENT)); + } +#endif + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::MINUS_EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::MINUS)); + } + break; + + case '*': + { + read(); + + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::ASTERISK)); + } + + return(new SL::Symbol(SL::Symbol::ASTERISK_EQUAL)); + } + break; + + case '/': + { + read(); + + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::SLASH_EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::SLASH)); + } + break; + + case '%': + { + read(); + + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::PERCENT_EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::PERCENT)); + } + break; + + case '=': + { + read(); + + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::EQUAL_EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::EQUAL)); + } + break; + + case '<': + { + read(); + + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::LT_EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::LT)); + } + break; + + case '>': + { + read(); + + if (skip('=')) + { + return(new SL::Symbol(SL::Symbol::GT_EQUAL)); + } + + return(new SL::Symbol(SL::Symbol::GT)); + } + break; + + + default: + { + return(nullptr); + } + } +} + +/** + * @brief Lexer::parseHexa + */ +void Lexer::parseHexa(void) +{ + if (!isHexaNumber(*m_pCurrent)) + { + return; // ERR + } + + do + { + read(); + } + while (isHexaNumber(*m_pCurrent)); +} + +/** + * @brief Lexer::parseBinary + */ +void Lexer::parseBinary(void) +{ + if (!isBinaryNumber(*m_pCurrent)) + { + return; // ERR + } + + do + { + read(); + } + while (isBinaryNumber(*m_pCurrent)); +} + +/** + * @brief Lexer::parseOctal + */ +void Lexer::parseOctal(void) +{ + if (!isOctalNumber(*m_pCurrent)) + { + return; // ERR + } + + do + { + read(); + } + while (isOctalNumber(*m_pCurrent)); +} + +/** + * @brief Lexer::read + */ +void Lexer::read(void) +{ + ++m_pCurrent; + ++m_uiCurrentColumn; +} diff --git a/src/Lexer.h b/src/Lexer.h new file mode 100644 index 0000000..1e10000 --- /dev/null +++ b/src/Lexer.h @@ -0,0 +1,46 @@ +#pragma once + +#include "SL/Token.h" + +class Lexer +{ + +public: + + explicit Lexer (const char * buffer); + virtual ~Lexer (void); + + SL::Token * next (void); + + unsigned int getCurrentLine(void) { return(m_uiCurrentLine); } + unsigned int getCurrentColumn(void) { return(m_uiCurrentColumn); } + +protected: + + bool skip (const char c); + + void skipNumbers (void); + void skipLetters (void); + void skipAlphaNum (void); + void skipWhiteSpaces (void); + + SL::Token * parseNumber (void); + SL::Token * parseWord (void); + SL::Token * parseOther (void); + + void parseHexa (void); + void parseBinary (void); + void parseOctal (void); + +private: + + void read (void); + + const char * m_pBuffer; + const char * m_pCurrent; + + unsigned int m_uiCurrentLine; + unsigned int m_uiCurrentColumn; + + SL::Token * m_pLast; +}; diff --git a/src/Node.cpp b/src/Node.cpp new file mode 100644 index 0000000..0c2b14d --- /dev/null +++ b/src/Node.cpp @@ -0,0 +1 @@ +#include "Node.h" diff --git a/src/Node.h b/src/Node.h new file mode 100644 index 0000000..1ea4a76 --- /dev/null +++ b/src/Node.h @@ -0,0 +1,18 @@ +#pragma once + +namespace AST +{ + + struct Node + { + enum ENodeType + { + DECLARATION, + EXPRESSION, + STATEMENT, + }; + + virtual ENodeType getNodeType (void) const = 0; + }; + +} diff --git a/src/Parser.cpp b/src/Parser.cpp new file mode 100644 index 0000000..e5e87c8 --- /dev/null +++ b/src/Parser.cpp @@ -0,0 +1,1009 @@ +#include "Parser.h" + +#include "AST/Expressions/Arithmetic//Addition.h" +#include "AST/Expressions/Arithmetic/Subtraction.h" +#include "AST/Expressions/Arithmetic/Multiplication.h" +#include "AST/Expressions/Arithmetic/Division.h" +#include "AST/Expressions/Arithmetic/Modulo.h" +#include "AST/Expressions/Arithmetic/UnaryPlus.h" +#include "AST/Expressions/Arithmetic/UnaryMinus.h" + +#include "AST/Expressions/Relational/EqualTo.h" +#include "AST/Expressions/Relational/NotEqualTo.h" +#include "AST/Expressions/Relational/GreaterThan.h" +#include "AST/Expressions/Relational/GreaterThanOrEqualTo.h" +#include "AST/Expressions/Relational/LessThan.h" +#include "AST/Expressions/Relational/LessThanOrEqualTo.h" + +#include "AST/Expressions/Assignment/BasicAssignment.h" + +#include +#include + +#define FORCE_FOR_INIT_TO_BE_A_DECLARATION + +/** + * @brief Constructor + * @param buffer : buffer to be parsed + */ +Parser::Parser(const char * buffer) +: m_lexer(buffer) +, m_pNext((SL::Token*)0xDEAD) +{ + // ... +} + +/** + * @brief Destructor + */ +Parser::~Parser(void) +{ + // ... +} + +/** + * @brief Put the next token in m_pNext + */ +void Parser::scan(void) +{ + assert(nullptr != m_pNext); + + if (!m_queueAhead.empty()) + { + m_pNext = m_queueAhead.front(); + m_queueAhead.pop(); + } + else + { + m_pNext = m_lexer.next(); + } + + assert(nullptr != m_pNext); +} + +/** + * @brief Look what will be coming + * @param n : number of token to skip + * @return + */ +SL::Token * Parser::lookAhead(unsigned int n) +{ + SL::Token * r = nullptr; + + for (unsigned int i = 0; i < n; ++i) + { + r = m_lexer.next(); + m_queueAhead.push(r); + } + + return(r); +} + +/** + * @brief Skip an expected token type (throw an error if the type is incorrect) + * @param t + */ +void Parser::skip(SL::Token::EType t) +{ + if (m_pNext->getType() != t) + { + error("Expected something else !"); + } + + scan(); +} + +/** + * @brief Parser::skip + * @param sym + */ +void Parser::skip(SL::Symbol::ESymbol sym) +{ + if (!SL::isSymbol(m_pNext, sym)) + { + error("Expected symbol"); + } + + scan(); +} + +/** + * @brief Skip an expected token type (throw an error if the type is incorrect) + * @param sep + */ +void Parser::skip(SL::Separator::ESeparator sep) +{ + if (!SL::isSeparator(m_pNext, sep)) + { + error("Expected separator"); + } + + scan(); +} + +/** + * @brief Skip an expected token type (throw an error if the type is incorrect) + * @param k + */ +void Parser::skip(SL::Keyword::EKeyword k) +{ + if (!SL::isKeyword(m_pNext, k)) + { + error("Expected keyword"); + } + + scan(); +} + +/** + * @brief Build the Abstract Syntax Tree + * @return true if the build process was succesful + */ +bool Parser::buildAST(void) +{ + scan(); + translation_unit(); + skip(SL::Token::ENDMARK); + + return(true); +} + +/** + * @brief Print an standard formated error message and exit + * @param str : message to be printed + */ +void Parser::error(const char * str) +{ + printf("ERROR (%d:%d) : %s \n", m_lexer.getCurrentLine(), m_lexer.getCurrentColumn(), str); + assert(false); +} + +/** + * @brief Translation unit + * + * translation-unit: + * declaration-seq (opt) + */ +void Parser::translation_unit(void) +{ + // declaration-seq (opt) + while (!SL::isEndmark(m_pNext)) + { + const AST::Declaration * pNode = declaration(); + m_aNodes.push_back(pNode); + } +} + +/** + * @brief used to parse member declaration (a declaration inside class/struct) + */ +const AST::Declaration * Parser::parse_member(void) +{ + if (SL::isIdentifier(m_pNext)) + { + SL::Token * t = lookAhead(2); + + if (SL::isSeparator(t, SL::Separator::LEFT_PARENTHESIS)) + { + const AST::FunctionDefinition * pNode = parse_method(); + return(pNode); + } + else + { + const AST::Declaration * pNode = parse_property(); + return(pNode); + } + } + else if (SL::isKeyword(m_pNext)) + { + SL::Keyword * pKeyword = static_cast(m_pNext); + + switch (pKeyword->getKeyword()) + { + case SL::Keyword::STRUCT: + { + const AST::Structure * pNode = parse_struct(); + return(pNode); + } + break; + + case SL::Keyword::CLASS: + { + const AST::Class * pNode = parse_class(); + return(pNode); + } + break; + + // TODO : public/protected/private + + default: + { + error("Only struct or class allowed here"); + } + } + } + else + { + error("Expected identifier or keyword (struct or class)"); // but found ... + } + + for (int a = 0; int b =0; -a) + { + a++; b++; + } + return(nullptr); +} + +/** + * @brief used to parse local declaration (a declaration inside function) + * TYPE ID "=" VALUE ";" + * ID "(" ID* ")" + */ +const AST::Statement * Parser::parse_statement(void) +{ + if (SL::isSeparator(m_pNext, SL::Separator::LEFT_CURLY_BRACKET)) + { + const AST::Statement * pNode = parse_block(); + return(pNode); + } + else if (SL::isKeyword(m_pNext)) + { + SL::Keyword * pKeyword = static_cast(m_pNext); + + switch (pKeyword->getKeyword()) + { + case SL::Keyword::RETURN: + { + const AST::Return * pNode = parse_return(); + return(pNode); + } + break; + + case SL::Keyword::BREAK: + { + const AST::JumpStatement * pNode = jump_statement(); + return(pNode); + } + break; + + case SL::Keyword::IF: + { + const AST::If * pNode = parse_if(); + return(pNode); + } + break; + + case SL::Keyword::WHILE: + { + const AST::While * pNode = parse_while(); + return(pNode); + } + break; + + case SL::Keyword::DO: + { + const AST::DoWhile * pNode = parse_do_while(); + return(pNode); + } + break; + + case SL::Keyword::FOR: + { + const AST::For * pNode = parse_for(); + return(pNode); + } + break; + + default: + error("unexpected keyword inside a function"); + break; + } + } + else + { + const AST::Statement * pStmt = nullptr; + SL::Token * t = lookAhead(1); + + if (SL::isIdentifier(t)) + { + const AST::Declaration * pDecl = parse_simple_declaration(); + pStmt = new AST::DeclarationList(pDecl); + } + else + { + const AST::Expression * pExpr = parse_expression(); + pStmt = new AST::ExpressionList(pExpr); + } + + skip(SL::Separator::SEMICOLON); + + return(pStmt); + } + + return(nullptr); +} + +/** + * @brief Parse an expression using an "Operator-precedence parser" + * @see http://en.wikipedia.org/wiki/Operator-precedence_parser + * @return + */ +const AST::Expression * Parser::parse_expression(void) +{ + const AST::Expression * lhs = parse_primary_expression(); + + const AST::Expression * pExpr = parse_expression_1(lhs, 0); + + return(pExpr); +} + +/** + * @brief internal function of expresion parsing + * @see http://en.wikipedia.org/wiki/Operator-precedence_parser + * @param lhs + * @param min_precedence + * @return + */ +const AST::Expression * Parser::parse_expression_1(const AST::Expression * lhs, unsigned int min_precedence) +{ + while (SL::isSymbol(m_pNext) && static_cast(m_pNext)->isBinary() && static_cast(m_pNext)->getPrecedence() >= min_precedence) // (lookahead is a binary operator whose precedence is >= min_precedence) + { + SL::Symbol * op = static_cast(m_pNext); + + skip(SL::Token::SYMBOL); + + const AST::Expression * rhs = parse_primary_expression(); + + while (SL::isSymbol(m_pNext) && + ( (static_cast(m_pNext)->isBinary() && static_cast(m_pNext)->getPrecedence() > op->getPrecedence()) + || (static_cast(m_pNext)->isRightAssociative() && static_cast(m_pNext)->getPrecedence() == op->getPrecedence()))) + { + rhs = parse_expression_1(rhs, static_cast(m_pNext)->getPrecedence()); // lookahead's precedence + } + + lhs = create_binary_expr(op, lhs, rhs); //the result of applying op with operands lhs and rhs + } + + return(lhs); +} + +/** + * @brief Parser::parse_primary_expression + * primary ::= '(' expression ')' | NUMBER | VARIABLE | '-' primary + * @return + */ +const AST::Expression * Parser::parse_primary_expression(void) +{ + if (SL::isSeparator(m_pNext, SL::Separator::LEFT_PARENTHESIS)) + { + skip(SL::Separator::LEFT_PARENTHESIS); + + const AST::Expression * pExpr = parse_expression(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + return(pExpr); + } + else if (SL::isNumber(m_pNext)) + { + const AST::Constant * pConstantExpr(nullptr); + + SL::Number * pNumber = static_cast(m_pNext); + + switch(pNumber->getFormat()) + { + case SL::Number::INT: + { + pConstantExpr = new AST::Constant(pNumber->getValueAsInt()); + } + break; + + case SL::Number::FLOAT: + { + pConstantExpr = new AST::Constant(pNumber->getValueAsFloat()); + } + break; + + case SL::Number::DOUBLE: + { + pConstantExpr = new AST::Constant(pNumber->getValueAsDouble()); + } + break; + } + + skip(SL::Token::NUMBER); + + return(pConstantExpr); + } + else if (SL::isIdentifier(m_pNext)) + { + AST::Expression * pExpr(nullptr); + + char strName [256]; + parse_name(strName, true); + + if (SL::isSeparator(m_pNext, SL::Separator::LEFT_PARENTHESIS)) + { + skip(SL::Separator::LEFT_PARENTHESIS); + + std::vector aArguments; + + if (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_PARENTHESIS)) + { + aArguments.push_back(parse_expression()); + + while (SL::isSeparator(m_pNext, SL::Separator::COMMA)) + { + skip(SL::Separator::COMMA); + aArguments.push_back(parse_expression()); + } + } + + skip(SL::Separator::RIGHT_PARENTHESIS); + + pExpr = new AST::Call(strName, aArguments); + } + else + { + pExpr = new AST::Variable(strName); + } + + // TODO : unary operators left-to-right + + return(pExpr); + } + else if (SL::isSymbol(m_pNext)) + { + SL::Symbol * op = static_cast(m_pNext); + + if (!op->isUnary()) + { + error("This is not an unary operator !"); + } + + skip(SL::Token::SYMBOL); + + const AST::Expression * pExpr = parse_primary_expression(); + + const AST::Unary * pUnaryExpr = create_unary_expr(op, pExpr); + + return(pUnaryExpr); + } + else + { + error("unexpected token"); + } + + return(nullptr); +} + +/** + * @brief Parser::parse_declaration + * @return + */ +const AST::SimpleDeclaration * Parser::parse_simple_declaration(void) +{ + char strType [256]; + parse_type(strType); + + char strName [256]; + parse_name(strName, true); + + const AST::Expression * pExpr = nullptr; + + if (SL::isSymbol(m_pNext, SL::Symbol::EQUAL)) + { + skip(SL::Symbol::EQUAL); + + pExpr = parse_expression(); + } + + // allocate and return + const AST::SimpleDeclaration * pDeclaration = new AST::SimpleDeclaration(strType, strName, pExpr); + return(pDeclaration); +} + +/** + * @brief Parser::parse_return + * @return + */ +const AST::Return * Parser::parse_return(void) +{ + skip(SL::Keyword::RETURN); + + const AST::Expression * pExpr = parse_expression(); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + AST::Return * pReturn = new AST::Return(pExpr); + return(pReturn); +} + +/** + * @brief Parser::parse_if + * @return + */ +const AST::If * Parser::parse_if(void) +{ + skip(SL::Keyword::IF); + + skip(SL::Separator::LEFT_PARENTHESIS); + + const AST::Expression * pExpr = parse_expression(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + const AST::Statement * pChild = parse_statement(); + + if (SL::isKeyword(m_pNext, SL::Keyword::ELSE)) + { + skip(SL::Keyword::ELSE); + + parse_statement(); + } + + // allocate and return + AST::If * pIf = new AST::If(pExpr, pChild); + return(pIf); +} + +/** + * @brief Parser::parse_while + * @return + */ +const AST::While * Parser::parse_while() +{ + skip(SL::Keyword::WHILE); + + skip(SL::Separator::LEFT_PARENTHESIS); + + const AST::Expression * pExpr = parse_expression(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + const AST::Statement * pChild = parse_statement(); + + // allocate and return + AST::While * pWhile = new AST::While(pExpr, pChild); + return(pWhile); +} + +/** + * @brief Parser::parse_do + * @return + */ +const AST::DoWhile * Parser::parse_do_while(void) +{ + skip(SL::Keyword::DO); + + const AST::Statement * pChild = parse_statement(); + + skip(SL::Keyword::WHILE); + + skip(SL::Separator::LEFT_PARENTHESIS); + + const AST::Expression * pExpr = parse_expression(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + AST::DoWhile * pDoWhile = new AST::DoWhile(pExpr, pChild); + return(pDoWhile); +} + +/** + * @brief Parser::parse_for + * @return + */ +const AST::For * Parser::parse_for(void) +{ + skip(SL::Keyword::FOR); + + skip(SL::Separator::LEFT_PARENTHESIS); + + // Init + const AST::Node * pInit = nullptr; + { + if (!SL::isSeparator(m_pNext, SL::Separator::SEMICOLON)) + { +#ifdef FORCE_FOR_INIT_TO_BE_A_DECLARATION + pInit = parse_simple_declaration(); +#else + SL::Token * t = lookAhead(1); + + if (SL::isIdentifier(t)) + { + pInit = parse_declaration(); + } + else + { + pInit = parse_expression(); + } +#endif + } + } + + skip(SL::Separator::SEMICOLON); + + // Condition + const AST::Expression * pCondition = nullptr; + { + if (!SL::isSeparator(m_pNext, SL::Separator::SEMICOLON)) + { + pCondition = parse_expression(); + } + } + + skip(SL::Separator::SEMICOLON); + + // Update + const AST::Expression * pUpdate = nullptr; + { + if (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_PARENTHESIS)) + { + pUpdate = parse_expression(); + } + } + + skip(SL::Separator::RIGHT_PARENTHESIS); + + const AST::Statement * pChild = parse_statement(); + + // allocate and return + AST::For * pFor = new AST::For(pInit, pCondition, pUpdate, pChild); + return(pFor); +} + +/** + * @brief Used to parse struct + * @todo handle public/private/protected + * "struct" ID "{" MEMBER* "}" + */ +const AST::Structure * Parser::parse_struct(void) +{ + AST::Structure * pStructure(nullptr); + + skip(SL::Keyword::STRUCT); + + if (SL::isIdentifier(m_pNext)) + { + pStructure = new AST::Structure(static_cast(m_pNext)->getValue()); + skip(SL::Token::IDENTIFIER); + } + else + { + error("Missing struct name"); + } + + skip(SL::Separator::LEFT_CURLY_BRACKET); + + while (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_CURLY_BRACKET)) + { + const AST::Declaration * pNode = parse_member(); + pStructure->addNode(pNode); + } + + skip(SL::Separator::RIGHT_CURLY_BRACKET); + + skip(SL::Separator::SEMICOLON); + + return(pStructure); +} + +/** + * @brief Used to parse class + * @todo handle public/private/protected + * "class" ID "{" MEMBER* "}" + */ +const AST::Class * Parser::parse_class(void) +{ + AST::Class * pClass(nullptr); + + skip(SL::Keyword::CLASS); + + if (SL::isIdentifier(m_pNext)) + { + pClass = new AST::Class(static_cast(m_pNext)->getValue()); + skip(SL::Token::IDENTIFIER); + } + else + { + error("Missing class name"); + } + + skip(SL::Separator::LEFT_CURLY_BRACKET); + + while (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_CURLY_BRACKET)) + { + const AST::Declaration * pNode = parse_member(); + pClass->addNode(pNode); + } + + skip(SL::Separator::RIGHT_CURLY_BRACKET); + + skip(SL::Separator::SEMICOLON); + + return(pClass); +} + +/** + * @brief Parser::parse_variable + * @param global + * @return + */ +const AST::SimpleDeclaration * Parser::parse_variable(void) +{ + char strType [256]; + parse_type(strType); + + char strName [256]; + parse_name(strName, true); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + const AST::SimpleDeclaration * pVariable = new AST::SimpleDeclaration(strType, strName); + return(pVariable); +} + +/** + * @brief Parser::parse_method + * @param global + * @return + */ +const AST::FunctionDefinition * Parser::parse_method(void) +{ + AST::FunctionDefinition * pFunction(nullptr); + + char strType [256]; + parse_type(strType); + + char strName [256]; + parse_name(strName, false); + + std::vector aParams; + + skip(SL::Separator::LEFT_PARENTHESIS); + + if (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_PARENTHESIS)) + { + aParams.push_back(parse_simple_declaration()); + + while (SL::isSeparator(m_pNext, SL::Separator::COMMA)) + { + skip(SL::Separator::COMMA); + aParams.push_back(parse_simple_declaration()); + } + } + + skip(SL::Separator::RIGHT_PARENTHESIS); + + // allocate + pFunction = new AST::FunctionDefinition(strName, strType, aParams); + + // add block + const AST::CompoundStatement * pBlock = parse_block(); + pFunction->addNode(pBlock); + + // return + return(pFunction); +} + +/** + * @brief Parser::parse_variable + * @param global + * @return + */ +const AST::SimpleDeclaration * Parser::parse_property(void) +{ + char strType [256]; + parse_type(strType); + + char strName [256]; + parse_name(strName, false); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + const AST::SimpleDeclaration * pVariable = new AST::SimpleDeclaration(strType, strName); + return(pVariable); +} + +/** + * @brief Parser::parse_block + * @return + */ +const AST::CompoundStatement * Parser::parse_block(void) +{ + std::vector aStatement; + + skip(SL::Separator::LEFT_CURLY_BRACKET); + + while (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_CURLY_BRACKET)) + { + const AST::Statement * pNode = parse_statement(); + aStatement.push_back(pNode); + } + + skip(SL::Separator::RIGHT_CURLY_BRACKET); + + // allocate and return + const AST::CompoundStatement * pBlock = new AST::CompoundStatement(aStatement); + return(pBlock); +} + +/** + * @brief parse function parameter + * @todo handle default value ("= V") + * TYPE [NAME] + */ +void Parser::parse_parameter(void) +{ + char strType [256]; + parse_type(strType); + + if (SL::isIdentifier(m_pNext)) + { + skip(SL::Token::IDENTIFIER); // parameter name + } +} + +/** + * @brief Parser::parse_type + */ +void Parser::parse_type(char * pType) +{ + if (SL::isIdentifier(m_pNext)) + { + strcpy(pType, static_cast(m_pNext)->getValue()); + skip(SL::Token::IDENTIFIER); + } + else + { + error("identifier ?"); + } + +#if 0 + while (m_next == "::") + { + skip("::"); + skip(Lexer::ID); + } +#endif +} + +/** + * @brief Parser::parse_name + */ +void Parser::parse_name(char * pName, bool global) +{ + if (SL::isIdentifier(m_pNext)) + { + strcpy(pName, static_cast(m_pNext)->getValue()); + skip(SL::Token::IDENTIFIER); + } + else + { + error("identifier ?"); + } + + if (global) + { +#if 0 + while (m_next == "::") + { + skip("::"); + skip(Lexer::ID); + } +#endif + } +} + +/** + * @brief Parser::create_binary_expr + * @param lhs + * @param lhs + * @return + */ +const AST::Binary * Parser::create_binary_expr(const SL::Symbol * symbol, const AST::Expression * lhs, const AST::Expression * rhs) +{ + switch (symbol->getSymbol()) + { + // arithmetic + case SL::Symbol::PLUS: return(new AST::Addition(lhs, rhs)); break; + case SL::Symbol::MINUS: return(new AST::Subtraction(lhs, rhs)); break; + case SL::Symbol::ASTERISK: return(new AST::Multiplication(lhs, rhs)); break; + case SL::Symbol::SLASH: return(new AST::Division(lhs, rhs)); break; + case SL::Symbol::PERCENT: return(new AST::Modulo(lhs, rhs)); break; + // relational + case SL::Symbol::EQUAL_EQUAL: return(new AST::EqualTo(lhs, rhs)); break; + case SL::Symbol::EXCLAMATION_EQUAL: return(new AST::NotEqualTo(lhs, rhs)); break; + case SL::Symbol::LT: return(new AST::LessThan(lhs, rhs)); break; + case SL::Symbol::LT_EQUAL: return(new AST::LessThanOrEqualTo(lhs, rhs)); break; + case SL::Symbol::GT: return(new AST::GreaterThan(lhs, rhs)); break; + case SL::Symbol::GT_EQUAL: return(new AST::GreaterThanOrEqualTo(lhs, rhs)); break; + // assignment + case SL::Symbol::EQUAL: return(new AST::BasicAssignment(lhs, rhs)); break; + case SL::Symbol::PLUS_EQUAL: return(new AST::BasicAssignment(lhs, rhs)); break; + case SL::Symbol::MINUS_EQUAL: return(new AST::BasicAssignment(lhs, rhs)); break; + case SL::Symbol::ASTERISK_EQUAL: return(new AST::BasicAssignment(lhs, rhs)); break; + case SL::Symbol::SLASH_EQUAL: return(new AST::BasicAssignment(lhs, rhs)); break; + case SL::Symbol::PERCENT_EQUAL: return(new AST::BasicAssignment(lhs, rhs)); break; + + default: error("BinaryExpr Factory failed to create an expression"); + } + + return(nullptr); +} + +/** + * @brief Parser::create_unary_expr + * @param symbol + * @param rhs + * @return + */ +const AST::Unary * Parser::create_unary_expr(const SL::Symbol * symbol, const AST::Expression * rhs) +{ + switch (symbol->getSymbol()) + { + case SL::Symbol::PLUS: return(new AST::UnaryPlus(rhs)); break; + case SL::Symbol::MINUS: return(new AST::UnaryMinus(rhs)); break; + + default: error("UnaryExpr Factory failed to create an expression"); + } + + return(nullptr); +} + +/** + * @brief Attribute specifier sequence + * + * attribute-specifier-seq: + * attribute-specifier-seq opt attribute-specifier + */ +void Parser::attribute_specifier_seq(bool opt) +{ + if (!opt) + { + attribute_specifier(); + } + + while (SL::isSeparator(m_pNext, SL::Separator::LEFT_SQUARE_BRACKET)) + { + attribute_specifier(); + } +} + +/** + * @brief Attribute specifier + */ +void Parser::attribute_specifier(void) +{ + if (1) + { + skip(SL::Separator::LEFT_SQUARE_BRACKET); + skip(SL::Separator::LEFT_SQUARE_BRACKET); + + // attribute_list(); + while (SL::isSeparator(m_pNext, SL::Separator::RIGHT_SQUARE_BRACKET)) + { + skip(m_pNext->getType()); + } + + skip(SL::Separator::RIGHT_SQUARE_BRACKET); + skip(SL::Separator::RIGHT_SQUARE_BRACKET); + } + else + { + // TODO alignment_specifier(); + } +} + + +const AST::Statement * Parser::try_block() +{ + return(nullptr); +} diff --git a/src/Parser.h b/src/Parser.h new file mode 100644 index 0000000..d34ad59 --- /dev/null +++ b/src/Parser.h @@ -0,0 +1,199 @@ +#pragma once + +#include "Lexer.h" + +#include +#include + +#include "SL/Token.h" +#include "SL/Identifier.h" +#include "SL/Keyword.h" +#include "SL/Number.h" +#include "SL/Separator.h" +#include "SL/Symbol.h" +#include "SL/Endmark.h" + +#include "AST/Declarations/FunctionDefinition.h" +#include "AST/Declarations/NamespaceDefinition.h" +#include "AST/Declarations/EmptyDeclaration.h" +#include "AST/Declarations/StaticAssertDeclaration.h" +#include "AST/Declarations/TemplateDeclaration.h" +#include "AST/Declarations/ExplicitInstantiation.h" +#include "AST/Declarations/ExplicitSpecialization.h" +#include "AST/Declarations/AttributeDeclaration.h" +#include "AST/Declarations/AssemblerDefinition.h" + +#include "AST/Declarations/SimpleDeclaration.h" +#include "AST/Declarations/Structure.h" +#include "AST/Declarations/Class.h" + +#include "AST/Statements/DeclarationList.h" +#include "AST/Statements/ExpressionList.h" +#include "AST/Statements/CompoundStatement.h" +#include "AST/Statements/SelectionStatements/If.h" +#include "AST/Statements/IterationStatements/While.h" +#include "AST/Statements/IterationStatements/DoWhile.h" +#include "AST/Statements/IterationStatements/For.h" +#include "AST/Statements/JumpStatements/Return.h" + +#include "AST/Expressions/Call.h" +#include "AST/Expressions/Unary.h" +#include "AST/Expressions/Binary.h" +#include "AST/Expressions/Constant.h" +#include "AST/Expressions/Variable.h" + +class Parser +{ + +public: + + explicit Parser (const char * buffer); + virtual ~Parser (void); + + bool buildAST (void); + + const std::vector & getAST (void) + { + return(m_aNodes); + } + +private: + + void error (const char * str); + + void scan (void); + SL::Token * lookAhead (unsigned int n); + + void skip (SL::Token::EType t); + void skip (SL::Symbol::ESymbol sym); + void skip (SL::Separator::ESeparator op); + void skip (SL::Keyword::EKeyword k); + +protected: + + void translation_unit (void); + + // Statements + const AST::Statement * statement (void); + + void condition (bool opt = false); + + const AST::Statement * labeled_statement (void); + const AST::Statement * expression_statement (void); + const AST::CompoundStatement * compound_statement (void); + const AST::Statement * selection_statement (void); + const AST::Statement * iteration_statement (void); + const AST::JumpStatement * jump_statement (void); + const AST::Statement * declaration_statement (void); + + // Declarations + const AST::Declaration * declaration (void); + + const AST::Declaration * block_declaration (void); + const AST::FunctionDefinition * function_definition (void); + +// void linkage_specification (void); + const AST::NamespaceDefinition * namespace_definition (void); + const AST::EmptyDeclaration * empty_declaration (void); + const AST::AttributeDeclaration * attribute_declaration (void); + + void simple_declaration (void); + const AST::AssemblerDefinition * asm_definition (void); + const AST::Declaration * linkage_specification (void); + void namespace_alias_definition (void); + void using_declaration (void); + void using_directive (void); + const AST::StaticAssertDeclaration *static_assert_declaration (void); + void alias_declaration (void); + void opaque_enum_declaration (void); + + // Declarators + + // ... + + // Classes + + // ... + + // Derived Classes + + // ... + + // Special member functions + + // ... + + // Overloading + + // ... + + // Templates + const AST::TemplateDeclaration * template_declaration (void); + void template_parameter_list (void); + void template_parameter (void); + void type_parameter (void); + void type_parameter_key (void); + const AST::ExplicitInstantiation * explicit_instantiation (void); + const AST::ExplicitSpecialization * explicit_specialization (void); + + // Exception handling + const AST::Statement * try_block (void); + + + + + const AST::Declaration * parse_member (void); + const AST::Statement * parse_statement (void); + + // global definitions + + const AST::Structure * parse_struct (void); + const AST::Class * parse_class (void); + const AST::SimpleDeclaration * parse_variable (void); + + // members + const AST::FunctionDefinition * parse_method (void); + const AST::SimpleDeclaration * parse_property (void); + + // statements + const AST::SimpleDeclaration * parse_simple_declaration(void); + const AST::CompoundStatement * parse_block (void); + const AST::If * parse_if (void); + const AST::While * parse_while (void); + const AST::DoWhile * parse_do_while (void); + const AST::For * parse_for (void); + const AST::Return * parse_return (void); + + // expressions + const AST::Expression * parse_expression (void); + const AST::Expression * parse_expression_1 (const AST::Expression * lhs, unsigned int min_precedence); + + //const AST::Expression * parse_equality_expression (void); + //const AST::Expression * parse_additive_expression (void); + //const AST::Expression * parse_multiplicative_expression (void); + const AST::Expression * parse_primary_expression (void); + + //const AST::Expression * parse_constant (void); + //const AST::Unary * parse_unary_expression (void); + + void parse_parameter (void); + void parse_type (char * pType); + void parse_name (char * pName, bool global); + + const AST::Binary * create_binary_expr(const SL::Symbol * symbol, const AST::Expression * lhs, const AST::Expression * rhs); + const AST::Unary * create_unary_expr(const SL::Symbol * symbol, const AST::Expression * rhs); + + // other + void attribute_specifier_seq(bool opt = false); + void attribute_specifier(void); + +private: + + Lexer m_lexer; + SL::Token * m_pNext; + + std::queue m_queueAhead; + + std::vector m_aNodes; + +}; diff --git a/src/Parser_declarations.cpp b/src/Parser_declarations.cpp new file mode 100644 index 0000000..4271cb6 --- /dev/null +++ b/src/Parser_declarations.cpp @@ -0,0 +1,518 @@ +#include "Parser.h" + +#include + +/** + * @brief Declaration + * + * declaration: + * block-declaration + * function-definition + * template-declaration + * explicit-instantiation + * explicit-specialization + * linkage-specification + * namespace-definition + * empty-declaration + * attribute-declaration + */ +const AST::Declaration * Parser::declaration(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::TEMPLATE)) + { + SL::Token * t1 = lookAhead(1); + + if (SL::isSymbol(t1, SL::Symbol::LT)) + { + SL::Token * t2 = lookAhead(2); + + if (SL::isSymbol(t2, SL::Symbol::GT)) + { + const AST::ExplicitSpecialization * pNode = explicit_specialization(); + return(pNode); + } + else + { + const AST::TemplateDeclaration * pNode = template_declaration(); + return(pNode); + } + } + else + { + const AST::ExplicitInstantiation * pNode = explicit_instantiation(); + return(pNode); + } + } + else if (SL::isKeyword(m_pNext, SL::Keyword::EXTERN)) + { + SL::Token * t1 = lookAhead(1); + + if (SL::isKeyword(t1, SL::Keyword::TEMPLATE)) + { + const AST::ExplicitInstantiation * pNode = explicit_instantiation(); + return(pNode); + } + else + { + const AST::Declaration * pNode = linkage_specification(); + return(pNode); + } + } + else if (SL::isKeyword(m_pNext, SL::Keyword::NAMESPACE)) + { + const AST::NamespaceDefinition * pNode = namespace_definition(); + return(pNode); + } + else if (SL::isSeparator(m_pNext, SL::Separator::SEMICOLON)) + { + const AST::EmptyDeclaration * pNode = empty_declaration(); + return(pNode); + } + else if (SL::isSeparator(m_pNext, SL::Separator::LEFT_SQUARE_BRACKET)) + { + const AST::AttributeDeclaration * pNode = attribute_declaration(); + return(pNode); + } + else if (SL::isIdentifier(m_pNext)) + { + attribute_specifier_seq(true); + + SL::Token * t = lookAhead(2); + + if (SL::isSeparator(t, SL::Separator::LEFT_PARENTHESIS)) + { + const AST::FunctionDefinition * pNode = function_definition(); + return(pNode); + } + else + { + const AST::Declaration * pNode = parse_variable(); + return(pNode); + } + } + else if (SL::isKeyword(m_pNext, SL::Keyword::CLASS) || SL::isKeyword(m_pNext, SL::Keyword::STRUCT)) + { + SL::Keyword * pKeyword = static_cast(m_pNext); + + switch (pKeyword->getKeyword()) + { + case SL::Keyword::STRUCT: + { + const AST::Structure * pNode = parse_struct(); + return(pNode); + } + break; + + case SL::Keyword::CLASS: + { + const AST::Class * pNode = parse_class(); + return(pNode); + } + break; + + default: + { + error("Only namespace, struct or class allowed here"); // but found ... + } + } + } + else + { + const AST::Declaration * pNode = block_declaration(); + return(pNode); + } + + error("This should not happen !"); + return(nullptr); +} + +/** + * @brief Block declaration + * + * block-declaration: + * simple-declaration + * asm-definition + * namespace-alias-definition + * using-declaration + * using-directive + * static_assert-declaration + * alias-declaration + * opaque-enum-declaration + */ +const AST::Declaration * Parser::block_declaration(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::ASM)) + { + const AST::AssemblerDefinition * pDeclaration = asm_definition(); + return(pDeclaration); + } + else if (SL::isKeyword(m_pNext, SL::Keyword::NAMESPACE)) + { + namespace_alias_definition(); + } + else if (SL::isKeyword(m_pNext, SL::Keyword::USING)) + { + SL::Token * t1 = lookAhead(1); + SL::Token * t2 = lookAhead(1); + + if (SL::isKeyword(t1, SL::Keyword::NAMESPACE)) + { + using_directive(); + } + else if (SL::isIdentifier(t1) && (SL::isSeparator(t2, SL::Separator::LEFT_SQUARE_BRACKET) || SL::isSymbol(t2, SL::Symbol::EQUAL))) + { + alias_declaration(); + } + else + { + using_declaration(); + } + } + else if (SL::isKeyword(m_pNext, SL::Keyword::STATIC_ASSERT)) + { + const AST::StaticAssertDeclaration * pDeclaration = static_assert_declaration(); + return(pDeclaration); + } + else if (SL::isKeyword(m_pNext, SL::Keyword::ENUM)) + { + opaque_enum_declaration(); + } + else + { + simple_declaration(); + } + + error("This should not happen !"); + return(nullptr); +} + +/** + * @brief Function definition + * + * function-definition: + * attribute-specifier-seq opt decl-specifier-seq opt declarator virt-specifier-seq opt function-body + */ +const AST::FunctionDefinition * Parser::function_definition(void) +{ + AST::FunctionDefinition * pFunction(nullptr); + + char strType [256]; + parse_type(strType); + + char strName [256]; + parse_name(strName, true); + + std::vector aParams; + + skip(SL::Separator::LEFT_PARENTHESIS); + + if (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_PARENTHESIS)) + { + aParams.push_back(parse_simple_declaration()); + + while (SL::isSeparator(m_pNext, SL::Separator::COMMA)) + { + skip(SL::Separator::COMMA); + aParams.push_back(parse_simple_declaration()); + } + } + + skip(SL::Separator::RIGHT_PARENTHESIS); + + // allocate + pFunction = new AST::FunctionDefinition(strName, strType, aParams); + + // add block + const AST::CompoundStatement * pBlock = parse_block(); + pFunction->addNode(pBlock); + + // return + return(pFunction); +} + +/** + * @brief Namespace definition + * + * namespace-definition: + * named-namespace-definition + * unnamed-namespace-definition nested-namespace-definition + */ +const AST::NamespaceDefinition * Parser::namespace_definition(void) +{ + const char * strName = nullptr; + std::vector aDeclarations; + + // parse + skip(SL::Keyword::NAMESPACE); + + if (SL::isIdentifier(m_pNext)) + { + strName = static_cast(m_pNext)->getValue(); + skip(SL::Token::IDENTIFIER); + } + else + { + error("Missing namespace name"); + } + + skip(SL::Separator::LEFT_CURLY_BRACKET); + + while (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_CURLY_BRACKET)) + { + aDeclarations.push_back(declaration()); + } + + skip(SL::Separator::RIGHT_CURLY_BRACKET); + + // allocate and return + const AST::NamespaceDefinition * pNamespace = new AST::NamespaceDefinition(strName, aDeclarations); + return(pNamespace); +} + +/** + * @brief Empty declaration + * + * empty-declaration: + * ; + */ +const AST::EmptyDeclaration * Parser::empty_declaration(void) +{ + skip(SL::Separator::SEMICOLON); + + // allocate and return + const AST::EmptyDeclaration * pDeclaration = new AST::EmptyDeclaration(); + return(pDeclaration); +} + +/** + * @brief Attribute declaration + * + * attribute-declaration: + * attribute-specifier-seq ; + */ +const AST::AttributeDeclaration * Parser::attribute_declaration(void) +{ + attribute_specifier_seq(); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + const AST::AttributeDeclaration * pDeclaration = new AST::AttributeDeclaration(); + return(pDeclaration); +} + +/** + * @brief Simple declaration + */ +void Parser::simple_declaration(void) +{ + +} + +/** + * @brief asm definition + * + * asm-definition: + * asm ( string-literal ) ; + */ +const AST::AssemblerDefinition * Parser::asm_definition(void) +{ + const char * str = nullptr; + + skip(SL::Keyword::ASM); + + skip(SL::Separator::LEFT_PARENTHESIS); + + assert(false); // string-literal + + skip(SL::Separator::RIGHT_PARENTHESIS); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + const AST::AssemblerDefinition * pDefinition = new AST::AssemblerDefinition(str); + return(pDefinition); +} + +/** + * @brief Linkage specification + * + * linkage-specification: + * extern string-literal { declaration-seq (opt) } + * extern string-literal declaration + */ +const AST::Declaration * Parser::linkage_specification(void) +{ + std::vector aDeclaration; + + skip(SL::Keyword::EXTERN); + + assert(false); // string-literal + + if (SL::isSeparator(m_pNext, SL::Separator::LEFT_CURLY_BRACKET)) + { + skip(SL::Separator::LEFT_CURLY_BRACKET); + + // declaration-seq (opt) + while (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_CURLY_BRACKET)) + { + const AST::Declaration * pNode = declaration(); + aDeclaration.push_back(pNode); + } + + skip(SL::Separator::RIGHT_CURLY_BRACKET); + } + else + { + const AST::Declaration * pNode = declaration(); + aDeclaration.push_back(pNode); + } + + // allocate and return + const AST::Declaration * pDeclaration = nullptr; // TODO + return(pDeclaration); +} + +/** + * @brief Namespace alias definition + * + * namespace-alias-definition: + * namespace identifier = qualified-namespace-specifier ; + */ +void Parser::namespace_alias_definition(void) +{ + skip(SL::Keyword::NAMESPACE); + + skip(SL::Token::IDENTIFIER); + + skip(SL::Symbol::EQUAL); + + assert(false); // qualified-namespace-specifier + + skip(SL::Separator::SEMICOLON); +} + +/** + * @brief using declaration + * + * using-declaration: + * using typename (opt) nested-name-specifier unqualified-id ; + */ +void Parser::using_declaration() +{ + skip(SL::Keyword::USING); + + assert(false); // typename (opt) + + assert(false); // nested-name-specifier + + assert(false); // unqualified-id + + skip(SL::Separator::SEMICOLON); +} + +/** + * @brief using directive + * + * using-directive: + * attribute-specifier-seq (opt) using namespace nested-name-specifier (opt) namespace-name ; + */ +void Parser::using_directive(void) +{ + attribute_specifier_seq(true); + + skip(SL::Keyword::USING); + + skip(SL::Keyword::NAMESPACE); + + assert(false); // nested-name-specifier + + assert(false); // namespace-name + + skip(SL::Separator::SEMICOLON); +} + +/** + * @brief static_assert declaration + * + * static_assert-declaration: + * static_assert ( constant-expression ) ; + * static_assert ( constant-expression , string-literal ) ; + */ +const AST::StaticAssertDeclaration * Parser::static_assert_declaration(void) +{ + skip(SL::Keyword::STATIC_ASSERT); + + skip(SL::Separator::LEFT_PARENTHESIS); + + const AST::Expression * pExpression = parse_expression(); // FIXME : constant_expression(); + + if (SL::isSeparator(m_pNext, SL::Separator::COMMA)) + { + skip(SL::Separator::COMMA); + assert(false); // string-literal + } + + skip(SL::Separator::RIGHT_PARENTHESIS); + + skip(SL::Separator::SEMICOLON); + + // allocate and return + const AST::StaticAssertDeclaration * pDeclaration = new AST::StaticAssertDeclaration(pExpression); + return(pDeclaration); +} + +/** + * @brief alias declaration + * + * alias-declaration: + * using identifier attribute-specifier-seq (opt) = type-id ; + */ +void Parser::alias_declaration(void) +{ + skip(SL::Keyword::USING); + + skip(SL::Token::IDENTIFIER); + + attribute_specifier_seq(true); + + skip(SL::Symbol::EQUAL); + + assert(false); // type-id + + skip(SL::Separator::SEMICOLON); +} + +/** + * @brief opaque enum declaration + * + * opaque-enum-declaration: + * enum-key attribute-specifier-seq (opt) identifier enum-base (opt) ; + */ +void Parser::opaque_enum_declaration(void) +{ + // enum-key + { + skip(SL::Keyword::ENUM); + + if (SL::isKeyword(m_pNext, SL::Keyword::CLASS) || SL::isKeyword(m_pNext, SL::Keyword::STRUCT)) + { + skip(SL::Token::KEYWORD); + } + } + + attribute_specifier_seq(true); + + skip(SL::Token::IDENTIFIER); + + // enum-base + { + if (SL::isSeparator(m_pNext, SL::Separator::COLON)) + { + skip(SL::Separator::COLON); + assert(false); // type-specifier-seq + } + } + + skip(SL::Separator::SEMICOLON); +} diff --git a/src/Parser_statements.cpp b/src/Parser_statements.cpp new file mode 100644 index 0000000..00a3730 --- /dev/null +++ b/src/Parser_statements.cpp @@ -0,0 +1,400 @@ +#include "Parser.h" + +#include + +/** + * @brief Statement + * + * statement: + * labeled-statement + * attribute-specifier-seq (opt) expression-statement + * attribute-specifier-seq (opt) compound-statement + * attribute-specifier-seq (opt) selection-statement + * attribute-specifier-seq (opt) iteration-statement + * attribute-specifier-seq (opt) jump-statement + * declaration-statement + * attribute-specifier-seq (opt) try-block + */ +const AST::Statement * Parser::statement(void) +{ + attribute_specifier_seq(true); + + if (SL::isSeparator(m_pNext, SL::Separator::LEFT_CURLY_BRACKET)) + { + compound_statement(); + } + else if (SL::isKeyword(m_pNext)) + { + switch (static_cast(m_pNext)->getKeyword()) + { + case SL::Keyword::IF: + case SL::Keyword::SWITCH: + { + selection_statement(); + } + break; + + case SL::Keyword::WHILE: + case SL::Keyword::DO: + case SL::Keyword::FOR: + { + iteration_statement(); + } + break; + + case SL::Keyword::BREAK: + case SL::Keyword::CONTINUE: + case SL::Keyword::RETURN: + case SL::Keyword::GOTO: + { + jump_statement(); + } + break; + + case SL::Keyword::CASE: + case SL::Keyword::DEFAULT: + { + labeled_statement(); + } + break; + + case SL::Keyword::TRY: + { + try_block(); + } + break; + + default: + error("unexpected keyword"); + } + } + else if (SL::isIdentifier(m_pNext)) + { + SL::Token * t = lookAhead(1); + + if (SL::isSeparator(t, SL::Separator::COLON)) + { + labeled_statement(); + } + else + { + // expression-statement or declaration + } + } + else + { + // expression-statement or declaration + } + + return(nullptr); +} + +/** + * @brief Condition + * + * condition: + * expression + * attribute-specifier-seq (opt) decl-specifier-seq declarator = initializer-clause + * attribute-specifier-seq (opt) decl-specifier-seq declarator braced-init-list + */ +void Parser::condition(bool opt) +{ + assert(false); +} + +/** + * @brief Labeled statement + * + * labeled-statement: + * attribute-specifier-seq opt identifier : statement + * attribute-specifier-seq opt case constant-expression : statement + * attribute-specifier-seq opt default : statement + */ +const AST::Statement * Parser::labeled_statement(void) +{ + if (SL::isIdentifier(m_pNext)) + { + skip(SL::Token::IDENTIFIER); + + skip(SL::Separator::COLON); + + statement(); + + return(nullptr); // TODO + } + else if (SL::isKeyword(m_pNext, SL::Keyword::CASE)) + { + skip(SL::Keyword::CASE); + + assert(false); // constant_expression(); + + skip(SL::Separator::COLON); + + statement(); + + return(nullptr); // TODO + } + else if (SL::isKeyword(m_pNext, SL::Keyword::DEFAULT)) + { + skip(SL::Keyword::DEFAULT); + + skip(SL::Separator::COLON); + + statement(); + + return(nullptr); // TODO + } + else + { + error("unexpected token"); + } + + return(nullptr); +} + +/** + * @brief Expression statement + * + * expression-statement: + * expression (opt) ; + */ +const AST::Statement * Parser::expression_statement(void) +{ + assert(false); // expression(true); + + skip(SL::Separator::SEMICOLON); + + return(nullptr); // TODO +} + +/** + * @brief Compound statement + * + * compound-statement: + * { statement-seq (opt) } + */ +const AST::CompoundStatement * Parser::compound_statement(void) +{ + std::vector aStatement; + + skip(SL::Separator::LEFT_CURLY_BRACKET); + + while (!SL::isSeparator(m_pNext, SL::Separator::RIGHT_CURLY_BRACKET)) + { + const AST::Statement * pNode = statement(); + aStatement.push_back(pNode); + } + + skip(SL::Separator::RIGHT_CURLY_BRACKET); + + // allocate and return + const AST::CompoundStatement * pStatement = new AST::CompoundStatement(aStatement); + return(pStatement); +} + +/** + * @brief Selection statement + * + * selection-statement: + * if ( condition ) statement + * if ( condition ) statement else statement + * switch ( condition ) statement + */ +const AST::Statement * Parser::selection_statement(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::IF)) + { + skip(SL::Keyword::IF); + + skip(SL::Separator::LEFT_PARENTHESIS); + + condition(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + statement(); + + if (SL::isKeyword(m_pNext, SL::Keyword::ELSE)) + { + skip(SL::Keyword::ELSE); + + statement(); + } + + return(nullptr); // TODO + } + else if (SL::isKeyword(m_pNext, SL::Keyword::SWITCH)) + { + skip(SL::Keyword::SWITCH); + + skip(SL::Separator::LEFT_PARENTHESIS); + + condition(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + statement(); + + return(nullptr); // TODO + } + else + { + error("unexpected token"); + } + + return(nullptr); +} + +/** + * @brief Iteration statement + * + * iteration-statement: + * while ( condition ) statement + * do statement while ( expression ) ; + * for ( for-init-statement condition opt ; expression opt ) statement + * for ( for-range-declaration : for-range-initializer ) statement + */ +const AST::Statement * Parser::iteration_statement(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::WHILE)) + { + skip(SL::Keyword::WHILE); + + skip(SL::Separator::LEFT_PARENTHESIS); + + condition(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + statement(); + + return(nullptr); // TODO + } + else if (SL::isKeyword(m_pNext, SL::Keyword::DO)) + { + skip(SL::Keyword::DO); + + statement(); + + skip(SL::Keyword::WHILE); + + skip(SL::Separator::LEFT_PARENTHESIS); + + assert(false); // expression(); + + skip(SL::Separator::RIGHT_PARENTHESIS); + + skip (SL::Separator::SEMICOLON); + + return(nullptr); // TODO + } + else if (SL::isKeyword(m_pNext, SL::Keyword::FOR)) + { + skip(SL::Keyword::FOR); + + skip(SL::Separator::LEFT_PARENTHESIS); + + // how to distinguish between for-init-statement and for-range-declaration ??? + // for now just support classic for + { + assert(false); // for-init-statement + + condition(true); + + skip (SL::Separator::SEMICOLON); + + assert(false); // expression(true); + } + skip(SL::Separator::RIGHT_PARENTHESIS); + + statement(); + + return(nullptr); // TODO + } + else + { + error("unexpected token"); + } + + return(nullptr); +} + +/** + * @brief Jump statement + * + * jump-statement: + * break ; + * continue ; + * return expression (opt) ; + * return braced-init-list ; + * goto identifier ; + */ +const AST::JumpStatement * Parser::jump_statement(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::BREAK)) + { + skip(SL::Keyword::BREAK); + + skip (SL::Separator::SEMICOLON); + + // allocate and return + const AST::JumpStatement * pStatement = new AST::JumpStatement(AST::JumpStatement::BREAK); + return(pStatement); + } + else if (SL::isKeyword(m_pNext, SL::Keyword::CONTINUE)) + { + skip(SL::Keyword::CONTINUE); + + skip (SL::Separator::SEMICOLON); + + // allocate and return + const AST::JumpStatement * pStatement = new AST::JumpStatement(AST::JumpStatement::CONTINUE); + return(pStatement); + } + else if (SL::isKeyword(m_pNext, SL::Keyword::RETURN)) + { + skip(SL::Keyword::GOTO); + + if (SL::isSeparator(m_pNext, SL::Separator::LEFT_CURLY_BRACKET)) + { + assert(false); // braced_init_list(); + } + else + { + assert(false); // expression(true); + } + + skip (SL::Separator::SEMICOLON); + + return(nullptr); // TODO + } + else if (SL::isKeyword(m_pNext, SL::Keyword::GOTO)) + { + skip(SL::Keyword::GOTO); + + skip(SL::Token::IDENTIFIER); + + // allocate and return + const AST::JumpStatement * pStatement = new AST::JumpStatement(AST::JumpStatement::GOTO); // FIXME : set identifier + return(pStatement); + } + else + { + error("unexpected token"); + } + + return(nullptr); +} + +/** + * @brief Declaration statement + * + * declaration-statement: + * block-declaration + */ +const AST::Statement * Parser::declaration_statement(void) +{ + block_declaration(); + + return(nullptr); // TODO +} diff --git a/src/Parser_templates.cpp b/src/Parser_templates.cpp new file mode 100644 index 0000000..c9b3809 --- /dev/null +++ b/src/Parser_templates.cpp @@ -0,0 +1,160 @@ +#include "Parser.h" + +#include + +/** + * @brief Template declaration + * + * template-declaration: + * template < template-parameter-list > declaration + */ +const AST::TemplateDeclaration * Parser::template_declaration(void) +{ + skip(SL::Keyword::TEMPLATE); + + skip(SL::Symbol::LT); + + // template-parameter-list + while (!SL::isSymbol(m_pNext, SL::Symbol::GT)) + { + skip(m_pNext->getType()); + } + + skip(SL::Symbol::GT); + + const AST::Declaration * pTemplatedDeclaration = declaration(); + + // allocate and return + const AST::TemplateDeclaration * pDeclaration = new AST::TemplateDeclaration(pTemplatedDeclaration); + return(pDeclaration); +} + +/** + * @brief template parameter list + * + * template-parameter-list: + * template-parameter + * template-parameter-list , template-parameter + */ +void Parser::template_parameter_list(void) +{ + template_parameter(); + + while (SL::isSeparator(m_pNext, SL::Separator::COMMA)) + { + skip(SL::Separator::COMMA); + template_parameter(); + } +} + +/** + * @brief template parameter + * + * template-parameter: + * type-parameter + * parameter-declaration + */ +void Parser::template_parameter(void) +{ + type_parameter(); + assert(false); // parameter_declaration(); +} + +/** + * @brief type parameter + * + * type-parameter: + * type-parameter-key ... (opt) identifier (opt) + * type-parameter-key identifier (opt) = type-id + * template < template-parameter-list > type-parameter-key ... (opt) identifier (opt) + * template < template-parameter-list > type-parameter-key identifier (opt) = id-expression + */ +void Parser::type_parameter(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::TEMPLATE)) + { + skip(SL::Keyword::TEMPLATE); + + skip(SL::Symbol::LT); + + template_parameter_list(); + + skip(SL::Symbol::GT); + + type_parameter_key(); + + assert(false); + } + else + { + type_parameter_key(); + + assert(false); + } +} + +/** + * @brief type parameter key + * + * type-parameter-key: + * class + * typename + */ +void Parser::type_parameter_key(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::CLASS)) + { + skip(SL::Keyword::CLASS); + } + else if (SL::isKeyword(m_pNext, SL::Keyword::TYPENAME)) + { + skip(SL::Keyword::TYPENAME); + } + else + { + error("Expected 'class' or 'typename' !"); + } +} + +/** + * @brief Explicit instantiation + * + * explicit-instantiation: + * extern (opt) template declaration + */ +const AST::ExplicitInstantiation * Parser::explicit_instantiation(void) +{ + if (SL::isKeyword(m_pNext, SL::Keyword::EXTERN)) + { + skip(SL::Keyword::EXTERN); + } + + skip(SL::Keyword::TEMPLATE); + + const AST::Declaration * pTemplatedDeclaration = declaration(); + + // allocate and return + const AST::ExplicitInstantiation * pDeclaration = new AST::ExplicitInstantiation(pTemplatedDeclaration); + return(pDeclaration); +} + +/** + * @brief Explicit specialization + * + * explicit-specialization: + * template < > declaration + */ +const AST::ExplicitSpecialization * Parser::explicit_specialization(void) +{ + skip(SL::Keyword::TEMPLATE); + + skip(SL::Symbol::LT); + + skip(SL::Symbol::GT); + + const AST::Declaration * pTemplatedDeclaration = declaration(); + + // allocate and return + const AST::ExplicitSpecialization * pDeclaration = new AST::ExplicitSpecialization(pTemplatedDeclaration); + return(pDeclaration); +} diff --git a/src/SL/Endmark.cpp b/src/SL/Endmark.cpp new file mode 100644 index 0000000..375394d --- /dev/null +++ b/src/SL/Endmark.cpp @@ -0,0 +1,19 @@ +#include "Endmark.h" + +/** + * @brief AST::Endmark::Endmark + */ +SL::Endmark::Endmark() +{ + // ... +} + +/** + * @brief AST::Endmark + * @param pNode + * @return + */ +bool SL::isEndmark(SL::Token * pNode) +{ + return(pNode->getType() == Token::ENDMARK); +} diff --git a/src/SL/Endmark.h b/src/SL/Endmark.h new file mode 100644 index 0000000..c8763d0 --- /dev/null +++ b/src/SL/Endmark.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Token.h" + +namespace SL +{ + +struct Endmark : public Token +{ + explicit Endmark(); + + virtual EType getType(void) const { return(ENDMARK); } +}; + +bool isEndmark(Token * pNode); + +} diff --git a/src/SL/Identifier.cpp b/src/SL/Identifier.cpp new file mode 100644 index 0000000..2b358a5 --- /dev/null +++ b/src/SL/Identifier.cpp @@ -0,0 +1,21 @@ +#include "Identifier.h" + +#include + +/** + * @brief AST::Identifier::Identifier + */ +SL::Identifier::Identifier(const char * pName) +{ + strcpy(m_pName, pName); +} + +/** + * @brief AST::isIdentifier + * @param pNode + * @return + */ +bool SL::isIdentifier(SL::Token * pNode) +{ + return(pNode->getType() == Token::IDENTIFIER); +} diff --git a/src/SL/Identifier.h b/src/SL/Identifier.h new file mode 100644 index 0000000..e4d8f66 --- /dev/null +++ b/src/SL/Identifier.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Token.h" + +namespace SL +{ + +struct Identifier : public Token +{ + explicit Identifier(const char * pName); + + virtual EType getType(void) const { return(IDENTIFIER); } + + const char * getValue(void) const { return(m_pName); } + +private: + + char m_pName [256]; + +}; + +bool isIdentifier(Token * pNode); + +} diff --git a/src/SL/Keyword.cpp b/src/SL/Keyword.cpp new file mode 100644 index 0000000..5e78ef6 --- /dev/null +++ b/src/SL/Keyword.cpp @@ -0,0 +1,39 @@ +#include "Keyword.h" + +const char * SL::Keyword::Strings [SL::Keyword::Count] = +{ + #define DEF(str, e) str, + #include "keywords.def" + #undef DEF +}; + +/** + * @brief AST::Keyword::Keyword + * @param type + */ +SL::Keyword::Keyword(EKeyword t) +: m_eType(t) +{ + // ... +} + +/** + * @brief AST::isKeyword + * @param pNode + * @return + */ +bool SL::isKeyword(SL::Token * pNode) +{ + return(pNode->getType() == Token::KEYWORD); +} + +/** + * @brief AST::isKeyword + * @param pNode + * @param k + * @return + */ +bool SL::isKeyword(SL::Token * pNode, SL::Keyword::EKeyword k) +{ + return(isKeyword(pNode) && static_cast(pNode)->getKeyword() == k); +} diff --git a/src/SL/Keyword.h b/src/SL/Keyword.h new file mode 100644 index 0000000..0f9e8a0 --- /dev/null +++ b/src/SL/Keyword.h @@ -0,0 +1,36 @@ +#pragma once + +#include "Token.h" + +namespace SL +{ + +struct Keyword : public Token +{ + enum EKeyword + { + #define DEF(str, e) e, + #include "keywords.def" + #undef DEF + }; + + static const unsigned int Count = ASM + 1; + + static const char * Strings [Count]; + + explicit Keyword(EKeyword t); + + virtual EType getType(void) const { return(KEYWORD); } + + EKeyword getKeyword(void) const { return(m_eType); } + +private: + + EKeyword m_eType; + +}; + +bool isKeyword(Token * pNode); +bool isKeyword(Token * pNode, Keyword::EKeyword k); + +} diff --git a/src/SL/Number.cpp b/src/SL/Number.cpp new file mode 100644 index 0000000..354f289 --- /dev/null +++ b/src/SL/Number.cpp @@ -0,0 +1,71 @@ +#include "Number.h" + +/** + * @brief AST::Number::Number + * @param v + */ +SL::Number::Number(float v) +: m_eFormat(FLOAT) +{ + value.as_float = v; +} + +/** + * @brief AST::Number::Number + * @param v + */ +SL::Number::Number(double v) +: m_eFormat(DOUBLE) +{ + value.as_double = v; +} + +/** + * @brief AST::Number::Number + * @param v + */ +SL::Number::Number(int v) +: m_eFormat(INT) +{ + value.as_int = v; +} + +/** + * @brief AST::Number::Number + * @param v + */ +SL::Number::Number(unsigned int v) +: m_eFormat(UINT) +{ + value.as_uint = v; +} + +/** + * @brief AST::Number::Number + * @param v + */ +SL::Number::Number(long v) +: m_eFormat(LONG) +{ + value.as_long = v; +} + +/** + * @brief AST::Number::Number + * @param v + */ +SL::Number::Number(unsigned long v) +: m_eFormat(ULONG) +{ + value.as_ulong = v; +} + +/** + * @brief AST::isNumber + * @param pNode + * @return + */ +bool SL::isNumber(SL::Token * pNode) +{ + return(pNode->getType() == Token::NUMBER); +} diff --git a/src/SL/Number.h b/src/SL/Number.h new file mode 100644 index 0000000..142d8ab --- /dev/null +++ b/src/SL/Number.h @@ -0,0 +1,61 @@ +#pragma once + +#include "Token.h" + +namespace SL +{ + +struct Number : public Token +{ + enum EFormat + { + FLOAT, + DOUBLE, + INT, + UINT, + LONG, + ULONG + }; + + union Values + { + float as_float; + double as_double; + int as_int; + unsigned int as_uint; + long as_long; + unsigned long as_ulong; + }; + + explicit Number (float v); + explicit Number (double v); + + explicit Number (int v); + explicit Number (unsigned int v); + + explicit Number (long v); + explicit Number (unsigned long v); + + virtual EType getType(void) const { return(NUMBER); } + + EFormat getFormat(void) { return(m_eFormat); } + + int getValueAsInt(void) { return(value.as_int); } + unsigned int getValueAsUInt(void) { return(value.as_uint); } + + long getValueAsLong(void) { return(value.as_long); } + unsigned long getValueAsULong(void) { return(value.as_ulong); } + + float getValueAsFloat(void) { return(value.as_float); } + double getValueAsDouble(void) { return(value.as_double); } + +private: + + EFormat m_eFormat; + Values value; + +}; + +bool isNumber(Token * pNode); + +} diff --git a/src/SL/Separator.cpp b/src/SL/Separator.cpp new file mode 100644 index 0000000..f261106 --- /dev/null +++ b/src/SL/Separator.cpp @@ -0,0 +1,32 @@ +#include "Separator.h" + +/** + * @brief AST::Separator::Separator + * @param t + */ +SL::Separator::Separator(ESeparator t) +: m_eType(t) +{ + // ... +} + +/** + * @brief isOperator + * @param pNode + * @return + */ +bool SL::isSeparator(SL::Token * pNode) +{ + return(pNode->getType() == Token::SEPARATOR); +} + +/** + * @brief isOperator + * @param pNode + * @param op + * @return + */ +bool SL::isSeparator(SL::Token * pNode, SL::Separator::ESeparator sep) +{ + return(isSeparator(pNode) && static_cast(pNode)->getSeparator() == sep); +} diff --git a/src/SL/Separator.h b/src/SL/Separator.h new file mode 100644 index 0000000..ada545a --- /dev/null +++ b/src/SL/Separator.h @@ -0,0 +1,42 @@ +#pragma once + +#include "Token.h" + +namespace SL +{ + +struct Separator : public Token +{ + enum ESeparator + { + // ... + DOT = '.', + COMMA = ',', + SEMICOLON = ';', + COLON = ':', + // brackets + LEFT_SQUARE_BRACKET = '[', + RIGHT_SQUARE_BRACKET = ']', + LEFT_CURLY_BRACKET = '{', + RIGHT_CURLY_BRACKET = '}', + // parethensis + LEFT_PARENTHESIS = '(', + RIGHT_PARENTHESIS = ')', + }; + + explicit Separator(ESeparator t); + + virtual EType getType(void) const { return(SEPARATOR); } + + ESeparator getSeparator(void) const { return(m_eType); } + +private: + + ESeparator m_eType; + +}; + +bool isSeparator(Token * pNode); +bool isSeparator(Token * pNode, Separator::ESeparator sep); + +} diff --git a/src/SL/Symbol.cpp b/src/SL/Symbol.cpp new file mode 100644 index 0000000..e2cf526 --- /dev/null +++ b/src/SL/Symbol.cpp @@ -0,0 +1,98 @@ +#include "Symbol.h" + +#include + +/** + * @brief SL::Symbol::Separator + * @param sym + */ +SL::Symbol::Symbol(SL::Symbol::ESymbol sym) +: m_eType(sym) +{ + // ... +} + +/** + * @brief SL::Symbol::getPriority + * @return + */ +unsigned int SL::Symbol::getBinaryPriority(void) const +{ + switch(m_eType) + { + #define UNARY(val, priority) + #define BINARY(val, priority) case val: return(priority); + #include "operator_precedence.def" + #undef UNARY + #undef BINARY + }; + + assert(false); +} + +/** + * @brief SL::Symbol::isRightAssociative + * @return + */ +bool SL::Symbol::isRightAssociative(void) const +{ + return(false); +} + +/** + * @brief SL::Symbol::isUnary + * @return + */ +bool SL::Symbol::isUnary(void) const +{ + switch(m_eType) + { + #define UNARY(val, priority) case val: return(true); + #define BINARY(val, priority) + #include "operator_precedence.def" + #undef UNARY + #undef BINARY + }; + + return(false); +} + +/** + * @brief SL::Symbol::isBinary + * @return + */ +bool SL::Symbol::isBinary(void) const +{ + switch(m_eType) + { + #define UNARY(val, priority) + #define BINARY(val, priority) case val: return(true); + #include "operator_precedence.def" + #undef UNARY + #undef BINARY + } + + return(false); +} + +/** + * @brief SL::isSymbol + * @param pNode + * @return + */ +bool SL::isSymbol(SL::Token * pNode) +{ + return(pNode->getType() == Token::SYMBOL); +} + +/** + * @brief SL::isSymbol + * @param pNode + * @param op + * @return + */ +bool SL::isSymbol(SL::Token * pNode, SL::Symbol::ESymbol sym) +{ + return(isSymbol(pNode) && static_cast(pNode)->getSymbol() == sym); +} + diff --git a/src/SL/Symbol.h b/src/SL/Symbol.h new file mode 100644 index 0000000..e69988d --- /dev/null +++ b/src/SL/Symbol.h @@ -0,0 +1,48 @@ +#pragma once + +#include "Token.h" + +namespace SL +{ + +/** + * @brief The Symbol struct + */ +struct Symbol : public Token +{ + enum ESymbol + { + #define DEF(str, val) val, + #include "symbols.def" + #undef DEF + }; + + explicit Symbol (ESymbol sym); + + virtual EType getType (void) const { return(SYMBOL); } + + ESymbol getSymbol(void) const { return(m_eType); } + + virtual bool isRightAssociative (void) const; + + virtual bool isUnary (void) const; + virtual bool isBinary (void) const; + + unsigned int getPrecedence(void) const + { + return(18 - getBinaryPriority()); + } + +protected: + + virtual unsigned int getBinaryPriority (void) const; + +private: + + ESymbol m_eType; +}; + +bool isSymbol(Token * pNode); +bool isSymbol(Token * pNode, Symbol::ESymbol sym); + +} diff --git a/src/SL/Token.cpp b/src/SL/Token.cpp new file mode 100644 index 0000000..cc052ad --- /dev/null +++ b/src/SL/Token.cpp @@ -0,0 +1 @@ +#include "Token.h" diff --git a/src/SL/Token.h b/src/SL/Token.h new file mode 100644 index 0000000..c1a3369 --- /dev/null +++ b/src/SL/Token.h @@ -0,0 +1,32 @@ +#pragma once + +namespace SL +{ + +class Token +{ + +public: + + enum EType + { + NUMBER, + IDENTIFIER, + KEYWORD, + SYMBOL, + SEPARATOR, + ENDMARK + }; + + virtual EType getType(void) const = 0; + +private: +#if 0 + std::string m_strFilename; + unsigned int m_uLine; + unsigned int m_uColumn; +#endif +}; + + +} diff --git a/src/SL/nouveau fichier b/src/SL/nouveau fichier new file mode 100644 index 0000000..e69de29 diff --git a/src/str.cpp b/src/str.cpp new file mode 100644 index 0000000..d0520e6 --- /dev/null +++ b/src/str.cpp @@ -0,0 +1,71 @@ +#include "str.h" + +/** + * @brief Lexer::isNumber + * @param c + * @return true if c is one of 0123456789 + */ +bool isNumber(const char c) +{ + return('0' <= c && '9' >= c); +} + +/** + * @brief isBinaryNumber + * @param c + * @return true if c is one of 01 + */ +bool isBinaryNumber(const char c) +{ + return('0' == c || '1' == c); +} + +/** + * @brief isHexaNumber + * @param c + * @return if c is one of 0123456789ABCDEF + */ +bool isHexaNumber(const char c) +{ + return(('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && 'F' >= c)); +} + +/** + * @brief isOctalNumber + * @param c + * @return true if c is one of 01234567 + */ +bool isOctalNumber(const char c) +{ + return('0' <= c && c <= '7'); +} + +/** + * @brief isLetter + * @param c + * @return true if c is between (inclusive) 'a' and 'z' (case insensitive) or '_' + */ +bool isLetter(const char c) +{ + return(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('_' == c)); +} + +/** + * @brief isLineBreak + * @param c + * @return true if c is a line break + */ +bool isLineBreak(const char c) +{ + return('\n' == c); +} + +/** + * @brief isWhiteSpace + * @param c + * @return true if c is a white space (space or tabulation) + */ +bool isWhiteSpace(const char c) +{ + return(' ' == c || '\t' == c); +} diff --git a/src/str.h b/src/str.h new file mode 100644 index 0000000..526c563 --- /dev/null +++ b/src/str.h @@ -0,0 +1,12 @@ +#pragma once + +typedef bool (* CharComparatorPFN) (const char c); + +bool isNumber (const char c); +bool isBinaryNumber (const char c); +bool isHexaNumber (const char c); +bool isOctalNumber (const char c); + +bool isLetter (const char c); +bool isWhiteSpace (const char c); +bool isLineBreak (const char c); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..b05b1e7 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) + +include_directories(../src) + +add_executable(sl_compiler compiler.cpp) + +target_link_libraries(sl_compiler SL++) diff --git a/test/compiler.cpp b/test/compiler.cpp new file mode 100644 index 0000000..68ba0f7 --- /dev/null +++ b/test/compiler.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +#include "Parser.h" +#include "Generator.h" + +int main(int argc, char ** argv) +{ + if (2 != argc) + { + printf("Usage: ./compiler \n"); + return(1); + } + + FILE * f = fopen(argv[1], "r"); + + // obtain file size + fseek(f , 0 , SEEK_END); + long lSize = ftell(f); + rewind(f); + + char * source = (char *)malloc(sizeof(char)*lSize); + + size_t result = fread(source, sizeof(char), lSize, f); + + assert(result == sizeof(char)*lSize); + + fclose(f); + + Parser p(source); + + p.buildAST(); + + //Generator::scheme::print_ast(p.getAST()); + + Generator::GLSL::print_ast(p.getAST()); + + return(0); +} diff --git a/test/compiler_v1.cpp b/test/compiler_v1.cpp new file mode 100644 index 0000000..7590d4a --- /dev/null +++ b/test/compiler_v1.cpp @@ -0,0 +1,341 @@ +#include +#include +#include + +#include "Parser.h" + +#include "AST/Function.h" +#include "AST/Namespace.h" +#include "AST/Structure.h" + +static unsigned int count = 0; + +void print_dot(const char * label) +{ + printf("I_%u [label=\"%s\"] ;\n", count++, label); +} + +void print_dot(int n) +{ + printf("I_%u [label=\"%d\"] ;\n", count++, n); +} + +void print_dot(unsigned int n) +{ + printf("I_%u [label=\"%u\"] ;\n", count++, n); +} + +void print_dot(long n) +{ + printf("I_%u [label=\"%ld\"] ;\n", count++, n); +} + +void print_dot(unsigned long n) +{ + printf("I_%u [label=\"%lu\"] ;\n", count++, n); +} + +void print_dot(float n) +{ + printf("I_%u [label=\"%f\"] ;\n", count++, n); +} + +void print_dot(double n) +{ + printf("I_%u [label=\"%f\"] ;\n", count++, n); +} + +void print_identifier(SL::Identifier * pNode) +{ + print_dot(pNode->getValue()); +} + +void print_number(SL::Number * pNode) +{ + switch(pNode->getFormat()) + { + case SL::Number::INT: + { + print_dot(pNode->getValueAsInt()); + } + break; + + case SL::Number::UINT: + { + print_dot(pNode->getValueAsUInt()); + } + break; + + case SL::Number::LONG: + { + print_dot(pNode->getValueAsLong()); + } + break; + + case SL::Number::ULONG: + { + print_dot(pNode->getValueAsULong()); + } + break; + + case SL::Number::FLOAT: + { + print_dot(pNode->getValueAsFloat()); + } + break; + + case SL::Number::DOUBLE: + { + print_dot(pNode->getValueAsDouble()); + } + break; + } +} + +void print_keyword(SL::Keyword * pNode) +{ + switch(pNode->getKeyword()) + { + case SL::Keyword::NAMESPACE: + { + print_dot("namespace"); + } + break; + + case SL::Keyword::CLASS: + { + print_dot("class"); + } + break; + + case SL::Keyword::STRUCT: + { + print_dot("struct"); + } + break; + + case SL::Keyword::ENUM: + { + print_dot("enum"); + } + break; + + case SL::Keyword::IF: + { + print_dot("if"); + } + break; + + case SL::Keyword::FOR: + { + print_dot("for"); + } + break; + + case SL::Keyword::WHILE: + { + print_dot("while"); + } + break; + + case SL::Keyword::DO: + { + print_dot("do"); + } + break; + } +} + +void print_operator(SL::Operator * pNode) +{ + switch(pNode->getOperator()) + { + case SL::Operator::PLUS: + { + print_dot("+"); + } + break; + + case SL::Operator::MINUS: + { + print_dot("-"); + } + break; + + case SL::Operator::MUL: + { + print_dot("*"); + } + break; + + case SL::Operator::DIV: + { + print_dot("/"); + } + break; + + case SL::Operator::MODULO: + { + print_dot("%"); + } + break; + + case SL::Operator::INCREMENT: + { + print_dot("++"); + } + break; + + case SL::Operator::EQUAL: + { + print_dot("="); + } + break; + + case SL::Operator::DECREMENT: + { + print_dot("--"); + } + break; + + case SL::Operator::EQ: + { + print_dot("=="); + } + break; + + case SL::Operator::NEQ: + { + print_dot("!="); + } + break; + } +} + +void print_recurse(const AST::Node * pCurrentNode) +{ + if (nullptr == pCurrentNode) return; // should be an assert !!! + + switch (pCurrentNode->getType()) + { + case AST::Node::NAMESPACE: + { + printf(" (ns %s", static_cast(pCurrentNode)->getName().c_str()); + } + break; + + case AST::Node::STRUCTURE: + { + printf(" (struct %s", static_cast(pCurrentNode)->getName().c_str()); + } + break; + + case AST::Node::FUNCTION: + { + printf(" (fn %s %s", static_cast(pCurrentNode)->getReturnType().c_str(), static_cast(pCurrentNode)->getName().c_str()); + } + break; + } + + for (const AST::Node * pNode : pCurrentNode->getNodes()) + { + print_recurse(pNode); + } + + printf(")"); +} + +void print_ast(const std::vector & aNodes) +{ + for (const AST::Node * pNode : aNodes) + { + print_recurse(pNode); + } + + printf("\n"); +} + +int main(int argc, char ** argv) +{ + if (2 != argc) + { + printf("Usage: ./compiler \n"); + return(1); + } + + FILE * f = fopen(argv[1], "r"); + + // obtain file size + fseek(f , 0 , SEEK_END); + long lSize = ftell(f); + rewind(f); + + char * source = (char *)malloc(sizeof(char)*lSize); + + size_t result = fread(source, sizeof(char), lSize, f); + + assert(result == sizeof(char)*lSize); + + fclose(f); + + Parser p(source); + + p.buildAST(); + + print_ast(p.getAST()); +#if 0 + printf("graph NS_GLOBAL {\n"); + + for (SL::Token * pNode : p.getAST_v1()) + { + assert(nullptr != pNode); + + switch(pNode->getType()) + { + case SL::Token::NUMBER: + { + print_number(static_cast(pNode)); + } + break; + + case SL::Token::IDENTIFIER: + { + print_identifier(static_cast(pNode)); + } + break; + + case SL::Token::KEYWORD: + { + print_keyword(static_cast(pNode)); + } + break; + + case SL::Token::OPERATOR: + { + print_operator(static_cast(pNode)); + } + break; + + case SL::Token::SEPARATOR: + { + print_dot("SEPARATOR "); + } + break; + + case SL::Token::ENDMARK: + { + //assert(false); + } + break; + + default: + { + assert(false); + } + } + } + + printf("} \n"); +#endif + return(0); +}