コード例 #1
0
ファイル: grokit_codegen_expr.php プロジェクト: gokulp/grokit
function parseGT($ast)
{
    assert_ast_type($ast, [NodeType::GT, NodeType::REFERENCE]);
    $type = ast_node_type($ast);
    $data = ast_node_data($ast);
    $source = ast_node_source($ast);
    switch ($type) {
        case NodeType::GT:
            $name = ast_get($data, NodeKey::NAME);
            $t_args = parseTemplateArgs(ast_get($data, NodeKey::TARGS));
            $alias = ast_has($data, NodeKey::ALIAS) ? null : parseIdentifier(ast_get($data, NodeKey::ALIAS));
            return new GT_Spec($source, $name, $t_args, $alias);
            break;
        case NodeType::REFERENCE:
            $info = parseReference($ast);
            grokit_assert($info->isGT(), 'Tried to look up reference as a GT, got a ' . $info->kind() . 'instead ' . $source);
            return $info;
            break;
    }
}
コード例 #2
0
ファイル: grokit_ast.php プロジェクト: gokulp/grokit
function ast_node_data($ast)
{
    grokit_logic_assert(ast_has($ast, NodeKey::NODE_DATA), 'Attempted to get data of non-node value.');
    return ast_get($ast, NodeKey::NODE_DATA);
}
コード例 #3
0
ファイル: grokit_codegen_top.php プロジェクト: gokulp/grokit
 function parseSelectionWP($ast, $name, $header)
 {
     // Push LibraryManager so we can undo this waypoint's definitions.
     ob_start();
     LibraryManager::Push();
     $res = new GenerationInfo();
     /***************   PROCESS AST   ***************/
     $attMap = parseAttributeMap(ast_get($ast, NodeKey::ATT_MAP), $res);
     $qFilters = ast_get($ast, NodeKey::FILTERS);
     $qSynth = ast_get($ast, NodeKey::SYNTH);
     $queries = [];
     foreach ($qFilters as $query => $qInfo) {
         $filterAST = ast_get($qInfo, NodeKey::ARGS);
         $gfAST = ast_get($qInfo, NodeKey::TYPE);
         if ($gfAST !== null) {
             $filter = parseNamedExpressionList($filterAST);
         } else {
             $filter = parseExpressionList($filterAST);
         }
         $gf = null;
         if ($gfAST !== null) {
             $gf = parseGF($gfAST);
             $gf = $gf->apply($filter);
         }
         if (ast_has($qInfo, NodeKey::CARGS)) {
             $cargs = parseLiteralList(ast_get($qInfo, NodeKey::CARGS));
         } else {
             $cargs = [];
         }
         $sargs = ast_has($qInfo, NodeKey::SARGS) ? parseStateList(ast_get($qInfo, NodeKey::SARGS), $query) : [];
         $synths = array();
         $synthAST = ast_get($ast, NodeKey::SYNTH);
         if (ast_has($synthAST, $query)) {
             $curSynths = ast_get($synthAST, $query);
             foreach ($curSynths as $curSynthAST) {
                 $expr = parseExpression(ast_get($curSynthAST, NodeKey::EXPR));
                 $att = parseAttribute(ast_get($curSynthAST, NodeKey::ATT));
                 if ($att->type() == null) {
                     AttributeManager::setAttributeType($att->name(), $expr->type());
                     $att = AttributeManager::lookupAttribute($att->name());
                 } else {
                     if (canConvert($expr, $att->type())) {
                         $expr = convertExpression($expr, $att->type());
                     } else {
                         grokit_error('Unable to convert expression for synthesized attribute ' . $att->name() . ' from type ' . $expr->type() . ' to type ' . $att->type() . ' ' . $expr->source());
                     }
                 }
                 $synths[$att->name()] = $expr;
             }
         }
         $info = ['filters' => $filter, 'synths' => $synths, 'gf' => $gf, 'cargs' => $cargs, 'states' => $sargs];
         $queries[$query] = $info;
         $res->addJob($query, $name);
         $res->absorbInfoList($filter);
         $res->absorbInfoList($synths);
         $res->absorbInfoList($cargs);
         $res->absorbStateList($sargs);
         if ($gf !== null) {
             $res->absorbInfo($gf);
         }
     }
     /*************** END PROCESS AST ***************/
     // Get this waypoint's headers
     $myHeaders = $header . PHP_EOL . ob_get_clean();
     // Only one file at the moment
     $filename = $name . '.cc';
     $res->addFile($filename, $name);
     _startFile($filename);
     SelectionGenerate($name, $queries, $attMap);
     _endFile($filename, $myHeaders);
     // Pop LibraryManager again to get rid of this waypoint's declarations
     LibraryManager::Pop();
     return $res;
 }