本文整理汇总了C#中ScriptSharp.Generator.ScriptGenerator类的典型用法代码示例。如果您正苦于以下问题:C# ScriptGenerator类的具体用法?C# ScriptGenerator怎么用?C# ScriptGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScriptGenerator类属于ScriptSharp.Generator命名空间,在下文中一共展示了ScriptGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateClassConstructorScript
public static void GenerateClassConstructorScript(ScriptGenerator generator, ClassSymbol classSymbol)
{
// NOTE: This is emitted last in the script file, and separate from the initial class definition
// because it needs to be emitted after the class registration.
foreach (MemberSymbol memberSymbol in classSymbol.Members) {
if ((memberSymbol.Type == SymbolType.Field) &&
((memberSymbol.Visibility & MemberVisibility.Static) != 0)) {
if (((FieldSymbol)memberSymbol).IsConstant &&
((memberSymbol.Visibility & (MemberVisibility.Public | MemberVisibility.Protected)) == 0)) {
// PrivateInstance/Internal constant fields are omitted since they have been inlined
continue;
}
MemberGenerator.GenerateScript(generator, memberSymbol);
}
}
if (classSymbol.StaticConstructor != null) {
ScriptTextWriter writer = generator.Writer;
writer.Write("(function");
writer.WriteTrimmed(" () ");
writer.Write("{");
writer.WriteNewLine();
writer.Indent++;
CodeGenerator.GenerateScript(generator, classSymbol.StaticConstructor);
writer.Indent--;
writer.Write("})();");
writer.WriteSignificantNewLine();
}
}
示例2: GenerateComment
public static void GenerateComment(ScriptGenerator generator, Symbol symbol) {
ScriptTextWriter writer = generator.Writer;
switch (symbol.Type) {
case SymbolType.Class:
GenerateClassComment(writer, (ClassSymbol)symbol);
break;
case SymbolType.Enumeration:
GenerateEnumerationComment(writer, (EnumerationSymbol)symbol);
break;
case SymbolType.Event:
GenerateEventComment(writer, (EventSymbol)symbol);
break;
case SymbolType.Indexer:
GenerateIndexerComment(writer, (IndexerSymbol)symbol);
break;
case SymbolType.Interface:
GenerateInterfaceComment(writer, (InterfaceSymbol)symbol);
break;
case SymbolType.Method:
GenerateMethodComment(writer, (MethodSymbol)symbol);
break;
case SymbolType.Property:
GeneratePropertyComment(writer, (PropertySymbol)symbol);
break;
default:
Debug.Fail("Unexpected symbol type");
break;
}
}
示例3: GenerateForStatement
private static void GenerateForStatement(ScriptGenerator generator, MemberSymbol symbol, ForStatement statement) {
if (statement.Body == null) {
return;
}
ScriptTextWriter writer = generator.Writer;
writer.WriteTrimmed("for ");
writer.Write("(");
if (statement.Initializers != null) {
ExpressionGenerator.GenerateExpressionList(generator, symbol, statement.Initializers);
}
else if (statement.Variables != null) {
GenerateVariableDeclarations(generator, symbol, statement.Variables);
}
writer.WriteTrimmed("; ");
if (statement.Condition != null) {
ExpressionGenerator.GenerateExpression(generator, symbol, statement.Condition);
}
writer.WriteTrimmed("; ");
if (statement.Increments != null) {
ExpressionGenerator.GenerateExpressionList(generator, symbol, statement.Increments);
}
writer.WriteTrimmed(") ");
writer.Write("{");
writer.WriteNewLine();
writer.Indent++;
GenerateStatement(generator, symbol, statement.Body);
writer.Indent--;
writer.Write("}");
writer.WriteNewLine();
}
示例4: GenerateScript
public static void GenerateScript(ScriptGenerator generator, MemberSymbol memberSymbol)
{
Debug.Assert(memberSymbol.Parent is TypeSymbol);
TypeSymbol typeSymbol = (TypeSymbol)memberSymbol.Parent;
string typeName = typeSymbol.FullGeneratedName;
switch (memberSymbol.Type) {
case SymbolType.Field:
GenerateField(generator, typeName, (FieldSymbol)memberSymbol);
break;
case SymbolType.Indexer:
GenerateIndexer(generator, typeName, (IndexerSymbol)memberSymbol);
break;
case SymbolType.Property:
GenerateProperty(generator, typeName, (PropertySymbol)memberSymbol);
break;
case SymbolType.Method:
GenerateMethod(generator, typeName, (MethodSymbol)memberSymbol);
break;
case SymbolType.Event:
GenerateEvent(generator, typeName, (EventSymbol)memberSymbol);
break;
}
}
示例5: GenerateBlockStatement
private static void GenerateBlockStatement(ScriptGenerator generator, MemberSymbol symbol, BlockStatement statement) {
ScriptTextWriter writer = generator.Writer;
foreach (Statement s in statement.Statements) {
GenerateStatement(generator, symbol, s);
}
}
示例6: GenerateExpressionStatement
private static void GenerateExpressionStatement(ScriptGenerator generator, MemberSymbol symbol, ExpressionStatement statement) {
ScriptTextWriter writer = generator.Writer;
ExpressionGenerator.GenerateExpression(generator, symbol, statement.Expression);
if (statement.IsFragment == false) {
writer.Write(";");
writer.WriteNewLine();
}
}
示例7: GenerateErrorStatement
private static void GenerateErrorStatement(ScriptGenerator generator, MemberSymbol symbol, ErrorStatement statement) {
ScriptTextWriter writer = generator.Writer;
writer.Write("// ERROR: ");
writer.Write(statement.Message);
writer.WriteSignificantNewLine();
writer.Write("// ERROR: at ");
writer.Write(statement.Location);
writer.WriteSignificantNewLine();
}
示例8: GenerateScript
public static void GenerateScript(ScriptGenerator generator, IndexerSymbol symbol, bool getter) {
SymbolImplementation accessorImpl;
if (getter) {
accessorImpl = symbol.GetterImplementation;
}
else {
accessorImpl = symbol.SetterImplementation;
}
GenerateImplementationScript(generator, symbol, accessorImpl);
}
示例9: GenerateRegistrationScript
public static void GenerateRegistrationScript(ScriptGenerator generator, TypeSymbol typeSymbol)
{
ClassSymbol classSymbol = typeSymbol as ClassSymbol;
if ((classSymbol != null) && classSymbol.IsExtenderClass) {
return;
}
ScriptTextWriter writer = generator.Writer;
writer.Write(typeSymbol.GeneratedName);
writer.Write(": ");
switch (typeSymbol.Type) {
case SymbolType.Class:
writer.Write("[ ");
writer.Write(typeSymbol.FullGeneratedName);
writer.Write(", ");
if (((ClassSymbol)typeSymbol).IsStaticClass == false) {
writer.Write(typeSymbol.FullGeneratedName);
writer.Write("$, ");
}
else {
writer.Write("null, ");
}
if ((classSymbol.BaseClass == null) || classSymbol.IsTestClass) {
// TODO: We need to introduce the notion of a base class that only exists in the metadata
// and not at runtime. At that point this check of IsTestClass can be generalized.
writer.Write("null");
}
else {
writer.Write(classSymbol.BaseClass.FullGeneratedName);
}
if (classSymbol.Interfaces != null) {
foreach (InterfaceSymbol interfaceSymbol in classSymbol.Interfaces) {
writer.Write(", ");
writer.Write(interfaceSymbol.FullGeneratedName);
}
}
writer.Write(" ]");
break;
case SymbolType.Interface:
writer.Write("[ ");
writer.Write(typeSymbol.FullGeneratedName);
writer.Write(" ]");
break;
case SymbolType.Record:
case SymbolType.Resources:
case SymbolType.Enumeration:
writer.Write(typeSymbol.FullGeneratedName);
break;
}
}
示例10: GenerateStatement
public static void GenerateStatement(ScriptGenerator generator, MemberSymbol symbol, Statement statement)
{
switch (statement.Type) {
case StatementType.Block:
GenerateBlockStatement(generator, symbol, (BlockStatement)statement);
break;
case StatementType.Empty:
break;
case StatementType.VariableDeclaration:
GenerateVariableDeclarationStatement(generator, symbol, (VariableDeclarationStatement)statement);
break;
case StatementType.Return:
GenerateReturnStatement(generator, symbol, (ReturnStatement)statement);
break;
case StatementType.Expression:
GenerateExpressionStatement(generator, symbol, (ExpressionStatement)statement);
break;
case StatementType.IfElse:
GenerateIfElseStatement(generator, symbol, (IfElseStatement)statement);
break;
case StatementType.While:
GenerateWhileStatement(generator, symbol, (WhileStatement)statement);
break;
case StatementType.For:
GenerateForStatement(generator, symbol, (ForStatement)statement);
break;
case StatementType.ForIn:
GenerateForInStatement(generator, symbol, (ForInStatement)statement);
break;
case StatementType.Switch:
GenerateSwitchStatement(generator, symbol, (SwitchStatement)statement);
break;
case StatementType.Break:
GenerateBreakStatement(generator, symbol, (BreakStatement)statement);
break;
case StatementType.Continue:
GenerateContinueStatement(generator, symbol, (ContinueStatement)statement);
break;
case StatementType.Throw:
GenerateThrowStatement(generator, symbol, (ThrowStatement)statement);
break;
case StatementType.TryCatchFinally:
GenerateTryCatchFinallyStatement(generator, symbol, (TryCatchFinallyStatement)statement);
break;
case StatementType.Error:
GenerateErrorStatement(generator, symbol, (ErrorStatement)statement);
break;
default:
Debug.Fail("Unexpected statement type: " + statement.Type);
break;
}
}
示例11: GenerateBaseInitializerExpression
private static void GenerateBaseInitializerExpression(ScriptGenerator generator, MemberSymbol symbol, BaseInitializerExpression expression) {
ScriptTextWriter writer = generator.Writer;
Debug.Assert(symbol.Parent is ClassSymbol);
writer.Write(((ClassSymbol)symbol.Parent).FullGeneratedName);
writer.Write(".initializeBase(this");
if (expression.Parameters != null) {
writer.Write(",");
writer.WriteTrimmed(" [ ");
GenerateExpressionList(generator, symbol, expression.Parameters);
writer.WriteTrimmed(" ]");
}
writer.Write(")");
}
示例12: GenerateScript
public static void GenerateScript(ScriptGenerator generator, NamespaceSymbol namespaceSymbol, Dictionary<string,bool> generatedNamespaces)
{
Debug.Assert(generator != null);
Debug.Assert(namespaceSymbol != null);
Debug.Assert(namespaceSymbol.HasApplicationTypes);
ScriptTextWriter writer = generator.Writer;
// First generate enums and interfaces which do not have cross-dependencies
// (Classes for example, might have dependencies on enums)
foreach (TypeSymbol type in namespaceSymbol.Types) {
if (type.IsApplicationType) {
if (type.IsTestType && (generator.Options.IncludeTests == false)) {
continue;
}
string namespaceName = type.GeneratedNamespace;
if ((namespaceName.Length != 0) &&
(generatedNamespaces.ContainsKey(namespaceName) == false)) {
writer.Write("Type.registerNamespace('");
writer.Write(namespaceName);
writer.Write("');");
writer.WriteNewLine();
writer.WriteNewLine();
generatedNamespaces[namespaceName] = true;
}
}
if (type.IsApplicationType &&
((type.Type == SymbolType.Enumeration) ||
(type.Type == SymbolType.Interface) ||
(type.Type == SymbolType.Record) ||
(type.Type == SymbolType.Resources))) {
TypeGenerator.GenerateScript(generator, type);
}
}
foreach (TypeSymbol type in namespaceSymbol.Types) {
if (type.IsApplicationType && (type.Type == SymbolType.Class)) {
if (type.IsTestType && (generator.Options.IncludeTests == false)) {
continue;
}
TypeGenerator.GenerateScript(generator, type);
}
}
}
示例13: GenerateClassRegistrationScript
public static void GenerateClassRegistrationScript(ScriptGenerator generator, ClassSymbol classSymbol)
{
// NOTE: This is emitted towards the end of the script file as opposed to immediately after the
// class definition, because it allows us to reference other class (base class, interfaces)
// without having to do a manual topological sort to get the ordering of class definitions
// that would be needed otherwise.
ScriptTextWriter writer = generator.Writer;
string name = classSymbol.FullGeneratedName;
writer.Write(name);
writer.Write(".registerClass('");
writer.Write(generator.Options.AssemblyName);
writer.Write("', '");
writer.Write(name);
writer.Write("'");
// TODO: We need to introduce the notion of a base class that only exists in the metadata
// and not at runtime. At that point this check of IsTestClass can be generalized.
if (classSymbol.IsTestClass) {
writer.Write(");");
writer.WriteNewLine();
return;
}
if (classSymbol.BaseClass != null) {
writer.WriteTrimmed(", ");
writer.Write(classSymbol.BaseClass.FullGeneratedName);
}
if (classSymbol.Interfaces != null) {
if (classSymbol.BaseClass == null) {
writer.WriteTrimmed(", ");
writer.Write("null");
}
foreach (InterfaceSymbol interfaceSymbol in classSymbol.Interfaces) {
writer.WriteTrimmed(", ");
writer.Write(interfaceSymbol.FullGeneratedName);
}
}
writer.Write(");");
writer.WriteNewLine();
}
示例14: GenerateClassConstructorScript
public static void GenerateClassConstructorScript(ScriptGenerator generator, ClassSymbol classSymbol)
{
// NOTE: This is emitted last in the script file, and separate from the initial class definition
// because it needs to be emitted after the class registration.
foreach (MemberSymbol memberSymbol in classSymbol.Members) {
if ((memberSymbol.Type == SymbolType.Field) &&
((memberSymbol.Visibility & MemberVisibility.Static) != 0)) {
FieldSymbol fieldSymbol = (FieldSymbol)memberSymbol;
if (fieldSymbol.IsConstant &&
((memberSymbol.Visibility & (MemberVisibility.Public | MemberVisibility.Protected)) == 0)) {
// PrivateInstance/Internal constant fields are omitted since they have been inlined
continue;
}
if (fieldSymbol.HasInitializer) {
MemberGenerator.GenerateScript(generator, memberSymbol);
}
}
}
if (classSymbol.StaticConstructor != null) {
ScriptTextWriter writer = generator.Writer;
SymbolImplementation implementation = classSymbol.StaticConstructor.Implementation;
bool requiresFunctionScope = implementation.DeclaresVariables;
if (requiresFunctionScope) {
writer.WriteLine("(function() {");
writer.Indent++;
}
CodeGenerator.GenerateScript(generator, classSymbol.StaticConstructor);
if (requiresFunctionScope) {
writer.Indent--;
writer.Write("})();");
writer.WriteLine();
}
}
}
示例15: GenerateMethodExpression
private static void GenerateMethodExpression(ScriptGenerator generator, MemberSymbol symbol, MethodExpression expression)
{
ScriptTextWriter writer = generator.Writer;
if (expression.Method.SkipGeneration) {
// If this method is to be skipped from generation, just generate the
// left-hand-side object reference, and skip everything past it, including
// the dot.
GenerateExpression(generator, symbol, expression.ObjectReference);
return;
}
if (expression.ObjectReference is BaseExpression) {
Debug.Assert(symbol.Parent is ClassSymbol);
Debug.Assert(expression.Method.IsGlobalMethod == false);
writer.Write(((ClassSymbol)symbol.Parent).FullGeneratedName);
writer.Write(".callBaseMethod(this, '");
writer.Write(expression.Method.GeneratedName);
writer.Write("'");
if ((expression.Parameters != null) && (expression.Parameters.Count != 0)) {
writer.Write(",");
writer.WriteTrimmed(" [ ");
GenerateExpressionList(generator, symbol, expression.Parameters);
writer.WriteTrimmed(" ]");
}
writer.Write(")");
}
else {
if (expression.Method.IsGlobalMethod) {
if (expression.Method.Parent is ClassSymbol) {
string mixinRoot = ((ClassSymbol)expression.Method.Parent).MixinRoot;
if (String.IsNullOrEmpty(mixinRoot) == false) {
writer.Write(mixinRoot);
writer.Write(".");
}
}
}
else {
GenerateExpression(generator, symbol, expression.ObjectReference);
if (expression.Method.GeneratedName.Length != 0) {
writer.Write(".");
}
}
if (expression.Method.GeneratedName.Length != 0) {
writer.Write(expression.Method.GeneratedName);
}
writer.Write("(");
if (expression.Parameters != null) {
GenerateExpressionList(generator, symbol, expression.Parameters);
}
writer.Write(")");
}
}