Пример #1
0
function parseType($ast)
{
    assert_ast_type($ast, [NodeType::DT, NodeType::IDENTIFIER, NodeType::TYPEOF, NodeType::REFERENCE]);
    $ast_type = ast_node_type($ast);
    $source = ast_node_source($ast);
    switch ($ast_type) {
        case NodeType::TYPEOF:
            return parseTypeOf($ast);
            break;
        case NodeType::IDENTIFIER:
            $name = parseIdentifier($ast);
            return lookupType($name, []);
            break;
        case NodeType::DT:
            $info = parseDataType($ast);
            grokit_assert($info->isDataType(), 'Performed lookup expecting DataType, got ' . $info->kind() . ' instead ' . $source);
            return $info;
            break;
        case NodeType::REFERENCE:
            $info = parseReference($ast);
            grokit_assert($info->isDataType(), 'Performed alias lookup expecting DataType, got ' . $info->kind() . ' instead ' . $source);
            return $info;
            break;
    }
}
Пример #2
0
 /**
  * Take an array of data values,
  * Format them according to the field map
  * and save in a new object
  */
 function import($data, $mapping, $match_on)
 {
     global $database;
     if (!is_array($data) or empty($data) or empty($mapping)) {
         return FALSE;
     }
     $defs =& $this->getFieldMap();
     $class = get_class($this);
     $jObject = new $class($database);
     $mapped_fields = $params = array();
     foreach ($mapping as $column => $fieldmap) {
         if (array_key_exists($fieldmap, $defs)) {
             $field = $defs[$fieldmap];
             if (!isset($field['import']) or $field['import'] == FALSE) {
                 continue;
             } else {
                 $mapped_fields[$fieldmap] = parseDataType($data, $column, $field);
                 //array_push($mapped_fields, $fieldmap);
                 if (in_array($fieldmap, $match_on)) {
                     $params[$fieldmap] = $mapped_fields[$fieldmap];
                 }
             }
         } else {
             continue;
         }
     }
     if (!empty($params)) {
         $jObject = new $class($database);
         $jObject->loadByParams($params);
     }
     foreach ($mapped_fields as $key => $val) {
         $jObject->{$key} = $val;
     }
     foreach ($defs as $key => $def) {
         if (!array_key_exists($key, $mapped_fields)) {
             if (isset($def['default'])) {
                 $jObject->{$key} = $def['default'];
             }
         }
     }
     return $jObject->save();
 }
Пример #3
0
    function parseProgramHeaders($ast)
    {
        $headers = ast_get($ast, NodeKey::HEADER);
        ob_start();
        // Generate standard header with date of generation and copyright notice
        echo '// This file was automatically generated on ' . date('l jS \\of F Y h:i:s A') . PHP_EOL;
        echo '// Copyright 2013 Tera Insights, LLC. All Rights Reserved' . PHP_EOL;
        // Echo out the standard headers.
        echo <<<'EOT'
// Including GrokIt headers
#include <climits>
#include <fstream>

#include "HashFunctions.h"
#include "WorkDescription.h"
#include "ExecEngineData.h"
#include "Chunk.h"
#include "DataTypes.h"
#include "MMappedStorage.h"
#include "ColumnIterator.h"
#include "ColumnIterator.cc"
#include "BString.h"
#include "BStringIterator.h"
#include "Constants.h"
#include "QueryManager.h"
#include <string.h>
#include "Logging.h" // for profiling facility
#include "Profiling.h"
#include "WPFExitCodes.h"
#include "HashFunctions.h"
#include "Null.h"

EOT;
        // Implicit using base
        $base_dir = getenv('GROKIT_INSTALLED_LIBRARY_PATH');
        include_once $base_dir . DIRECTORY_SEPARATOR . 'base.php';
        foreach ($headers as $h) {
            $type = ast_node_type($h);
            switch ($type) {
                case NodeType::IMPORT:
                    parseImport($h);
                    break;
                case NodeType::DT:
                    parseDataType($h);
                    break;
                case NodeType::GLA:
                    $res = parseGLA($h);
                    $res->apply([], []);
                    break;
                case NodeType::GT:
                    $res = parseGT($h);
                    $res->apply([], []);
                    break;
                case NodeType::GF:
                    $res = parseGF($h);
                    $res->apply([]);
                    break;
                case NodeType::GIST:
                    $res = parseGIST($h);
                    $res->apply([]);
                    break;
                case NodeType::GI:
                    $res = parseGI($h);
                    $res->apply([]);
                    break;
            }
        }
        $ret = ob_get_clean();
        return $ret;
    }