示例#1
0
    def _visit_CommentLine(self, stmt):

        # if annotated comment

        if stmt.s.startswith('#$'):
            env = stmt.s[2:].lstrip()
            if env.startswith('omp'):
                return omp_parse(stmts=stmt.s)
            elif env.startswith('acc'):
                return acc_parse(stmts=stmt.s)
            elif env.startswith('header'):
                expr = hdr_parse(stmts=stmt.s)
                if isinstance(expr, MetaVariable):

                    # a metavar will not appear in the semantic stage.
                    # but can be used to modify the ast

                    self._metavars[str(expr.name)] = str(expr.value)
                    expr = EmptyNode()
                else:
                    expr.set_fst(stmt)

                return expr
            else:

                errors.report(PYCCEL_INVALID_HEADER,
                              symbol=stmt,
                              severity='error')

        else:
            txt = stmt.s[1:].lstrip()
            return Comment(txt)
示例#2
0
    def _visit_CommentNode(self, stmt):

        # if annotated comment

        if stmt.value.startswith('#$'):
            env = stmt.value[2:].lstrip()
            if env.startswith('omp'):
                txt = reconstruct_pragma_multilines(stmt)
                return omp_parse(stmts=txt)
            elif env.startswith('acc'):

                txt = reconstruct_pragma_multilines(stmt)
                return acc_parse(stmts=txt)
            elif env.startswith('header'):

                txt = reconstruct_pragma_multilines(stmt)
                expr = hdr_parse(stmts=txt)
                if isinstance(expr, MetaVariable):

                    # a metavar will not appear in the semantic stage.
                    # but can be used to modify the ast

                    self._metavars[str(expr.name)] = str(expr.value)

                    # return NewLine()

                    expr = EmptyLine()
                else:
                    expr.set_fst(stmt)

                return expr
            else:

                # TODO an info should be reported saying that either we
                # found a multiline pragma or an invalid pragma statement

                return NewLine()
        else:

            #                    errors.report(PYCCEL_INVALID_HEADER,
            #                                  bounding_box=stmt.absolute_bounding_box,
            #                                  severity='error')

            # TODO improve

            txt = stmt.value[1:].lstrip()
            return Comment(txt)
示例#3
0
    def _visit_CommentMultiLine(self, stmt):

        exprs = []
        # if annotated comment
        for com in stmt.s.split('\n'):
            if com.startswith('#$'):
                env = com[2:].lstrip()
                if env.startswith('omp'):
                    exprs.append(omp_parse(stmts=com))
                elif env.startswith('acc'):
                    exprs.append(acc_parse(stmts=com))
                elif env.startswith('header'):
                    expr = hdr_parse(stmts=com)
                    if isinstance(expr, MetaVariable):

                        # a metavar will not appear in the semantic stage.
                        # but can be used to modify the ast

                        self._metavars[str(expr.name)] = str(expr.value)
                        expr = EmptyNode()
                    else:
                        expr.set_fst(stmt)

                    exprs.append(expr)
                else:
                    errors.report(PYCCEL_INVALID_HEADER,
                                  symbol=stmt,
                                  severity='error')
            else:

                txt = com[1:].lstrip()
                exprs.append(Comment(txt))

        if len(exprs) == 1:
            return exprs[0]
        else:
            return CodeBlock(exprs)