зеркало из https://github.com/CryptoPro/go.git
- gofmt'ing of some stragglers, now with correct comment indentation
in special cases - re-gofmt'ing of some files that are now improved R=r, rsc http://go/go-review/1023003
This commit is contained in:
Родитель
6c13f8f10e
Коммит
8cd2e76404
|
@ -153,7 +153,10 @@ func walksymtab(data []byte, fn func(sym) os.Error) os.Error {
|
|||
// returning an in-memory representation.
|
||||
func NewTable(symtab []byte, pcln *LineTable) (*Table, os.Error) {
|
||||
var n int;
|
||||
err := walksymtab(symtab, func(s sym) os.Error { n++; return nil });
|
||||
err := walksymtab(symtab, func(s sym) os.Error {
|
||||
n++;
|
||||
return nil;
|
||||
});
|
||||
if err != nil {
|
||||
return nil, err;
|
||||
}
|
||||
|
@ -208,7 +211,7 @@ func NewTable(symtab []byte, pcln *LineTable) (*Table, os.Error) {
|
|||
fname[uint16(s.value)] = ts.Name;
|
||||
}
|
||||
lasttyp = s.typ;
|
||||
return nil
|
||||
return nil;
|
||||
});
|
||||
if err != nil {
|
||||
return nil, err;
|
||||
|
@ -345,7 +348,7 @@ func (t *Table) PCToFunc(pc uint64) *Func {
|
|||
// If there is no information, it returns fn == nil.
|
||||
func (t *Table) PCToLine(pc uint64) (file string, line int, fn *Func) {
|
||||
if fn = t.PCToFunc(pc); fn == nil {
|
||||
return
|
||||
return;
|
||||
}
|
||||
file, line = fn.Obj.lineFromAline(fn.LineTable.PCToLine(pc));
|
||||
return;
|
||||
|
@ -427,7 +430,7 @@ func (o *Obj) lineFromAline(aline int) (string, int) {
|
|||
start int;
|
||||
offset int;
|
||||
prev *stackEnt;
|
||||
};
|
||||
}
|
||||
|
||||
noPath := &stackEnt{"", 0, 0, nil};
|
||||
tos := noPath;
|
||||
|
@ -547,4 +550,3 @@ func (e *DecodingError) String() string {
|
|||
msg += fmt.Sprintf(" at byte %#x", e.off);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ type Error struct {
|
|||
}
|
||||
|
||||
func (e *Error) String() string {
|
||||
return fmt.Sprintf("line %d: %s", e.Line, e.Msg)
|
||||
return fmt.Sprintf("line %d: %s", e.Line, e.Msg);
|
||||
}
|
||||
|
||||
// Most of the literals are aces.
|
||||
|
@ -167,7 +167,7 @@ type state struct {
|
|||
}
|
||||
|
||||
func (parent *state) clone(data reflect.Value) *state {
|
||||
return &state{parent, data, parent.wr, parent.errors}
|
||||
return &state{parent, data, parent.wr, parent.errors};
|
||||
}
|
||||
|
||||
// New creates a new template with the specified formatter map (which
|
||||
|
@ -197,21 +197,21 @@ func (t *Template) parseError(err string, args ...) {
|
|||
|
||||
// Is c a white space character?
|
||||
func white(c uint8) bool {
|
||||
return c == ' ' || c == '\t' || c == '\r' || c == '\n'
|
||||
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
||||
}
|
||||
|
||||
// Safely, does s[n:n+len(t)] == t?
|
||||
func equal(s []byte, n int, t []byte) bool {
|
||||
b := s[n:len(s)];
|
||||
if len(t) > len(b) { // not enough space left for a match.
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
for i, c := range t {
|
||||
if c != b[i] {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
|
||||
// nextItem returns the next item from the input buffer. If the returned
|
||||
|
@ -277,12 +277,12 @@ Loop:
|
|||
if t.buf[i] == '\n' {
|
||||
t.linenum++;
|
||||
i++;
|
||||
break // stop after newline
|
||||
break; // stop after newline
|
||||
}
|
||||
}
|
||||
}
|
||||
t.p = i;
|
||||
return item
|
||||
return item;
|
||||
}
|
||||
|
||||
// Turn a byte array into a white-space-split array of strings.
|
||||
|
@ -299,19 +299,19 @@ func words(buf []byte) []string {
|
|||
for ; p < len(buf) && !white(buf[p]); p++ {
|
||||
}
|
||||
if start == p { // no text left
|
||||
break
|
||||
break;
|
||||
}
|
||||
if i == cap(s) {
|
||||
ns := make([]string, 2*cap(s));
|
||||
for j := range s {
|
||||
ns[j] = s[j]
|
||||
ns[j] = s[j];
|
||||
}
|
||||
s = ns;
|
||||
}
|
||||
s = s[0 : i+1];
|
||||
s[i] = string(buf[start:p])
|
||||
s[i] = string(buf[start:p]);
|
||||
}
|
||||
return s
|
||||
return s;
|
||||
}
|
||||
|
||||
// Analyze an item and return its token type and, if it's an action item, an array of
|
||||
|
@ -333,7 +333,7 @@ func (t *Template) analyze(item []byte) (tok int, w []string) {
|
|||
// Comment
|
||||
if item[len(t.ldelim)] == '#' {
|
||||
tok = tokComment;
|
||||
return
|
||||
return;
|
||||
}
|
||||
// Split into words
|
||||
w = words(item[len(t.ldelim) : len(item)-len(t.rdelim)]); // drop final delimiter
|
||||
|
@ -378,7 +378,7 @@ func (t *Template) analyze(item []byte) (tok int, w []string) {
|
|||
return;
|
||||
}
|
||||
t.parseError("bad directive: %s", item);
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// -- Parsing
|
||||
|
@ -402,15 +402,15 @@ func (t *Template) newVariable(name_formatter string) (v *variableElement) {
|
|||
// Is it in user-supplied map?
|
||||
if t.fmap != nil {
|
||||
if _, ok := t.fmap[formatter]; ok {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Is it in builtin map?
|
||||
if _, ok := builtins[formatter]; ok {
|
||||
return
|
||||
return;
|
||||
}
|
||||
t.parseError("unknown formatter: %s", formatter);
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab the next item. If it's simple, just append it to the template.
|
||||
|
@ -418,7 +418,7 @@ func (t *Template) newVariable(name_formatter string) (v *variableElement) {
|
|||
func (t *Template) parseSimple(item []byte) (done bool, tok int, w []string) {
|
||||
tok, w = t.analyze(item);
|
||||
if t.error != nil {
|
||||
return
|
||||
return;
|
||||
}
|
||||
done = true; // assume for simplicity
|
||||
switch tok {
|
||||
|
@ -446,7 +446,7 @@ func (t *Template) parseSimple(item []byte) (done bool, tok int, w []string) {
|
|||
t.elems.Push(t.newVariable(w[0]));
|
||||
return;
|
||||
}
|
||||
return false, tok, w
|
||||
return false, tok, w;
|
||||
}
|
||||
|
||||
// parseRepeated and parseSection are mutually recursive
|
||||
|
@ -476,7 +476,7 @@ Loop:
|
|||
break;
|
||||
}
|
||||
if done {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
switch tok {
|
||||
case tokEnd:
|
||||
|
@ -508,10 +508,10 @@ Loop:
|
|||
}
|
||||
}
|
||||
if t.error != nil {
|
||||
return nil
|
||||
return nil;
|
||||
}
|
||||
if r.altend < 0 {
|
||||
r.altend = t.elems.Len()
|
||||
r.altend = t.elems.Len();
|
||||
}
|
||||
r.end = t.elems.Len();
|
||||
return r;
|
||||
|
@ -540,7 +540,7 @@ Loop:
|
|||
break;
|
||||
}
|
||||
if done {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
switch tok {
|
||||
case tokEnd:
|
||||
|
@ -562,7 +562,7 @@ Loop:
|
|||
}
|
||||
}
|
||||
if t.error != nil {
|
||||
return nil
|
||||
return nil;
|
||||
}
|
||||
s.end = t.elems.Len();
|
||||
return s;
|
||||
|
@ -572,14 +572,14 @@ func (t *Template) parse() {
|
|||
for t.error == nil {
|
||||
item := t.nextItem();
|
||||
if t.error != nil {
|
||||
break
|
||||
break;
|
||||
}
|
||||
if len(item) == 0 {
|
||||
break
|
||||
break;
|
||||
}
|
||||
done, tok, w := t.parseSimple(item);
|
||||
if done {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
switch tok {
|
||||
case tokOr, tokEnd, tokAlternates:
|
||||
|
@ -604,7 +604,7 @@ func (t *Template) parse() {
|
|||
// it represents the actual named field.
|
||||
func (st *state) findVar(s string) reflect.Value {
|
||||
if s == "@" {
|
||||
return st.data
|
||||
return st.data;
|
||||
}
|
||||
data := st.data;
|
||||
elems := strings.Split(s, ".", 0);
|
||||
|
@ -612,26 +612,26 @@ func (st *state) findVar(s string) reflect.Value {
|
|||
// Look up field; data must be a struct.
|
||||
data = reflect.Indirect(data);
|
||||
if data == nil {
|
||||
return nil
|
||||
return nil;
|
||||
}
|
||||
typ, ok := data.Type().(*reflect.StructType);
|
||||
if !ok {
|
||||
return nil
|
||||
return nil;
|
||||
}
|
||||
field, ok := typ.FieldByName(elems[i]);
|
||||
if !ok {
|
||||
return nil
|
||||
return nil;
|
||||
}
|
||||
data = data.(*reflect.StructValue).FieldByIndex(field.Index);
|
||||
}
|
||||
return data
|
||||
return data;
|
||||
}
|
||||
|
||||
// Is there no data to look at?
|
||||
func empty(v reflect.Value) bool {
|
||||
v = reflect.Indirect(v);
|
||||
if v == nil {
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
switch v := v.(type) {
|
||||
case *reflect.BoolValue:
|
||||
|
@ -653,7 +653,7 @@ func (t *Template) varValue(name string, st *state) reflect.Value {
|
|||
field := st.findVar(name);
|
||||
if field == nil {
|
||||
if st.parent == nil {
|
||||
t.execError(st, t.linenum, "name not found: %s", name)
|
||||
t.execError(st, t.linenum, "name not found: %s", name);
|
||||
}
|
||||
return t.varValue(name, st.parent);
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ func (t *Template) writeVariable(v *variableElement, st *state) {
|
|||
fn(st.wr, val, formatter);
|
||||
return;
|
||||
}
|
||||
t.execError(st, v.linenum, "missing formatter %s for variable %s", formatter, v.name)
|
||||
t.execError(st, v.linenum, "missing formatter %s for variable %s", formatter, v.name);
|
||||
}
|
||||
|
||||
// Execute element i. Return next index to execute.
|
||||
|
@ -701,13 +701,13 @@ func (t *Template) executeElement(i int, st *state) int {
|
|||
}
|
||||
e := t.elems.At(i);
|
||||
t.execError(st, 0, "internal error: bad directive in execute: %v %T\n", reflect.NewValue(e).Interface(), e);
|
||||
return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Execute the template.
|
||||
func (t *Template) execute(start, end int, st *state) {
|
||||
for i := start; i < end; {
|
||||
i = t.executeElement(i, st)
|
||||
i = t.executeElement(i, st);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -723,17 +723,17 @@ func (t *Template) executeSection(s *sectionElement, st *state) {
|
|||
if !empty(field) {
|
||||
// Execute the normal block.
|
||||
if end < 0 {
|
||||
end = s.end
|
||||
end = s.end;
|
||||
}
|
||||
} else {
|
||||
// Execute the .or block. If it's missing, do nothing.
|
||||
start, end = s.or, s.end;
|
||||
if start < 0 {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
for i := start; i < end; {
|
||||
i = t.executeElement(i, st)
|
||||
i = t.executeElement(i, st);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -745,15 +745,15 @@ func iter(v reflect.Value) *reflect.ChanValue {
|
|||
ft := fv.Type().(*reflect.FuncType);
|
||||
// TODO(rsc): NumIn() should return 0 here, because ft is from a curried FuncValue.
|
||||
if mth.Name != "Iter" || ft.NumIn() != 1 || ft.NumOut() != 1 {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
ct, ok := ft.Out(0).(*reflect.ChanType);
|
||||
if !ok || ct.Dir() & reflect.RecvDir == 0 {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
return fv.Call(nil)[0].(*reflect.ChanValue)
|
||||
return fv.Call(nil)[0].(*reflect.ChanValue);
|
||||
}
|
||||
return nil
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Execute a .repeated section
|
||||
|
@ -766,10 +766,10 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
|
|||
|
||||
start, end := r.start, r.or;
|
||||
if end < 0 {
|
||||
end = r.end
|
||||
end = r.end;
|
||||
}
|
||||
if r.altstart >= 0 {
|
||||
end = r.altstart
|
||||
end = r.altstart;
|
||||
}
|
||||
first := true;
|
||||
|
||||
|
@ -780,33 +780,33 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
|
|||
// .alternates between elements
|
||||
if !first && r.altstart >= 0 {
|
||||
for i := r.altstart; i < r.altend; {
|
||||
i = t.executeElement(i, newst)
|
||||
i = t.executeElement(i, newst);
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
|
||||
for i := start; i < end; {
|
||||
i = t.executeElement(i, newst)
|
||||
i = t.executeElement(i, newst);
|
||||
}
|
||||
}
|
||||
} else if ch := iter(field); ch != nil {
|
||||
for {
|
||||
e := ch.Recv();
|
||||
if ch.Closed() {
|
||||
break
|
||||
break;
|
||||
}
|
||||
newst := st.clone(e);
|
||||
|
||||
// .alternates between elements
|
||||
if !first && r.altstart >= 0 {
|
||||
for i := r.altstart; i < r.altend; {
|
||||
i = t.executeElement(i, newst)
|
||||
i = t.executeElement(i, newst);
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
|
||||
for i := start; i < end; {
|
||||
i = t.executeElement(i, newst)
|
||||
i = t.executeElement(i, newst);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -820,21 +820,21 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
|
|||
if start >= 0 {
|
||||
newst := st.clone(field);
|
||||
for i := start; i < end; {
|
||||
i = t.executeElement(i, newst)
|
||||
i = t.executeElement(i, newst);
|
||||
}
|
||||
}
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// A valid delimiter must contain no white space and be non-empty.
|
||||
func validDelim(d []byte) bool {
|
||||
if len(d) == 0 {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
for _, c := range d {
|
||||
if white(c) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -847,7 +847,7 @@ func validDelim(d []byte) bool {
|
|||
// the error.
|
||||
func (t *Template) Parse(s string) os.Error {
|
||||
if !validDelim(t.ldelim) || !validDelim(t.rdelim) {
|
||||
return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)}
|
||||
return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)};
|
||||
}
|
||||
t.buf = strings.Bytes(s);
|
||||
t.p = 0;
|
||||
|
@ -889,9 +889,9 @@ func Parse(s string, fmap FormatterMap) (t *Template, err os.Error) {
|
|||
t = New(fmap);
|
||||
err = t.Parse(s);
|
||||
if err != nil {
|
||||
t = nil
|
||||
t = nil;
|
||||
}
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// MustParse is like Parse but panics if the template cannot be parsed.
|
||||
|
@ -900,5 +900,5 @@ func MustParse(s string, fmap FormatterMap) *Template {
|
|||
if err != nil {
|
||||
panic("template parse error: ", err.String());
|
||||
}
|
||||
return t
|
||||
return t;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче