diff options
author | Klaas Boesche <klaasb@google.com> | 2015-11-06 12:16:03 +0000 |
---|---|---|
committer | Florian Weikert <fwe@google.com> | 2015-11-06 16:40:00 +0000 |
commit | 0ec13b9f03417142ca63b9fe1eb85827d6308233 (patch) | |
tree | 5350445840d49888fcebc98a28d6b9182d71c85a /src/main/java/com/google/devtools/build/lib/syntax/compiler/LoopLabels.java | |
parent | 976f1b657bb45c5cb58d48327ce05babe9cd4cdf (diff) |
Add initial Skylark byte code generation code.
Does not yet contain any implementation for expressions and statements
but sets up various needed mechanisms and helper classes.
--
MOS_MIGRATED_REVID=107222845
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/compiler/LoopLabels.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/compiler/LoopLabels.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/compiler/LoopLabels.java b/src/main/java/com/google/devtools/build/lib/syntax/compiler/LoopLabels.java new file mode 100644 index 0000000000..e1bb9d36b1 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/syntax/compiler/LoopLabels.java @@ -0,0 +1,55 @@ +// Copyright 2015 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.syntax.compiler; + +import com.google.common.base.Optional; +import com.google.devtools.build.lib.syntax.FlowStatement.Kind; + +import org.objectweb.asm.Label; + +/** + * Container for passing around current loop labels during compilation. + */ +public class LoopLabels { + public final Label continueLabel; + public final Label breakLabel; + + private LoopLabels(Label continueLabel, Label breakLabel) { + this.continueLabel = continueLabel; + this.breakLabel = breakLabel; + } + + /** + * Only use Optional-wrapped instances of this class. + */ + public static Optional<LoopLabels> of(Label continueLabel, Label breakLabel) { + return Optional.of(new LoopLabels(continueLabel, breakLabel)); + } + + public static final Optional<LoopLabels> ABSENT = Optional.absent(); + + /** + * Get the label for a certain kind of flow statement. + */ + public Label labelFor(Kind kind) { + switch (kind) { + case BREAK: + return breakLabel; + case CONTINUE: + return continueLabel; + default: + throw new Error("missing flow kind: " + kind); + } + } +} |