internal bool IsPropertyField(IPropertySymbol symbol) { bool isAutoField; if (!isFieldPropertys_.TryGetValue(symbol, out isAutoField)) { bool?isMateField = XmlMetaProvider.IsPropertyField(symbol); if (isMateField.HasValue) { isAutoField = isMateField.Value; } else { if (IsImplicitInterfaceImplementation(symbol)) { isAutoField = false; } else { isAutoField = symbol.IsPropertyField(); } } isFieldPropertys_.Add(symbol, isAutoField); } return(isAutoField); }
public LuaSyntaxGenerator(IEnumerable <SyntaxTree> syntaxTrees, IEnumerable <MetadataReference> references, CSharpCompilationOptions options, IEnumerable <string> metas, SettingInfo setting, string[] attributes) { CSharpCompilation compilation = CSharpCompilation.Create("_", syntaxTrees, references, options.WithOutputKind(OutputKind.DynamicallyLinkedLibrary)); using (MemoryStream ms = new MemoryStream()) { EmitResult result = compilation.Emit(ms); if (!result.Success) { var errors = result.Diagnostics.Where(i => i.Severity == DiagnosticSeverity.Error); string message = string.Join("\n", errors); throw new CompilationErrorException(message); } } compilation_ = compilation; XmlMetaProvider = new XmlMetaProvider(metas); Setting = setting; if (attributes != null) { if (attributes.Length == 0) { isExportAttributesAll_ = true; } else { exportAttributes_ = new HashSet <string>(attributes); } } DoPretreatment(); }
private void ExportManifestFile(List <string> modules, string outFolder) { const string kDir = "dir"; const string kDirInitCode = "dir = (dir and #dir > 0) and (dir .. '.') or \"\""; const string kRequire = "require"; const string kLoadCode = "local load = function(module) return require(dir .. module) end"; const string kLoad = "load"; const string kInit = "System.init"; const string kManifestFile = "manifest.lua"; if (modules.Count > 0) { modules.Sort(); var types = GetExportTypes(); if (types.Count > 0) { LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax(); functionExpression.AddParameter(new LuaIdentifierNameSyntax(kDir)); functionExpression.AddStatement(new LuaIdentifierNameSyntax(kDirInitCode)); LuaIdentifierNameSyntax requireIdentifier = new LuaIdentifierNameSyntax(kRequire); functionExpression.AddStatement(new LuaLocalVariableDeclaratorSyntax(requireIdentifier, requireIdentifier)); functionExpression.AddStatement(new LuaIdentifierNameSyntax(kLoadCode)); functionExpression.AddStatement(LuaBlankLinesStatement.One); LuaIdentifierNameSyntax loadIdentifier = new LuaIdentifierNameSyntax(kLoad); foreach (string module in modules) { var argument = new LuaStringLiteralExpressionSyntax(new LuaIdentifierNameSyntax(module)); var invocation = new LuaInvocationExpressionSyntax(loadIdentifier, argument); functionExpression.AddStatement(invocation); } functionExpression.AddStatement(LuaBlankLinesStatement.One); LuaTableInitializerExpression typeTable = new LuaTableInitializerExpression(); foreach (var type in types) { LuaIdentifierNameSyntax typeName = XmlMetaProvider.GetTypeShortName(type); typeTable.Items.Add(new LuaSingleTableItemSyntax(new LuaStringLiteralExpressionSyntax(typeName))); } LuaInvocationExpressionSyntax initInvocation = new LuaInvocationExpressionSyntax(new LuaIdentifierNameSyntax(kInit), typeTable); FillManifestInitConf(initInvocation); functionExpression.AddStatement(initInvocation); LuaCompilationUnitSyntax luaCompilationUnit = new LuaCompilationUnitSyntax(); luaCompilationUnit.Statements.Add(new LuaReturnStatementSyntax(functionExpression)); string outFile = Path.Combine(outFolder, kManifestFile); Write(luaCompilationUnit, outFile); } } }
private string GetSymbolBaseName(ISymbol symbol) { switch (symbol.Kind) { case SymbolKind.Method: { IMethodSymbol method = (IMethodSymbol)symbol; string name = XmlMetaProvider.GetMethodMapName(method); if (name != null) { return(name); } var implementation = method.ExplicitInterfaceImplementations.FirstOrDefault(); if (implementation != null) { return(implementation.Name); } break; } case SymbolKind.Property: { IPropertySymbol property = (IPropertySymbol)symbol; if (property.IsIndexer) { return(string.Empty); } else { var implementation = property.ExplicitInterfaceImplementations.FirstOrDefault(); if (implementation != null) { return(implementation.Name); } } break; } case SymbolKind.Event: { IEventSymbol eventSymbol = (IEventSymbol)symbol; var implementation = eventSymbol.ExplicitInterfaceImplementations.FirstOrDefault(); if (implementation != null) { return(implementation.Name); } break; } } return(symbol.Name); }
public override LuaSyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) { var symbol = (IMethodSymbol)semanticModel_.GetSymbolInfo(node).Symbol; LuaExpressionSyntax creationExpression; if (symbol != null) { string codeTemplate = XmlMetaProvider.GetMethodCodeTemplate(symbol); if (codeTemplate != null) { creationExpression = BuildCodeTemplateExpression(codeTemplate, null, node.ArgumentList.Arguments.Select(i => i.Expression), symbol.TypeArguments); } else { var expression = (LuaExpressionSyntax)node.Type.Accept(this); var invokeExpression = BuildObjectCreationInvocation(symbol, expression); var arguments = BuildArgumentList(symbol, symbol.Parameters, node.ArgumentList); TryRemoveNilArgumentsAtTail(symbol, arguments); invokeExpression.AddArguments(arguments); creationExpression = invokeExpression; } } else { Contract.Assert(!node.ArgumentList.Arguments.Any()); var expression = (LuaExpressionSyntax)node.Type.Accept(this); var invokeExpression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.SystemNew, expression); creationExpression = invokeExpression; } if (node.Initializer == null) { return(creationExpression); } else { var functionExpression = BuildObjectInitializerExpression(node.Initializer); return(new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.Create, creationExpression, functionExpression)); } }
private void FillManifestInitConf(LuaInvocationExpressionSyntax invocation) { LuaTableInitializerExpression confTable = new LuaTableInitializerExpression(); if (mainEntryPoint_ != null) { LuaIdentifierNameSyntax methodName = new LuaIdentifierNameSyntax(mainEntryPoint_.Name); var methodTypeName = XmlMetaProvider.GetTypeName(mainEntryPoint_.ContainingType, null); var quote = new LuaIdentifierNameSyntax(LuaSyntaxNode.Tokens.Quote); LuaCodeTemplateExpressionSyntax codeTemplate = new LuaCodeTemplateExpressionSyntax(); codeTemplate.Expressions.Add(quote); codeTemplate.Expressions.Add(new LuaMemberAccessExpressionSyntax(methodTypeName, methodName)); codeTemplate.Expressions.Add(quote); confTable.Items.Add(new LuaKeyValueTableItemSyntax(new LuaTableLiteralKeySyntax(methodName), codeTemplate)); } if (confTable.Items.Count > 0) { invocation.AddArgument(confTable); } }
internal bool IsExportAttribute(INamedTypeSymbol attributeTypeSymbol) { if (isExportAttributesAll_) { return(true); } else { if (exportAttributes_ != null && exportAttributes_.Count > 0) { if (exportAttributes_.Contains(attributeTypeSymbol.ToString())) { return(true); } } if (XmlMetaProvider.IsExportAttribute(attributeTypeSymbol)) { return(true); } } return(false); }
private LuaIdentifierNameSyntax InternalGetMemberName(ISymbol symbol) { if (symbol.Kind == SymbolKind.Method) { string name = XmlMetaProvider.GetMethodMapName((IMethodSymbol)symbol); if (name != null) { return(new LuaIdentifierNameSyntax(name)); } } if (!symbol.IsFromCode() || symbol.ContainingType.TypeKind == TypeKind.Interface) { return(new LuaIdentifierNameSyntax(GetSymbolBaseName(symbol))); } if (symbol.IsStatic) { if (symbol.ContainingType.IsStatic) { return(GetStaticClassMemberName(symbol)); } } while (symbol.IsOverride) { var overriddenSymbol = symbol.OverriddenSymbol(); if (!overriddenSymbol.IsFromCode()) { break; } symbol = overriddenSymbol; } return(GetAllTypeSameName(symbol)); }
private LuaExpressionSyntax GetTypeName(ISymbol symbol) { return(XmlMetaProvider.GetTypeName(symbol, this)); }
private LuaIdentifierNameSyntax GetTypeShortName(ISymbol symbol) { return(XmlMetaProvider.GetTypeShortName(symbol, this)); }