def _parse_literal(self, tokens, index): bits = [] while True: if index >= len(tokens): return expr.LiteralExpr(bits), index elif tokens[index] == '0': bits.append(False) elif tokens[index] == '1': bits.append(True) elif tokens[index] == '_': return expr.LiteralExpr(bits), index + 1 else: return expr.LiteralExpr(bits), index index = index + 1
def placeholder(self, e): if self.inside_cond: try: return expr.LiteralExpr(self.mapping[e.var], pos=e.pos) except KeyError: pass return e
def _get_clean_commands(self, mk_fmt, expr_fmt, graphs, submakefiles): if self.uses_builddir: for e in self.autoclean_extensions: p = expr.PathExpr([expr.LiteralExpr("*." + e)], expr.ANCHOR_BUILDDIR) yield "%s %s" % (self.del_command, expr_fmt.format(p)) for g in graphs: for node in g.all_nodes(): for f in node.outputs: try: if f.get_extension() not in self.autoclean_extensions: yield "%s %s" % (self.del_command, expr_fmt.format(f)) except CannotDetermineError: yield "%s %s" % (self.del_command, expr_fmt.format(f)) for subname, subdir, subfile, subdeps in submakefiles: yield mk_fmt.submake_command(subdir, subfile, "clean")
def _make_build_nodes_for_file(toolset, target, srcfile, ft_to, files_map): src = srcfile.filename assert isinstance(src, expr.PathExpr) ext = src.get_extension() # FIXME: don't use target_basename.o form for object files, use just the basename, # unless there's a conflict between two targets if srcfile in files_map: objbase = files_map[srcfile] else: objbase = src.get_basename() objname = expr.PathExpr( [expr.LiteralExpr("%s_%s" % (target.name, objbase))], expr.ANCHOR_BUILDDIR, pos=src.pos).change_extension(ft_to.extensions[0]) ft_from = get_file_type(ext) compiler = get_compiler(toolset, ft_from, ft_to) if compiler is None: # Try to compile into source file, then into binaries. A typical use of # this is flex/bison parser generator. for ft_source in get_file_types_compilable_into(toolset, ft_to): if get_compiler(toolset, ft_from, ft_source) is not None: compilables, allnodes = _make_build_nodes_for_file( toolset, target, srcfile, ft_source, files_map) objects = [] for o in compilables: for outf in o.outputs: objn, alln = _make_build_nodes_for_file( toolset, target, model.SourceFile(target, outf, None), ft_to, files_map) objects += objn allnodes += alln return (objects, allnodes) raise Error("don't know how to compile \"%s\" files into \"%s\"" % (ft_from.name, ft_to.name)) node = BuildNode(commands=compiler.commands(toolset, target, src, objname), inputs=[src] + list(srcfile["dependencies"]), outputs=[objname], source_pos=srcfile.source_pos) return ([node], [node])
def PrimaryExpr(self): _token_ = self._peek("r'\\('", "r'\\$'", "r'\\.'", 'FUNCNAME', 'NUMBER', 'DQUOTE', 'SQUOTE') if _token_ not in ["r'\\('", "r'\\$'", "r'\\.'", 'FUNCNAME']: Literal = self.Literal() return X.LiteralExpr(Literal) elif _token_ == "r'\\$'": VariableReference = self.VariableReference() return VariableReference elif _token_ == "r'\\('": self._scan("r'\\('") Expr = self.Expr() self._scan("r'\\)'") return Expr elif _token_ == "r'\\.'": ContextItemExpr = self.ContextItemExpr() return ContextItemExpr else: # == 'FUNCNAME' FunctionCall = self.FunctionCall() return FunctionCall
def std_target_props(): """Creates list of all standard target properties.""" return _std_model_part_props() + [ Property("id", type=IdType(), default=lambda t: expr.LiteralExpr(t.name), readonly=True, inheritable=False, doc="Target's unique name (ID)."), Property("deps", type=ListType(IdType()), default=[], inheritable=False, doc=""" Dependencies of the target (list of IDs). The dependencies are handled in target-specific ways. At the very least, they are added to the list of dependencies in generated makefiles or projects to ensure correct build order. Some targets may be smart about some kinds of the dependencies and do more. In particular, compiled targets (executables, DLLs) will automatically link against all libraries found in `deps`. """), Property("pre-build-commands", type=ListType(StringType()), default=[], inheritable=False, doc=""" Custom commands to run before building the target. The value is a list of shell commands to run. Notice that the commands are platform-specific and so typically need to be set conditionally depending on the value of ``toolset``. Currently only implemented by Visual Studio. """), Property("post-build-commands", type=ListType(StringType()), default=[], inheritable=False, doc=""" Custom commands to run after building the target. The value is a list of shell commands to run. Notice that the commands are platform-specific and so typically need to be set conditionally depending on the value of ``toolset``. Currently only implemented by Visual Studio. """), Property("configurations", type=ListType(StringType()), # FIXME: use a custom type that validates config names default="Debug Release", inheritable=True, doc=""" List of configurations to use for this target. See :ref:`configurations` for more information. """ ), ]
def srcdir_as_path(self): p = os.path.relpath(self.srcdir, start=self.project.top_module.srcdir) return expr.PathExpr( [expr.LiteralExpr(x) for x in p.split(os.path.sep)], anchor=expr.ANCHOR_TOP_SRCDIR)
def parse_body(self, fns): if len(self.body) == 0: self.expr = expr.LiteralExpr([]) else: self.expr = self._parse_exprs(self.body, 0, self.patterns, fns) del self.body