예제 #1
0
// computeMemberSignature computes a type signature for the given type member.
// Note that the signature format (except for type references) is internal to
// this method and can be changed at any time.
func computeMemberSignature(member typegraph.TGMember) memberSignature {
	kind := member.Signature().MemberKind

	// Signature form: "MemberName|MemberTypeInt|MemberTypeReference"
	var buf bytes.Buffer
	buf.WriteRune('"')
	buf.WriteString(member.Name())
	buf.WriteRune('|')
	buf.WriteString(strconv.Itoa(int(*kind)))
	buf.WriteRune('|')

	dynamic := appendSigReference(member.MemberType(), &buf)

	buf.WriteRune('"')
	return memberSignature{buf.String(), dynamic}
}
예제 #2
0
// GetStaticMemberPath returns the global path for the given statically defined type member.
func (p Pather) GetStaticMemberPath(member typegraph.TGMember, referenceType typegraph.TypeReference) string {
	// TODO(jschorr): We should generalize non-SRG support.
	if member.Name() == "new" && !member.IsPromising() {
		parentType, _ := member.ParentType()
		if strings.HasSuffix(parentType.ParentModule().Path(), ".webidl") {
			return "$t.nativenew(" + p.GetTypePath(parentType) + ")"
		}
	}

	name := p.GetMemberName(member)
	parent := member.Parent()
	if parent.IsType() {
		return p.GetStaticTypePath(parent.(typegraph.TGTypeDecl), referenceType) + "." + name
	} else {
		return p.GetModulePath(parent.(typegraph.TGModule)) + "." + name
	}
}
예제 #3
0
// generateVariable generates the given variable into ES5.
func (gen *es5generator) generateVariable(member typegraph.TGMember) generatedSourceResult {
	srgMember, _ := gen.getSRGMember(member)
	initializer, _ := srgMember.Initializer()
	initResult := statemachine.GenerateExpressionResult(initializer, gen.scopegraph, gen.positionMapper)

	prefix := "instance"
	if member.IsStatic() {
		prefix = "$static"
	}

	data := struct {
		Name        string
		Prefix      string
		Initializer expressiongenerator.ExpressionResult
	}{member.Name(), prefix, initResult}

	source := esbuilder.Template("variable", variableTemplateStr, data)
	return generatedSourceResult{source, initResult.IsPromise()}
}