public override void VisitIdentifierName(IdentifierNameSyntax node) { string name = node.Identifier.Text; if (m_ClassInfoStack.Count > 0) { ClassInfo classInfo = m_ClassInfoStack.Peek(); SymbolInfo symbolInfo = m_Model.GetSymbolInfoEx(node); var sym = symbolInfo.Symbol; if (null != sym) { bool isExtern = !SymbolTable.Instance.IsCs2DslSymbol(sym); if (sym.Kind == SymbolKind.NamedType || sym.Kind == SymbolKind.Namespace) { string fullName = ClassInfo.GetFullName(sym); CodeBuilder.Append(fullName); if (sym.Kind == SymbolKind.NamedType) { var namedType = sym as INamedTypeSymbol; AddReferenceAndTryDeriveGenericTypeInstance(classInfo, namedType); } return; } else if (sym.Kind == SymbolKind.Field || sym.Kind == SymbolKind.Property || sym.Kind == SymbolKind.Event) { var fsym = sym as IFieldSymbol; var psym = sym as IPropertySymbol; string fullName = ClassInfo.GetFullName(sym.ContainingType); if (sym.IsStatic) { if (isExtern && null != fsym && fsym.Type.IsValueType && !SymbolTable.IsBasicType(fsym.Type)) { MarkNeedFuncInfo(); CodeBuilder.AppendFormat("getexternstaticstructmember(SymbolKind.{0}, {1}, \"{2}\")", SymbolTable.Instance.GetSymbolKind(sym), fullName, sym.Name); } else if (isExtern && null != psym && psym.Type.IsValueType && !SymbolTable.IsBasicType(psym.Type)) { MarkNeedFuncInfo(); CodeBuilder.AppendFormat("getexternstaticstructmember(SymbolKind.{0}, {1}, \"{2}\")", SymbolTable.Instance.GetSymbolKind(sym), fullName, sym.Name); } else { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, {2}, \"{3}\")", isExtern ? "getexternstatic" : "getstatic", SymbolTable.Instance.GetSymbolKind(sym), fullName, sym.Name); } return; } else if (IsNewObjMember(name)) { if (isExtern && null != fsym && fsym.Type.IsValueType && !SymbolTable.IsBasicType(fsym.Type)) { MarkNeedFuncInfo(); CodeBuilder.AppendFormat("getexterninstancestructmember(SymbolKind.{0}, newobj, {1}, \"{2}\")", SymbolTable.Instance.GetSymbolKind(sym), fullName, name); } else if (isExtern && null != psym && psym.Type.IsValueType && !SymbolTable.IsBasicType(psym.Type)) { MarkNeedFuncInfo(); CodeBuilder.AppendFormat("getexterninstancestructmember(SymbolKind.{0}, newobj, {1}, \"{2}\")", SymbolTable.Instance.GetSymbolKind(sym), fullName, name); } else { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, newobj, {2}, \"{3}\")", isExtern ? "getexterninstance" : "getinstance", SymbolTable.Instance.GetSymbolKind(sym), fullName, name); } return; } else if (sym.ContainingType == classInfo.SemanticInfo || sym.ContainingType == classInfo.SemanticInfo.OriginalDefinition || classInfo.IsInherit(sym.ContainingType)) { if (isExtern && null != fsym && fsym.Type.IsValueType && !SymbolTable.IsBasicType(fsym.Type)) { MarkNeedFuncInfo(); CodeBuilder.AppendFormat("getexterninstancestructmember(SymbolKind.{0}, this, {1}, \"{2}\")", SymbolTable.Instance.GetSymbolKind(sym), fullName, sym.Name); } else if (isExtern && null != psym && psym.Type.IsValueType && !SymbolTable.IsBasicType(psym.Type)) { MarkNeedFuncInfo(); CodeBuilder.AppendFormat("getexterninstancestructmember(SymbolKind.{0}, this, {1}, \"{2}\")", SymbolTable.Instance.GetSymbolKind(sym), fullName, sym.Name); } else { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, this, {2}, \"{3}\")", isExtern ? "getexterninstance" : "getinstance", SymbolTable.Instance.GetSymbolKind(sym), fullName, sym.Name); } return; } } else if (sym.Kind == SymbolKind.Method) { var msym = sym as IMethodSymbol; string manglingName = NameMangling(msym); var mi = new MethodInfo(); mi.Init(msym, node); string fullName = ClassInfo.GetFullName(sym.ContainingType); if (sym.IsStatic && node.Parent is InvocationExpressionSyntax) { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, {2}, \"{3}\")", isExtern ? "getexternstatic" : "getstatic", SymbolTable.Instance.GetSymbolKind(sym), fullName, manglingName); return; } else if (sym.ContainingType == classInfo.SemanticInfo || sym.ContainingType == classInfo.SemanticInfo.OriginalDefinition || classInfo.IsInherit(sym.ContainingType)) { if (node.Parent is InvocationExpressionSyntax) { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, this, {2}, \"{3}\")", isExtern ? "getexterninstance" : "getinstance", SymbolTable.Instance.GetSymbolKind(sym), fullName, manglingName); } else { string srcPos = GetSourcePosForVar(node); string delegationKey = string.Format("{0}:{1}", fullName, manglingName); if (msym.IsStatic) { CodeBuilder.AppendFormat("builddelegation(\"{0}\", \"{1}\", {2}, {3}, {4})", srcPos, delegationKey, fullName, manglingName, "true"); } else { CodeBuilder.AppendFormat("builddelegation(\"{0}\", \"{1}\", this, {2}, {3})", srcPos, delegationKey, manglingName, "false"); } } return; } } } else { string fn; SymbolKind kind; if (IsNewObjMember(name, out fn, out kind)) { CodeBuilder.AppendFormat("getinstance(SymbolKind.{0}, newobj, {1}, \"{2}\")", kind.ToString(), fn, name); return; } ReportIllegalSymbol(node, symbolInfo); } } CodeBuilder.Append(name); }
public override void VisitIdentifierName(IdentifierNameSyntax node) { string name = node.Identifier.Text; if (m_ClassInfoStack.Count > 0) { ClassInfo classInfo = m_ClassInfoStack.Peek(); SymbolInfo symbolInfo = m_Model.GetSymbolInfo(node); var sym = symbolInfo.Symbol; if (null != sym) { bool isExtern = !SymbolTable.Instance.IsCs2DslSymbol(sym); if (sym.Kind == SymbolKind.NamedType || sym.Kind == SymbolKind.Namespace) { string fullName = ClassInfo.GetFullName(sym); CodeBuilder.Append(fullName); if (sym.Kind == SymbolKind.NamedType) { var namedType = sym as INamedTypeSymbol; AddReferenceAndTryDeriveGenericTypeInstance(classInfo, namedType); } return; } else if (sym.Kind == SymbolKind.Field || sym.Kind == SymbolKind.Property || sym.Kind == SymbolKind.Event) { if (IsNewObjMember(name)) { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, newobj, \"{2}\")", isExtern ? "getexterninstance" : "getinstance", sym.Kind.ToString(), name); return; } if (sym.ContainingType == classInfo.SemanticInfo || sym.ContainingType == classInfo.SemanticInfo.OriginalDefinition || classInfo.IsInherit(sym.ContainingType)) { if (sym.IsStatic) { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, {2}, \"{3}\")", isExtern ? "getexternstatic" : "getstatic", sym.Kind.ToString(), classInfo.Key, sym.Name); } else { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, this, \"{2}\")", isExtern ? "getexterninstance" : "getinstance", sym.Kind.ToString(), sym.Name); } return; } } else if (sym.Kind == SymbolKind.Method && (sym.ContainingType == classInfo.SemanticInfo || sym.ContainingType == classInfo.SemanticInfo.OriginalDefinition || classInfo.IsInherit(sym.ContainingType))) { var msym = sym as IMethodSymbol; string manglingName = NameMangling(msym); var mi = new MethodInfo(); mi.Init(msym, node); if (node.Parent is InvocationExpressionSyntax) { if (sym.IsStatic) { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, {2}, \"{3}\")", isExtern ? "getexternstatic" : "getstatic", sym.Kind.ToString(), classInfo.Key, manglingName); } else { CodeBuilder.AppendFormat("{0}(SymbolKind.{1}, this, \"{2}\")", isExtern ? "getexterninstance" : "getinstance", sym.Kind.ToString(), manglingName); } } else { string className = ClassInfo.GetFullName(msym.ContainingType); string delegationKey = string.Format("{0}:{1}", className, manglingName); string varName = string.Format("__delegation_{0}", GetSourcePosForVar(node)); CodeBuilder.Append("(function(){ "); string paramsString = string.Join(", ", mi.ParamNames.ToArray()); if (msym.IsStatic) { CodeBuilder.AppendFormat("builddelegation(\"{0}\", {1}, \"{2}\", {3}, {4}, {5}, {6});", paramsString, varName, delegationKey, className, manglingName, msym.ReturnsVoid ? "false" : "true", msym.IsStatic ? "true" : "false"); } else { CodeBuilder.AppendFormat("builddelegation(\"{0}\", {1}, \"{2}\", {3}, {4}, {5}, {6});", paramsString, varName, delegationKey, "this", manglingName, msym.ReturnsVoid ? "false" : "true", msym.IsStatic ? "true" : "false"); } CodeBuilder.Append(" })()"); } return; } } else { SymbolKind kind; if (IsNewObjMember(name, out kind)) { CodeBuilder.AppendFormat("getinstance(SymbolKind.{0}, newobj, \"{1}\")", kind.ToString(), name); return; } ReportIllegalSymbol(node, symbolInfo); } } CodeBuilder.Append(name); }