Esempio n. 1
0
TEST_F(ParserTests_Types, GlobalPointerToFunctionWithPointerArg) {
    ASTNode* node = this->parseNode("*(*Void) -> Void value\n");

    ASSERT_EQ(1, node->childCount());
    node = node->childAtIndex(0);

    ASSERT_EQ(DataType::Pointer, node->dataType().kind());
    ASSERT_EQ(1, node->dataType().subtypeCount());
    ASSERT_EQ(DataType::Function, node->dataType().subtypeAtIndex(0).kind());
}
TEST_F(ParserTests_Atomics, AtomicStatementWithFallbackFunctions) {
    ASTNode* node = this->parseNodeWithBodies("def fn_1(*Void ptr) -> Bool\n"
                                              "  return true\n"
                                              "end\n"
                                              "def fn_2(*Void ptr) -> Bool\n"
                                              "  return true\n"
                                              "end\n"
                                              "def test(*Void ptr)\n"
                                              "  atomic:fallback(fn_1, fn_2, ptr)\n"
                                              "    abort\n"
                                              "  end\n"
                                              "end\n");

    ASSERT_EQ(3, node->childCount());
    node = node->childAtIndex(2);

    ASSERT_EQ("Function Definition", node->nodeName());
    ASSERT_EQ(1, node->childCount());
    node = node->childAtIndex(0);

    ASSERT_EQ("Atomic Statement", node->nodeName());
    auto atomicNode = dynamic_cast<AtomicStatementNode*>(node);

    node = atomicNode->lockFunction();
    ASSERT_TRUE(node != nullptr);
    ASSERT_EQ("Function Variable", node->nodeName());
    ASSERT_EQ("fn_1", node->name());

    node = atomicNode->unlockFunction();
    ASSERT_TRUE(node != nullptr);
    ASSERT_EQ("Function Variable", node->nodeName());
    ASSERT_EQ("fn_2", node->name());

    node = atomicNode->lockContext();
    ASSERT_TRUE(node != nullptr);
    ASSERT_EQ("Local Variable", node->nodeName());
    ASSERT_EQ("ptr", node->name());
}
TEST_F(ParserTests_Atomics, AtomicExpressionAssign) {
    ASTNode* node = this->parseSingleFunction("def test(Int a)\n"
                                              "  atomic:ordered(a = a)\n"
                                              "end\n");

    ASSERT_EQ(1, node->childCount());
    node = node->childAtIndex(0);

    ASSERT_EQ("Atomic Expression", node->nodeName());
    ASSERT_EQ(AtomicNode::Ordering::SequentiallyConsistent, dynamic_cast<Three::AtomicExpressionNode*>(node)->ordering());

    node = node->childAtIndex(0);

    ASSERT_EQ("Assign Operator", node->nodeName());
}