diff --git a/core/aux/graphs_trees_depth.lp b/core/aux/graphs_trees_depth.lp deleted file mode 100644 index a322358..0000000 --- a/core/aux/graphs_trees_depth.lp +++ /dev/null @@ -1,2 +0,0 @@ -graphs_tree_depth(X, 0) :- not graphs_tree_depends(X, _); graphs_node(X). -graphs_tree_depth(X, LEVEL):- LEVEL = #max{L+1, graphs_tree_depth(Y, L): graphs_tree_depth(Y, L), graphs_tree_depends(X, Y)}; graphs_node(X); LEVEL > 0. \ No newline at end of file diff --git a/core/dominators.lp b/core/dominators.lp deleted file mode 100644 index e69de29..0000000 diff --git a/core/exploitation.lp b/core/exploitation.lp deleted file mode 100644 index 20f47d5..0000000 --- a/core/exploitation.lp +++ /dev/null @@ -1,12 +0,0 @@ -expl_sites(Data, Site) :- S=(_, Site); bind(S, exploitation_initialized(file)); bind(S, static(data(Data))). -expl_sites(Data, Site) :- S=(_, Site); bind(S, exploitation_initialized(file)); bind(S, static(ref(Root))); bind(Root, static(data(Data))). - - -expl_parent(Site, dom(Parent)) :- cfa_forwdom(Parent, range(A, B)); cfa_forwdom(Site, range(A1, B1)); Acount && "Parser errors"); fclose(input); } TEST(AST, InterfacesDataCFA) { PassManager* man = PassManager::prepareForCode ("interface(cfa){\n" " operator map :: annotation1.\n" "}"); auto answer = man->root->__interfacesData.equal_range(CFA); EXPECT_EQ(1, std::distance(answer.first, answer.second)); Expression&& scheme = move(answer.first->second); EXPECT_EQ(Operator::MAP, scheme.op); EXPECT_EQ("annotation1", scheme.getOperands().at(0).getValueString()); } TEST(AST, syntax_recognizeIdentifiers){ PassManager* man = PassManager::prepareForCode(R"Code( test= function(a:: num):: num; entry { a = b:: int. b = 8:: int. a } )Code"); } TEST(AST, syntax_operatorIndex){ PassManager* man = PassManager::prepareForCode(R"Code( test= function(a:: num):: num; entry { b = a[1]. b } )Code"); } TEST(AST, DISABLED_InterfacesDataDFA){ } TEST(AST, DISABLED_InterfacesDataExtern){ } //TODO xreate.atg: replace all Type<> as ExprAnnotations<> diff --git a/cpp/tests/containers.cpp b/cpp/tests/containers.cpp index a9f3c2b..7037a8d 100644 --- a/cpp/tests/containers.cpp +++ b/cpp/tests/containers.cpp @@ -1,109 +1,109 @@ /* * containers.cpp * * Created on: Jun 9, 2015 * Author: pgess */ #include "passmanager.h" #include "query/containers.h" #include "Parser.h" #include "gtest/gtest.h" using namespace std; using namespace xreate; using namespace containers; TEST(Containers, ListAsArray){ PassManager* man = PassManager::prepareForCode( R"Code( main = function(x:: int):: int;entry { a = [1, 2, 3]:: [int]. a[x] } )Code" ); void* mainPtr = man->run(); int (*main)(int) = (int (*)(int))mainPtr; ASSERT_EQ(2, main(1)); delete man; } TEST(Containers, ListAsArray2){ PassManager* man = PassManager::prepareForCode( R"Code( // CONTAINERS interface(dfa) { operator map:: (op(seqaccess)) -> impl(solid). operator list_range:: ()->impl(on_the_fly). operator list:: ()->impl(solid). operator fold:: (op(seqaccess)). operator index:: (op(randaccess)). } import raw("core/containers.lp") main = function:: int;entry { a= [1, 2, 3]:: [int]. b= loop map(a->el:: int):: [int]{ 2 * el }. sum = loop fold(b->el:: int, 0->acc):: int { acc + el }. sum } )Code" ); void* mainPtr = man->run(); int (*main)() = (int (*)())mainPtr; ASSERT_EQ(12, main()); delete man; } TEST(Containers, ContanierLinkedList1){ - FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate","r"); + FILE* input = fopen("scripts/containers/Containers_Implementation_LinkedList1.xreate","r"); assert(input != nullptr); Scanner scanner(input); Parser parser(&scanner); parser.Parse(); AST& ast = parser.root; CodeScope* body = ast.findFunction("test")->getEntryScope(); const Symbol symb_chilrenRaw{body->getSymbol("childrenRaw"), body}; containers::ImplementationLinkedList iLL(symb_chilrenRaw); ASSERT_EQ(true, static_cast(iLL)); ASSERT_EQ("next", iLL.fieldPointer); Implementation impl = Implementation::create(symb_chilrenRaw); ASSERT_NO_FATAL_FAILURE(impl.extract()); ImplementationRec recOnthefly = impl.extract(); ASSERT_EQ(symb_chilrenRaw, recOnthefly.source); } TEST(Containers, Implementation_LinkedListFull){ - FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate","r"); + FILE* input = fopen("scripts/containers/Containers_Implementation_LinkedList1.xreate","r"); assert(input != nullptr); std::unique_ptr program(PassManager::prepareForCode(input)); void* mainPtr = program->run(); int (*main)() = (int (*)())(intptr_t)mainPtr; int answer = main(); ASSERT_EQ(17, answer); fclose(input); } diff --git a/cpp/tests/externc.cpp b/cpp/tests/externc.cpp index b8f9536..4aa5d7e 100644 --- a/cpp/tests/externc.cpp +++ b/cpp/tests/externc.cpp @@ -1,106 +1,106 @@ #include "gtest/gtest.h" #include "passmanager.h" #include "Scanner.h" #include "Parser.h" #include #include using namespace std; TEST(InterfaceExternC, testAST) { std::string code = " \ interface(extern-c){ \ xml2 = library:: pkgconfig(\"libxml-2.0\"). \ \ include { \ xml2 = [\"libxml/tree.h\"] \ }. \ } \ "; Scanner scanner(reinterpret_cast (code.c_str()), code.size()); Parser parser(&scanner); parser.Parse(); ASSERT_EQ(1, parser.root.__externdata.size()); for (const ExternEntry& lib : parser.root.__externdata) { ASSERT_EQ("libxml-2.0", lib.package); ASSERT_EQ(1, lib.headers.size()); ASSERT_EQ("libxml/tree.h", lib.headers.at(0)); } } TEST(InterfaceExternC, testfetchPackageHeaders) { ExternEntry entry{"libxml-2.0", {}}; vector args = ExternLayer::fetchPackageFlags(entry); ASSERT_EQ(1, args.size()); ASSERT_EQ("-I/usr/include/libxml2", args.at(0)); } TEST(InterfaceExternC, testfetchPackageLibs) { ExternEntry entry{"libxml-2.0", {}}; vector args = ExternLayer::fetchPackageLibs(entry); ASSERT_EQ(1, args.size()); ASSERT_EQ("xml2", args.at(0)); } TEST(InterfaceExternC, testLoadLib) { std::string msgErr; if (!llvm::sys::DynamicLibrary::LoadLibraryPermanently("-lpcre -lxml2", &msgErr)) { cout << msgErr; ASSERT_EQ("", msgErr); } ASSERT_TRUE(true); } TEST(InterfaceExternC, testBSD1) { std::string code = " \n\ interface(extern-c){ \n\ libbsd = library:: pkgconfig(\"libbsd\"). \n\ \n\ include { \n\ libbsd = [\"bsd/stdlib.h\"] \n\ }. \n\ } \n" "main= function:: int; entry{arc4random_uniform(24) }"; std::unique_ptr program(PassManager::prepareForCode(move(code))); void* entryPtr = program->run(); int (*entry)() = (int (*)())(intptr_t) entryPtr; int answer = 24; answer = entry(); cout << answer; ASSERT_LT(answer, 24); } TEST(InterfaceExternC, testStructFields1) { - FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate", "r"); + FILE* input = fopen("scripts/containers/Containers_Implementation_LinkedList1.xreate", "r"); assert(input != nullptr); Scanner scanner(input); Parser parser(&scanner); parser.Parse(); AST& ast = parser.root; CodeScope* body = ast.findFunction("test")->getEntryScope(); const TypeAnnotation& tTree = body->getDeclaration(body->getSymbol("tree")).type; const ExpandedType& t2Tree = ast.expandType(tTree); LLVMLayer llvm(&ast); TypeUtils utils(&llvm); std::vectorfields = utils.getStructFields(t2Tree); auto field = std::find(fields.begin(), fields.end(), "children"); ASSERT_TRUE(field != fields.end()); } diff --git a/cpp/tests/types.cpp b/cpp/tests/types.cpp index b9d3e96..5ff99b6 100644 --- a/cpp/tests/types.cpp +++ b/cpp/tests/types.cpp @@ -1,163 +1,163 @@ /* * types.cpp * * Created on: Jun 4, 2015 * Author: pgess */ #include "gtest/gtest.h" #include "passmanager.h" #include "llvmlayer.h" #include "Parser.h" using namespace std; using namespace xreate; TEST(Types, DependantTypes1) { string&& code = "XmlNode = type alias {\n" " tag:: string,\n" " /* attrs:: [string],*/\n" " content:: string\n" "}.\n"; std::unique_ptr program(PassManager::prepareForCode(move(code))); ExpandedType typeXmlNode = program->root->findType("XmlNode"); ASSERT_EQ(TypeOperator::STRUCT, typeXmlNode->__operator); ASSERT_EQ(2, typeXmlNode->__operands.size()); ASSERT_EQ(TypePrimitive::String, typeXmlNode->__operands.at(0).__value); ASSERT_EQ(TypePrimitive::String, typeXmlNode->__operands.at(1).__value); } TEST(Types, DependantTypes2) { string&& code = "XmlNode = type alias {\n" " tag:: string,\n" " /* attrs:: [string],*/\n" " content:: string\n" "}.\n" "" "Template = type Template(Leaf) [Leaf, [Leaf[content]]]." "Concrete = type alias Template(XmlNode)."; std::unique_ptr program(PassManager::prepareForCode(move(code))); ExpandedType typeConcrete = program->root->findType("Concrete"); ASSERT_EQ(TypeOperator::TUPLE, typeConcrete->__operator); ASSERT_EQ(2, typeConcrete->__operands.size()); ASSERT_EQ(TypeOperator::STRUCT, typeConcrete->__operands.at(0).__operator); ASSERT_EQ(TypeOperator::ARRAY, typeConcrete->__operands.at(1).__operator); ASSERT_EQ(TypePrimitive::String, typeConcrete->__operands.at(1).__operands.at(0).__value); } TEST(Types, TreeType1) { string&& code = "XmlNode = type alias {\n" " tag:: string,\n" " /* attrs:: [string],*/\n" " content:: string\n" "}.\n" "" "Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]." "Concrete = type alias Tree(XmlNode)."; std::unique_ptr program(PassManager::prepareForCode(move(code))); ExpandedType typeConcrete = program->root->findType("Concrete"); ASSERT_EQ(TypeOperator::TUPLE, typeConcrete->__operator); ASSERT_EQ(2, typeConcrete->__operands.size()); ASSERT_EQ(TypeOperator::STRUCT, typeConcrete->__operands.at(0).__operator); ASSERT_EQ(TypeOperator::ARRAY, typeConcrete->__operands.at(1).__operator); auto typeLink = typeConcrete->__operands.at(1).__operands.at(0); ASSERT_EQ(TypeOperator::LINK, typeLink.__operator); ASSERT_EQ(typeConcrete->conjuctionId,typeLink.conjuctionId); } TEST(Types, TreeType1LLvm){ string&& code = "XmlNode = type alias {\n" " tag:: string,\n" " /* attrs:: [string],*/\n" " content:: string\n" "}.\n" "" "Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]." "Concrete = type alias Tree(XmlNode)."; std::unique_ptr program(PassManager::prepareForCode(move(code))); ExpandedType typeConcrete = program->root->findType("Concrete"); llvm::Type* raw = program->llvm->toLLVMType(typeConcrete); } TEST(Types, ArrayOfExternal1){ - FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate","r"); + FILE* input = fopen("scripts/containers/Containers_Implementation_LinkedList1.xreate","r"); assert(input != nullptr); Scanner scanner(input); Parser parser(&scanner); parser.Parse(); AST& ast = parser.root; CodeScope* body = ast.findFunction("test")->getEntryScope(); const TypeAnnotation& t = body->getDeclaration(body->getSymbol("childrenRaw")).type; const ExpandedType& t2 = ast.expandType(t); EXPECT_EQ(t2->__operator, TypeOperator::ARRAY); } TEST(Types, ExternType1){ - FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate","r"); + FILE* input = fopen("scripts/containers/Containers_Implementation_LinkedList1.xreate","r"); assert(input != nullptr); Scanner scanner(input); Parser parser(&scanner); parser.Parse(); AST& ast = parser.root; CodeScope* body = ast.findFunction("test")->getEntryScope(); const TypeAnnotation& t = body->getDeclaration(body->getSymbol("tree")).type; const ExpandedType& t2 = ast.expandType(t); EXPECT_EQ(t2->__operator, TypeOperator::CUSTOM); } TEST(Types, ast_VariantType1){ string&& code = " colors = type variant (RED, BLUE, GREEN).\n" " test = function:: colors; entry {GREEN}"; std::unique_ptr program(PassManager::prepareForCode(move(code))); ExpandedType typ = program->root->findType("colors"); EXPECT_EQ(TypeOperator::VARIANT, typ->__operator); Expression eRed = program->root->findFunction("test")->getEntryScope()->getBody(); EXPECT_EQ(Expression::VARIANT, eRed.__state); const ExpandedType& typ2 = program->root->expandType(eRed.type); EXPECT_EQ(TypeOperator::VARIANT, typ2->__operator); program->run(); } TEST(Types, full_VariantType_Switch1){ string&& code = " colors = type variant (RED, BLUE, GREEN). \n" " test = function:: colors {GREEN} \n" "main = function:: int; entry { \n" " switch(test()):: int \n" " case (GREEN) {0} \n" " case default {1} \n" "}"; PassManager* man = PassManager::prepareForCode(move(code)); int (*main)() = (int (*)()) man->run(); EXPECT_EQ(0, main()); } //TOTEST string type diff --git a/scripts/cases/bugs-code.xreate b/scripts/cases/bugs-code.xreate deleted file mode 100644 index dd8875a..0000000 --- a/scripts/cases/bugs-code.xreate +++ /dev/null @@ -1,32 +0,0 @@ -//unsafe code propagation rule -rule: (X: function, Y: function) -case X call Y, -X tag suppress(unsafe_propagation_warning) - { - warning Y tag unsafe -> X tag unsafe - message "safe function should not call unsafe code" - } - -//bugs propagation rule -rule: (X: function, Y: function) -case X call Y, - X tag suppress(bugs_propagation_warnings) - { - warning Y tag bug(no(No)) -> X tag bug(no(No)) - message "Function should declare bugs it aware of" - } - -testfunc3 = function: (a: num, b: num)->num,unsafe, bug(no(1273)) //function tags list -{ - x = a+b: num; - y = a - b: num; - - (x + y) / 2; -} - -testfunc2 = function: (a: num)->bool // because of testfunc3 marked as unsafe code, - // testfunc2 should be marked so too -,suppress(bugs_propagation_warnings), suppress(unsafe_propagation_warning) - -{ - b = testfunc3(a+1, a-1): num; - (b==0); -} \ No newline at end of file diff --git a/scripts/cases/log.xreate b/scripts/cases/log.xreate deleted file mode 100644 index 997edf1..0000000 --- a/scripts/cases/log.xreate +++ /dev/null @@ -1,64 +0,0 @@ -/* - - Log level: - Log entry(flat, hierarchical) - -*/ - - - - - // EXTERN INCLUDES -interface(extern-c){ - xml2 = library:: pkgconfig("libxml-2.0"). - - include { - xml2 = ["libxml/tree.h", "string.h"] - }. -} - - // CONTAINERS -interface(dfa) { - operator map:: (op(seqaccess)) -> impl(solid). - operator list_range:: ()->impl(on_the_fly). - operator list:: ()->impl(solid). - operator fold:: (op(seqaccess)). - operator index:: (op(randaccess)). - /* operator map: (op(seqaccess)) -> impl(llvm_array | on_the_fly); */ -} - -import raw("core/containers.lp"). - - - // PROGRAM -XmlNode = type alias { - tag:: string, - /* attrs:: [string],*/ - content:: string -}. - -Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]. -XmlTree = type alias Tree(XmlNode). - - -test= function():: num; entry { - filename = "project/documentation.fodt" :: string. - docRaw = xmlParseFile(filename) :: xmlDocPtr. - tree= xmlDocGetRootElement(docRaw) :: xmlNodePtr. - childrenRaw = tree["children"]:: [xmlNodePtr]; containers:linkedlist(next, null). - size = loop fold(childrenRaw->child:: xmlNodePtr, 0->count::int):: int { - -// $log{ -// count +1:: warning, subsystem=xml -// } - - - //log{warning, subsystem=xml, ..} - childName = child["name"]::string; logging. - count + strlen(childName):: int - }. - - size -} - - diff --git a/scripts/cases/unsafe-code.xreate b/scripts/cases/unsafe-code.xreate deleted file mode 100644 index 9705f31..0000000 --- a/scripts/cases/unsafe-code.xreate +++ /dev/null @@ -1,23 +0,0 @@ - -//unsafe code propagation rule -rule: (X: function, Y: function) -case X call Y - { - warning Y tag unsafe -> X tag unsafe - message "safe function should not call unsafe code" - } - -testfunc3 = function: (a: num, b: num)->num , unsafe //function tags list -{ - x = a+b: num; - y = a - b: num; - - (x + y) / 2; -} - -testfunc2 = function: (a: num)->bool // since testfunc3 marked as unsafe code, - // testfunc2 should be marked so too -{ - b = testfunc3(a+1, a-1): num; - (b==0); -} diff --git a/scripts/containers-set-intersection.xreate b/scripts/containers-set-intersection.xreate deleted file mode 100644 index 22b378d..0000000 --- a/scripts/containers-set-intersection.xreate +++ /dev/null @@ -1,11 +0,0 @@ -/** - * intersection of two sets - */ - -intersection = function(X: [a], sorted; Y: [b], sorted) -{ - loop map (X -> x: a | exists(Y, x)) - {x;}; -} - - \ No newline at end of file diff --git a/scripts/testspass/Containers_Implementation_LinkedList1-data.xml b/scripts/containers/Containers_Implementation_LinkedList1-data.xml similarity index 100% rename from scripts/testspass/Containers_Implementation_LinkedList1-data.xml rename to scripts/containers/Containers_Implementation_LinkedList1-data.xml diff --git a/scripts/containers/Containers_Implementation_LinkedList1.xreate b/scripts/containers/Containers_Implementation_LinkedList1.xreate deleted file mode 120000 index 25bdd31..0000000 --- a/scripts/containers/Containers_Implementation_LinkedList1.xreate +++ /dev/null @@ -1 +0,0 @@ -/private/prg/code/xreate/scripts/testspass/Containers_Implementation_LinkedList1.xreate \ No newline at end of file diff --git a/scripts/containers/Containers_Implementation_LinkedList1.xreate b/scripts/containers/Containers_Implementation_LinkedList1.xreate new file mode 100644 index 0000000..a645574 --- /dev/null +++ b/scripts/containers/Containers_Implementation_LinkedList1.xreate @@ -0,0 +1,47 @@ + + // EXTERN INCLUDES +interface(extern-c){ + xml2 = library:: pkgconfig("libxml-2.0"). + + include { + xml2 = ["libxml/tree.h"] + }. +} + + // CONTAINERS +interface(dfa) { + operator map:: (op(seqaccess)) -> impl(solid). + operator list_range:: ()->impl(on_the_fly). + operator list:: ()->impl(solid). + operator fold:: (op(seqaccess)). + /* operator index:: (op(randaccess)). - BREAKS THE ANALYSIS. MAKE tree VIEWED AS COLLECTION */ + /* operator map: (op(seqaccess)) -> impl(llvm_array | on_the_fly); */ +} + +import raw("core/containers.lp") + + + // PROGRAM +XmlNode = type alias { + tag:: string, + /* attrs:: [string],*/ + content:: string +}. + +Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]. +XmlTree = type alias Tree(XmlNode). + + +test= function:: num; entry { + filename = "scripts/containers/Containers_Implementation_LinkedList1-data.xml" :: string. + docRaw = xmlParseFile(filename) :: xmlDocPtr. + tree= xmlDocGetRootElement(docRaw) :: xmlNodePtr. + childrenRaw = tree["children"]:: [xmlNodePtr]; linkedlist(next, null). + size = loop fold(childrenRaw->child:: xmlNodePtr, 0->count):: int { + count +1::int + }. + + size +} + + diff --git a/scripts/containers/containers-indexed-1.xreate b/scripts/containers/containers-indexed-1.xreate deleted file mode 100644 index 69fd40c..0000000 --- a/scripts/containers/containers-indexed-1.xreate +++ /dev/null @@ -1,29 +0,0 @@ -//Expose indexes signature(anonymous): - a:: [(string, string, num)]; byName <- index(0); byCity <- index(1); - byNameAndCity <- index(0, 1). - -//Expose index signature(named) - type Record = - { - name:: string, - city:: string, - age:: num - }. - - b:: [Record]; byName <- index(Record.name). - -//Use determined index - x = a["Rabat"]:: Record; index(byCity). - -//Determined syntax(view) - viewByCity = a:: [Record]; index(byCIty). - x = viewByCity["Rabat"]. - -//Determined index(inline) - x = a[byCity: "Rabbat"]:: Record. - - -//Undefined index - x = a[{city: "Rabat"}] :: Record. <- index byCity should be deduced - x = a[{name: "Hind", city: "Rabat"}] - diff --git a/scripts/containers/containers.xreate b/scripts/containers/containers.xreate deleted file mode 100644 index 31ecddf..0000000 --- a/scripts/containers/containers.xreate +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * Show-case for a automatic adjustment of container implementations based on actual operations. - * Possible implementations: llvm_array, llvm_const_array, on_the_fly(unwinded container) - * - */ - -pass(dfa) { - operator map: (op(seqaccess)) -> impl(solid); - operator list_range: ()->impl(on_the_fly); - operator list: ()->impl(solid); - operator fold: (op(seqaccess)); - operator index: (op(randaccess)); - /* operator map: (op(seqaccess)) -> impl(llvm_array | on_the_fly); */ -} - -import raw("core/containers.lp"); - - -testfunc = function: ()->bool -{ - a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] : [num]; - a2 = [1 .. 100] : [num]; - - b = loop map (a1 -> el: num) : [num] - {2 * el;}; - - c = b : [num]; - - d = loop fold (a2->el: num, 0->acc: num): [num] - {acc + el;}; - - c[5]==d; -} - - diff --git a/scripts/exploitation/test1-fixture.lp b/scripts/exploitation/test1-fixture.lp deleted file mode 100644 index 491a935..0000000 --- a/scripts/exploitation/test1-fixture.lp +++ /dev/null @@ -1,50 +0,0 @@ -function(test1). -bind_func(test1, entry). -function(appendA; appendB; append). -scope(0..3). -%scope tags: no tags at all - -% Static analysis: CFA -cfa_parent(0, function(test1)). -cfa_parent(1, function(appendA)). -cfa_parent(2, function(appendB)). -cfa_parent(3, function(append)). -cfa_call(0, appendA). -cfa_call(0, appendB). -cfa_call(1, append). -cfa_call(2, append). - -% Static analysis: DFA -dfa_connection((2, 3), (anonym(0), 1), weak). %append:msg - anonym(0) -dfa_connection((3, 3), (anonym(1), 1), weak). %append:filename - anonym(1) -dfa_connection((0, 1), (0, 3), strong). %appendA: *retv - append: *retv -dfa_connection((2, 3), (anonym(2), 2), weak). %append:msg - anonym(2) -dfa_connection((3, 3), (anonym(3), 2), weak). %append:filename - anonym(3) -dfa_connection((0, 2), (0, 3), strong). %appendB: *retv - append: *retv - -v((anonym(0), 1)). %anonym(0) -v((anonym(1), 1)). %anonym(1) -v((0, 2)). %appendB: *retv -v((anonym(2), 2)). %anonym(2) -v((anonym(3), 2)). %anonym(3) -v((0, 3)). %append: *retv -v((2, 3)). %append:msg -v((3, 3)). %append:filename - -cfa_forwdom(0, range(0, 7)). -cfa_forwdom(1, range(1, 2)). -cfa_forwdom(2, range(5, 6)). -cfa_forwdom(3, range(3, 4)). -cfa_postdom(0, range(3, 4)). -cfa_postdom(1, range(1, 2)). -cfa_postdom(2, range(5, 6)). -cfa_postdom(3, range(0, 7)). - -% EXPLOITATION TAGS: -bind((3,3), exploitation_initialized(file)). - -% BIND ACTUAL DATA FOR STATIC SYMBOLS -bind((anonym(0), 1), static(data(a))). %anonym(0) -bind((anonym(1), 1), static(data(tmp_test1_txt))). %anonym(1) -bind((anonym(2), 2), static(data(b))). %anonym(2) -bind((anonym(3), 2), static(data(tmp_test1_txt))). %anonym(3) diff --git a/scripts/exploitation/test1.xreate b/scripts/exploitation/test1.xreate deleted file mode 100644 index cc8eced..0000000 --- a/scripts/exploitation/test1.xreate +++ /dev/null @@ -1,38 +0,0 @@ -test1 = function :: int; entry { - appendA() + appendB -} - -appendA = function:: int { - append("a", "/tmp/test1.txt") -} - -appendB = function:: int { - append("b", "/tmp/test1.txt") -} - -append:: function(message::string, filename::string):: int, -{ - f = initialize(filename):: FILE. - - fprintf(f, message) -} - -====================================================== -initialize(filename:: string; exploitation_file_initialized) -{ - // get cached descriptor for FileName: - files:: cached(exploitation_files). - - files[filename] -} - -attach scope:: openFile(FileName) { - fid = fopen(FileName). - (FileName, fid):: cached(exploitation_files). -} - -attach scope:: closeFile(FileName){ - files:: cached(exploitation_files). - fid = files[FileName]. - fclose(fid) -} diff --git a/scripts/function-modifications/current b/scripts/function-modifications/current deleted file mode 100644 index 1cbf57d..0000000 --- a/scripts/function-modifications/current +++ /dev/null @@ -1,92 +0,0 @@ -interface(extern-c){ -xml2 = library:: pkgconfig(\"libxml-2.0\") - [\"libxml/tree.h\"]. - -include [xml2]. -} - - -a = function()::int; - enrty; bug(2530) -{ - - -} - -interface(cfg){ - context operator map:: hfgfgfgf - context function a:: optimization: mem -} - -function a :: entry; -} - -a::int. - - -result = fold(vector->el, zero -> acc) { - -} - - -main:: entry; bug(2711); unsafe; permissions(usb_access) = function(a::int, b::int)::string; { -} - -a = function() -context -main = function (a::xxs, b::fefe -> r::fdfd):: fdfdfd case attr x:: AA, BB - { - - context:: { - frdkfkfe - } - - } - - case attr - { - a() + b(). - } - - { - - - } - - context:: optimization: mem; warnings: off - { - - } { - - case { - result = a() + b() :: - } - - case a::odd { - - } - - context - result = a() + b() :: odd. - - result = a()::odd + b(). -} - - -a = function() {}{}{}{} {}{}{}{}{}{}{}{}{}{}{}{}{} - -argument -function -result -function context - -annotation several values, annotation sole value; -function xxs;fdfdfd;fdfd, fdfd;qwqwq;trtrt;iui, aaa;bbb -> qqq; www - :: entry - - case { - - a() + b() - } - - diff --git a/scripts/function-modifications/data-context.lp b/scripts/function-modifications/data-context.lp deleted file mode 100644 index 8b13789..0000000 --- a/scripts/function-modifications/data-context.lp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/scripts/metatests/aux/graphs_trees_depth-test1.lp b/scripts/metatests/aux/graphs_trees_depth-test1.lp deleted file mode 100644 index 00f89f7..0000000 --- a/scripts/metatests/aux/graphs_trees_depth-test1.lp +++ /dev/null @@ -1,9 +0,0 @@ -#include "core/aux/graphs_trees_depth.lp". - -graphs_node(a; b; c; d). -graphs_tree_depends(b,a). -graphs_tree_depends(c,a). -graphs_tree_depends(d, a). -graphs_tree_depends(d, c). - -#show graphs_tree_depth/2. \ No newline at end of file diff --git a/scripts/metatests/aux/graphs_trees_depth-test2.lp b/scripts/metatests/aux/graphs_trees_depth-test2.lp deleted file mode 100644 index 630d807..0000000 --- a/scripts/metatests/aux/graphs_trees_depth-test2.lp +++ /dev/null @@ -1,8 +0,0 @@ -#include "core/aux/graphs_trees_depth.lp". - -graphs_node(a; b; c). -graphs_tree_depends(b,a). -graphs_tree_depends(b,c). -graphs_tree_depends(c,b). - -#show graphs_tree_depth/2. \ No newline at end of file diff --git a/scripts/precompilation-1.lp b/scripts/precompilation-1.lp deleted file mode 100644 index 1c14007..0000000 --- a/scripts/precompilation-1.lp +++ /dev/null @@ -1,11 +0,0 @@ -%%DATA EMBEDDING: - %bind(S, static(Data)):- Data= ref(_); bind(SymbolFrom, static(Data)); dfa_connection(S, SymbolFrom, _). - %bind(S, static(ref(Root))):- Data= data(_); bind(Root, static(Data)); dfa_connection(S, Root, _). - -%% SCHEME: - % bind(S, static). - % dfa_static(S, data(Data)) - % dfa_static(S, ref(RootSymbol)) - -bind(S2, static) :- bind(S1, static): dfa_connection(S2, S1, _). - diff --git a/scripts/sprint1_environment/current b/scripts/sprint1_environment/current deleted file mode 100644 index ba337ec..0000000 --- a/scripts/sprint1_environment/current +++ /dev/null @@ -1,8 +0,0 @@ -// install cmake -// install llvm -// install gcc -// install gtest - -function():: testEnvironment(exists(gcc)){ - exec("gcc -v") :: expectNoErrors. -} diff --git a/scripts/sprint1_environment/sprint1-Installation1.xreate b/scripts/sprint1_environment/sprint1-Installation1.xreate deleted file mode 120000 index 31eab23..0000000 --- a/scripts/sprint1_environment/sprint1-Installation1.xreate +++ /dev/null @@ -1 +0,0 @@ -/private/prg/code/xreate/scripts/testspass/sprint1-Installation1.xreate \ No newline at end of file diff --git a/scripts/sprint1_environment/xreate-environment b/scripts/sprint1_environment/xreate-environment deleted file mode 100644 index 149efed..0000000 --- a/scripts/sprint1_environment/xreate-environment +++ /dev/null @@ -1,73 +0,0 @@ -// install cmake -// install llvm -// install gcc -// install gtest - -EXISTS(gcc) = function(){ - exec("gcc -v") :: ExpectNoErrors; log("Check gcc"). -} - -function():: provide(gcc) { - exec("sudo apt-get install gcc"):: log("[GCC] Installation"). -} - -function():: TestEnvironment(exists(cmake)){ - exec("cmake /V"):: ExpectNoErrors; log("Check cmake"). -} - -function():: provide(cmake) { - exec("sudo apt-get install cmake"):: log("[CMake] Installation"). -} - -function():: TestEnvironment(exists(subversion)){ - exec("svn --version"):: ExpectNoErrors; log("Check svn"). -} - -function():: provide(subversion) { - exec("sudo apt-get install subversion"):: log("[Subversion] Installation"). -} - -function():: TestEnvironment(exists(scons)){ - exec("scons -v"):: ExpectNoErrors; log("Check scons"). -} - -function():: provide(scons) { - exec("sudo apt-get install scons"):: log("[Scons] Installation"). -} - -function():: TestEnvironment(exists(bison)){ - exec("bison --version"):: ExpectNoErrors; log("Check bison"). -} - -function():: provide(bison) { - exec("sudo apt-get install bison"):: log("[Bison] Installation"). -} - -//FEATURE dependent packages: Subversion -function():: provide(gringo) -{ - exec("cd /opt"). //FEATURE states: dir("/opt") - exec("svn://svn.code.sf.net/p/potassco/code/trunk") - :: log("[Potassco] cloning latest version"); - require(svn); require(rights("/opt", WRITE)). //"sudo chown -R user ./potassco" - - // - exec("scons --build-dir=release"):: require(scons) -} - - -function()::depends(env(gringo)){ - -} - -exec(cmd::string) = procedure { - system(cmd)::ErrorCodeResult. -} - -procedure :: EnvironmentTest(gcc) { - exec("gcc -v")::ExpectNoErrors. -} - -EnvironmentProvider(gcc) = procedure { - exec("sudo apt-get install gcc"):: log("[GCC] Installation"). -} \ No newline at end of file diff --git a/scripts/testspass/Containers_Implementation_LinkedList1.xreate b/scripts/testspass/Containers_Implementation_LinkedList1.xreate deleted file mode 100644 index 8340f56..0000000 --- a/scripts/testspass/Containers_Implementation_LinkedList1.xreate +++ /dev/null @@ -1,47 +0,0 @@ - - // EXTERN INCLUDES -interface(extern-c){ - xml2 = library:: pkgconfig("libxml-2.0"). - - include { - xml2 = ["libxml/tree.h"] - }. -} - - // CONTAINERS -interface(dfa) { - operator map:: (op(seqaccess)) -> impl(solid). - operator list_range:: ()->impl(on_the_fly). - operator list:: ()->impl(solid). - operator fold:: (op(seqaccess)). - /* operator index:: (op(randaccess)). - BREAKS THE ANALYSIS. MAKE tree VIEWED AS COLLECTION */ - /* operator map: (op(seqaccess)) -> impl(llvm_array | on_the_fly); */ -} - -import raw("core/containers.lp") - - - // PROGRAM -XmlNode = type alias { - tag:: string, - /* attrs:: [string],*/ - content:: string -}. - -Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]. -XmlTree = type alias Tree(XmlNode). - - -test= function:: num; entry { - filename = "scripts/testspass/Containers_Implementation_LinkedList1-data.xml" :: string. - docRaw = xmlParseFile(filename) :: xmlDocPtr. - tree= xmlDocGetRootElement(docRaw) :: xmlNodePtr. - childrenRaw = tree["children"]:: [xmlNodePtr]; linkedlist(next, null). - size = loop fold(childrenRaw->child:: xmlNodePtr, 0->count):: int { - count +1::int - }. - - size -} - - diff --git a/scripts/testspass/log.xreate b/scripts/testspass/log.xreate deleted file mode 100644 index 997edf1..0000000 --- a/scripts/testspass/log.xreate +++ /dev/null @@ -1,64 +0,0 @@ -/* - - Log level: - Log entry(flat, hierarchical) - -*/ - - - - - // EXTERN INCLUDES -interface(extern-c){ - xml2 = library:: pkgconfig("libxml-2.0"). - - include { - xml2 = ["libxml/tree.h", "string.h"] - }. -} - - // CONTAINERS -interface(dfa) { - operator map:: (op(seqaccess)) -> impl(solid). - operator list_range:: ()->impl(on_the_fly). - operator list:: ()->impl(solid). - operator fold:: (op(seqaccess)). - operator index:: (op(randaccess)). - /* operator map: (op(seqaccess)) -> impl(llvm_array | on_the_fly); */ -} - -import raw("core/containers.lp"). - - - // PROGRAM -XmlNode = type alias { - tag:: string, - /* attrs:: [string],*/ - content:: string -}. - -Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]. -XmlTree = type alias Tree(XmlNode). - - -test= function():: num; entry { - filename = "project/documentation.fodt" :: string. - docRaw = xmlParseFile(filename) :: xmlDocPtr. - tree= xmlDocGetRootElement(docRaw) :: xmlNodePtr. - childrenRaw = tree["children"]:: [xmlNodePtr]; containers:linkedlist(next, null). - size = loop fold(childrenRaw->child:: xmlNodePtr, 0->count::int):: int { - -// $log{ -// count +1:: warning, subsystem=xml -// } - - - //log{warning, subsystem=xml, ..} - childName = child["name"]::string; logging. - count + strlen(childName):: int - }. - - size -} - - diff --git a/scripts/testspass/sprint1-Installation1.xreate b/scripts/testspass/sprint1-Installation1.xreate deleted file mode 100644 index e02797f..0000000 --- a/scripts/testspass/sprint1-Installation1.xreate +++ /dev/null @@ -1,100 +0,0 @@ -import raw ("core/dependencies.lp") -import raw ("core/control-context.lp") -import raw ("core/unit-tests.lp") - -InstallationStatus = type variant(NOT_INSTALLED, INSTALLED). - -interface(adhoc){ - pre function expectNoErrors:: InstallationStatus { - case Error {NOT_INSTALLED} - case Success {INSTALLED} - } -} - -interface(extern-c){ - libFake = library:: pkgconfig("libxml-2.0"). - - include { - libFake = ["stdio.h", "stdlib.h"] - }. -} - -exec = pre function(comm:: string) { - result = system(comm):: num. - - if (result==0)::InstallationStatus - {ad hoc "Success"} - else {ad hoc "Error"} -} - -start = function:: int; entry { - context:: goal(artefact(gcc)). - - provideGoals() -} - -provideGoals = function:: int { - loop context ("goal") { - provideArtefact() - } -} - -provideArtefact = function:: int{ - switch (actionEXISTS())::int - - case INSTALLED {0} - - case NOT_INSTALLED { - sequence [ - provideDependencies(), - actionPROVIDE() - ] - } - - case default {-1} -} - -provideDependencies = function::int { - rule context:: childs(Child) - case artefact(Item) { - artefact_depends(Item, Child) - } - - loop context ("childs") { - provideArtefact() - } -} - -case context:: artefact(subversion) { - actionEXISTS = function::int { - context:: expectNoErrors. - - exec("svn --version") - } - - actionPROVIDE = function::int { - context:: expectNoErrors. - - exec("sudo apt-get install subversion") - } -} - -actionEXISTS = function::int { - -1 -} - -actionPROVIDE = function::int { - -1 -} - - -// DRAFT -/* - flagIsProvided = if(dictProvided()) {true} else - dictProvided = dictProvided + - -expectErrorCode = pre function(x::int){ - if (x==0)::bool {ad hoc "Success"} - else {ad hoc "Error"} -} -*/ diff --git a/scripts/testspass/xml-test1.xreate b/scripts/testspass/xml-test1.xreate deleted file mode 100644 index f5388c9..0000000 --- a/scripts/testspass/xml-test1.xreate +++ /dev/null @@ -1,142 +0,0 @@ -/* C++ SECTION -Example of c++ code: - - xmlDocPtr doc; - xmlNodePtr cur; - doc = xmlParseFile(docname.c_str()); - if (doc == NULL ) { - fprintf(stderr,"Document not parsed successfully. \n"); - return; - } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - fprintf(stderr,"empty document\n"); - xmlFreeDoc(doc); - return; - } - - cur = cur->xmlChildrenNode; - while (cur != NULL) { - printf("child: %s\n", cur->name); - - cur = cur->next; - } - -*/ - -/* FEATURES SECTION - - Default strategies: - - what to do with unspecified nodes - - Node content strategy: - - send as-is - - apply transforms (all / named) - - ?? skip - - Processing order: - - dependencies - - Mapping: - * tree -> list - -*/ - -/* TODO SECTION - -- gather types aliases (tree->list mapping) - -- flyweight implementation ('doc' field calculation, for example. based on are there more than one opened document ) -*/ - -// REQUIREMENTS SECTION -/* require ptrvalid */ -/* local scope doc ptr */ -/* singleton element check(::single) */ - -XmlAttr = type alias { - name:: string, - content:: string -}. - -XmlNode = type alias { - name:: string, /* the name of the node, or the entity */ - - content:: string, /* the content */ - attributes::[XmlAttr] /* properties list */ - - /* - children:: [xmlNode], // parent->childs link - - void *_private; // application data - struct _xmlNode *parent; // child->parent link - struct _xmlNode *next; // next sibling link - struct _xmlNode *prev; // previous sibling link - struct _xmlDoc *doc; // the containing document - unsigned short line; // line number - */ -}. - -interface(extern-c){ - xml2 = library:: pkgconfig("libxml-2.0"). - - include { - xml2 = ["libxml/tree.h", "string.h"] - }. -} - -Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]. -XmlTree = type alias Tree(XmlNode). - -toXmlNode = function (nodeRaw:: xmlNodePtr):: XmlNode -{ - propertiesRaw = nodeRaw["properties"]:: [xmlAttrPtr]; containers:linkedlist(next, null). - properties = loop map(propertiesRaw -> property::xmlAttrPtr)::[XmlAttr]{ - {name=property["name"], content=property["children", "content"]} - }. - - {name = nodeRaw["name"], - content=nodeRaw["content"], - attributes=properties} -} - -children = function(nodeRaw::xmlDocPtr)::[XmlTree] { - childrenRaw = nodeRaw["children"]:: [xmlDocPtr]; containers:linkedlist(next, null). - - children = loop map(childrenRaw->child:: xmlDocPtr) :: [XmlTree]{ - [toXmlNode(child), children(child)] - }. - - children -} - -document = function (filename:: string):: XmlTree -{ - docRaw = xmlParseFile(filename) :: xmlDocPtr. - nodeRaw= xmlDocGetRootElement(docRaw) :: xmlNodePtr. - - [toXmlNode(nodeRaw), children(nodeRaw)]:: XmlTree -} - -traverse = function(tree:: XmlTree) :: [XmlNode] { - listOfNodes = loop fold(tree -> node:: XmlTree, []->acc):: [XmlNode]{ - acc + node[0] + traverse(node[1]):: [XmlNode] - }. - - listOfNodes -} - -test1 = function:: int; entry { - filename = "project/documentation.fodt" :: string. - - root = document(filename):: XmlTree. - nodesAll = traverse(root):: [XmlNode]. - - result = loop fold(nodesAll->node:: XmlNode, 0->count):: int{ - count + if (0==strcmp(node["name"], "section")) :: int { - 1 - } else { - 0 - } - }. - - result -} diff --git a/scripts/trash/ftransform.li b/scripts/trash/ftransform.li deleted file mode 100644 index d75c454..0000000 --- a/scripts/trash/ftransform.li +++ /dev/null @@ -1,26 +0,0 @@ -//преобразование параметров функции - -function(first-function, vars-list(var(x, i32), var(y, i32)), i32, - div(add(x, 5), y)) - --------------------------------------------------------------------------------------------------- - -type(name(ListNode), struct( - field(name(caption), type(String)), - field(name(args), type(collection(ListNode))) -)) - - - -transform( - name(f-transform), guard(var(name(X), constraints(caption(simple-function)))), - body( - set (args, field(X, args), - - - wrap(extract(args, 0), caption(name)), - - wrap - name(field()) - ) -) diff --git a/scripts/trash/intersection.li2 b/scripts/trash/intersection.li2 deleted file mode 100644 index 6ce957a..0000000 --- a/scripts/trash/intersection.li2 +++ /dev/null @@ -1,93 +0,0 @@ -// пример реализации процедуры определения пересечения двух множеств -// -// -// A, B - два множества - - -Iterator (Set set) : (Set set, int pos) - -next(Iterator Set i): action of Iterator{ - pos++; - - return i; -} - -written El_Type x = Iterator/Set/El_Type i : substitution{ - x = i.pos; -} - - -A overtake B: action of Iterator { - elB = current (B); //эта команда может превратиться просто в использование elA из вызывающей функции, используя аннотацию context или bag - - repeat-post elA elB) - elB = B overtake A; - else - elA = A overake B; - - if (elA == elB) - put(RESULT-SET, elA); - -return RESULT-SET -} - -// repeat - бесконечный повтор? -// repeat-pre - повтор с предусловием, repeat-post - повтор с постусловием - - - - - Работа с Map: - Пример отображения(view), пример №1: - -Map/(KEY, VALUE): type = [(KEY, VALUE)]; - -Map-T ([KEY], [VALUE]): view, pairs: Map/(KEY, VALUE) = { - keys = map pairs, pair - (key, ) = pair; - key - - values = map pairs, pair - (, value) = pair; - value - - return (keys, values) -} - -//(SELECT key, SELECT value) - возможно ли в функцию передавать названия поля, с кот. ей нужно работать.. ? - - Пример №2 (свести к поиску 6): - -find6: function = { -x: [int] = [1, 2, 3, 4, 5, 6, 7]; //эффективная инициализация! - -y = map x, el - 2 * el - -return exists(x, 12); -} - - -/** - * Построить: - * сортировка :- необходимо ordered-list(linked-list, tree-list) - * RA доступ :- желательно hash-list или желательно tree-list - * последовательный доступ :- желательно ordered-list - * - * -Necessarily and ◇ for Possibly \ No newline at end of file diff --git a/scripts/trash/opcode.comments b/scripts/trash/opcode.comments deleted file mode 100644 index 31c457b..0000000 --- a/scripts/trash/opcode.comments +++ /dev/null @@ -1,30 +0,0 @@ - -/* - -ASTLispNode - - -transform( - - function(__name, __vars), function(name(__name), vars-list(__vars), body(function.body) -) -*/ - - -add(y, div(add(x, 5), 15)))) - - -opcode(add, LLVMAddInstruction) -opcode(div, LLVMDivideInstruction) - -function(name(first-function), - vars-list(var(name(x), type(i32)), var(name(y), type(i32))), - return(type(i32)), - body( - div(add(x, 5), y))) - -function (name(second-f), vars-list, return(type(i32)), body( - add(add (10, 20), first-function(11, 80)) -)) - -main(second-f) \ No newline at end of file diff --git a/scripts/trash/opcode.li b/scripts/trash/opcode.li deleted file mode 100644 index 5f62311..0000000 --- a/scripts/trash/opcode.li +++ /dev/null @@ -1,14 +0,0 @@ -opcode(add, LLVMAddInstruction) -opcode(div, LLVMDivideInstruction) - -function(name(first-function), - vars-list(var(name(x), type(i32)), var(name(y), type(i32))), - return(type(i32)), - body( - div(add(x, 5), y))) - -function (name(second-f), vars-list, return(type(i32)), body( - add(add (10, 20), first-function(80, 11)) -)) - -main(second-f) \ No newline at end of file diff --git a/scripts/xml/[old] xml-client.xreate b/scripts/xml/[old] xml-client.xreate deleted file mode 100644 index 5ea610f..0000000 --- a/scripts/xml/[old] xml-client.xreate +++ /dev/null @@ -1,112 +0,0 @@ -/* - -Example of c++ code: - - xmlDocPtr doc; - xmlNodePtr cur; - doc = xmlParseFile(docname.c_str()); - if (doc == NULL ) { - fprintf(stderr,"Document not parsed successfully. \n"); - return; - } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - fprintf(stderr,"empty document\n"); - xmlFreeDoc(doc); - return; - } - - cur = cur->xmlChildrenNode; - while (cur != NULL) { - printf("child: %s\n", cur->name); - - cur = cur->next; - } - -*/ - -/* - - Default strategies: - - what to do with unspecified nodes - - Node content strategy: - - send as-is - - apply transforms (all / named) - - ?? skip - - Processing order: - - dependencies - - */ - - default_filname = "project/documentation.fodt" : string; - -/* require ptrvalid */ -/* local scope doc ptr */ - -XmlNode = type { - tag: string; - attrs: [string]; - content: string}. - -Tree = type(Leaf) Tree [Leaf; [Tree(Leaf)]]; - -XmlTree = Tree(XmlNode); - - -children = function: (tree: xmlNodePtr)->XmlTree -{ - childrenRaw = tree[xmlChildrenNode]: [xmlNodePtr], linkedlist(next, null); - - map (childrenRaw->childRaw: xmlNodePtr) { - Tree[childRaw[name] children(childRaw)] - } -} - - -document = function: (filename: string)->XmlTree -{ - docRaw = xmlParseFile(docname.c_str()) : xmlDocPtr; - nodeRaw= xmlDocGetRootElement(docRaw) : xmlNodePtr; - - Tree [nodeRaw[name] children(nodeRaw)); -} - - -query = function(tree: XmlTree): [XmlTree] -{ - children : context(children) = - case default - [] - - case (tree[0]: NeedChildren(childrenFilters), ApplyTransform(transFilters)) - { - loop fold (tree[1]->child: Tree(Leaf) | childrenFilters; []->accum). - {accum + traverse(child): cases(transFilters) }; - } - - node = - case (node.tag == "style:style"; class = node[attrs, "style:name"]; exists(class, ParaKnownClasses)) - { - [class, node[attrs, "style:display-name"]]; - } - - case default - [] ; - - Tree[node children] | node + children -} - -test = function: ()->num -{ - data = query(document(default_filename)): [string, string]; - - exists(data, "pgess1"). -} - - /* -traverse = function(trees: [XmlTree]) : [XmlTree] - loop fold(trees->tree: Tree; []->acc) - acc + traverse(tree) - */ \ No newline at end of file diff --git a/scripts/xml/all.xreate b/scripts/xml/all.xreate deleted file mode 100644 index 3cd606f..0000000 --- a/scripts/xml/all.xreate +++ /dev/null @@ -1,188 +0,0 @@ -/* C++ SECTION -Example of c++ code: - - xmlDocPtr doc; - xmlNodePtr cur; - doc = xmlParseFile(docname.c_str()); - if (doc == NULL ) { - fprintf(stderr,"Document not parsed successfully. \n"); - return; - } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - fprintf(stderr,"empty document\n"); - xmlFreeDoc(doc); - return; - } - - cur = cur->xmlChildrenNode; - while (cur != NULL) { - printf("child: %s\n", cur->name); - - cur = cur->next; - } - -*/ - -/* FEATURES SECTION - - Default strategies: - - what to do with unspecified nodes - - Node content strategy: - - send as-is - - apply transforms (all / named) - - ?? skip - - Processing order: - - dependencies - - Mapping: - * tree -> list - -*/ - -/* TODO SECTION - -- gather types aliases (tree->list mapping) - -- flyweight implementation (doc calculation, for example. based on are there more than one opened document ) -*/ - -// REQUIREMENTS SECTION -/* require ptrvalid */ -/* local scope doc ptr */ -/* singleton element check(::single) */ - -XmlAttr = type alias { - name:: String, - content:: String -}. - -XmlNode = type alias { - name:: String, /* the name of the node, or the entity */ - children:: [xmlNode], /* parent->childs link */ - content:: String, /* the content */ - attributes::[XmlAttr] /* properties list */ - - /* - void *_private; // application data - struct _xmlNode *parent; // child->parent link - struct _xmlNode *next; // next sibling link - struct _xmlNode *prev; // previous sibling link - struct _xmlDoc *doc; // the containing document - unsigned short line; // line number - */ -}. - -interface(extern-c){ - xml2 = library:: pkgconfig("libxml-2.0"). - - include { - xml2 = ["libxml/tree.h", "string.h"] - }. -} - -Tree = type Tree(Leaf) [Leaf, [Tree(Leaf)]]. -XmlTree = type alias Tree(XmlNode). - -find = .. -[xmlNodePtr]; containers:linkedlist(next, null). - - - -test1 = function():: int; entry { - dictAliases = dictAliases():: AliasList. - - count = loop fold(dictAliases->alias::Alias, 0->count::int):: int{ - aliasName = alias[0]:: String; logging. - aliasOrigClass = alias[1]::String; logging. - - count + 1 - } - - count -} - -/* -toXmlNode = function (nodeRaw:: xmlNodePtr):: XmlNode -{ - {tag = nodeRaw["name"], content=null} -} - - -children = function (tree:: xmlNodePtr):: XmlTree -{ - childrenRaw = tree["xmlChildrenNode"]:: [xmlNodePtr]; containers:linkedlist(next, null). - - loop map (childrenRaw->childRaw:: xmlNodePtr):: XmlTree { - [toXmlNode(childRaw), children(childRaw)] - } -} - - -document = function (filename:: string):: XmlTree -{ - docRaw = xmlParseFile(filename) :: xmlDocPtr. - nodeRaw= xmlDocGetRootElement(docRaw) :: xmlNodePtr. - - [toXmlNode(nodeRaw), children(nodeRaw)]:: XmlTree -} - -*/ - -Alias = type alias { - alias: String, - original: String -}. - -AliasList = type alias [Alias]. - -classesPar = ["pgess1", "pgess2"] :: [String]. -classesAliasQuery = function(node:: xmlNodePtr):: Alias -{ - result = - case default {none} - - case node[tag] == "style", class in classesPara, - classAlias = node[attrs, "name"], - class=node[attrs, "parent-style-name"], - { - [classAlias. class] - }. - - result. -} - - - -dictAliases = function():: AliasList{ - filename = "project/documentation.fodt" :: string. - docRaw = xmlParseFile(filename) :: xmlDocPtr. - tree= xmlDocGetRootElement(docRaw) :: xmlNodePtr. - - nodeStylesRoot = findNodes(tree, "office:automatic-styles"):: xmlNodePtr; single. - nodesStyles= findNodes(nodeStylesRoot, "style:style"):: [xmlNodePtr]. - - nodesChildAliases = filter(nodeStyles){ - "style:parent-style-name" in classesPar - } - - dictChildAliases = loop fold(nodesChilds->node:: xmlNodePtr, []->aliases::[Alias]) { - aliases + {alias = attr(node, "style:name"), original = attr(node, "style:parent-style-name")} - }. - - nodesDisplayAliases = filter(nodesStyles){ - "style:parent-style-name" in classesPar - } - - dictDisplayAliases = loop fold(nodesDisplayAliases->node:: xmlNodePtr, []->aliases::[Alias]) { - aliases + {alias = attr(node, "style:display-name"), original = attr(node, "style:name")} - }. - - nodesDisplayAliases + dictDisplayAliases -} - - - - - - diff --git a/scripts/xml/xml-test1.xreate b/scripts/xml/xml-test1.xreate deleted file mode 120000 index a65ed28..0000000 --- a/scripts/xml/xml-test1.xreate +++ /dev/null @@ -1 +0,0 @@ -/private/prg/code/xreate/scripts/testspass/xml-test1.xreate \ No newline at end of file