public static UnifiedParameter CreateParameterDeclaration(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "parameter_declaration"); /* * parameter_declaration * : declaration_specifiers (declarator|abstract_declarator)* */ UnifiedIdentifier name; UnifiedSet <UnifiedParameter> parameters; var modifiersAndType = CreateDeclarationSpecifiers( node.Element("declaration_specifiers")); var modifiers = modifiersAndType.Item1; var type = (UnifiedType)modifiersAndType.Item2; var declarators = node.Elements("declarator"); if (declarators.Count() == 0) { return(UnifiedParameter.Create(null, modifiers, type)); } var declarator = CreateDeclarator(node.FirstElement("declarator")); // abstract_declaratorはおそらく[]など=> よって、最初に現れることはないはず( // TODO 未検証) if (node.Element("abstract_declarator") != null) { // TODO (int y[])の場合は、[]はどこに付くのか? throw new NotImplementedException(); } // TODO 実際のところ、そこまで理解しきれていない else if (declarators.Count() == 1) { // 多分declarator自体は1つしか現れないはず( // TODO 未検証) return(UnifiedParameter.Create( null, modifiers, type, declarator.Item1.ToSet())); } else if (node.Element("declarator") != null) { parameters = declarator.Item2; name = declarator.Item1; if (parameters != null && parameters.Count > 0) { // この場合はパラメータが関数ポインタ var returnType = type; type = UnifiedType.Create( UnifiedFunctionDefinition.Create( null, modifiers, returnType, null, null, parameters)); modifiers = null; } return(UnifiedParameter.Create( null, modifiers, type, name.ToSet(), null)); } throw new InvalidOperationException(); }
//関数定義 : e.g. function hoge() { } public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { WriteIndent(arg.IndentDepth); Writer.Write("function "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); element.Body.TryAccept(this, arg.Set(ForBlock)); return(element.Body == null); }
public static UnifiedExpression CreateDefn(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "defn"); return(UnifiedFunctionDefinition.Create( null, null, null, null, CreateSymbol(node.NthElement(0)), CreateArgs(node.NthElement(1)), null, CreateScope(node.NthElement(2)))); }
public static IEnumerable<UnifiedFunctionDefinition> FindFunctionCollision(UnifiedElement element, UnifiedFunctionDefinition target) { foreach (var function in element.Descendants<UnifiedFunctionDefinition>()) { if (IsFunctionCollision(function, target)) { yield return function; } } }
public UnifiedElement VisitOperatorDeclaration(OperatorDeclaration dec, object data) { var attrs = dec.Attributes.AcceptVisitorAsAttrs(this, data); var mods = LookupModifiers(dec.Modifiers); var type = LookupType(dec.ReturnType); var name = UnifiedVariableIdentifier.Create(dec.Name); var parameters = dec.Parameters.AcceptVisitorAsParams(this, data); var body = dec.Body.TryAcceptForExpression(this).ToBlock(); return(UnifiedFunctionDefinition.Create( attrs, mods, type, /*generics*/ null, name, parameters, /*throws*/ null, body)); }
// 関数定義(UnifiedFunctionDefinition) public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { // int main(int param) { ... }; element.Modifiers.TryAccept(this, arg); element.Type.TryAccept(this, arg); Writer.Write(" "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); element.Body.TryAccept(this, arg.Set(ForBlock)); return element.Body == null; }
// 関数定義(UnifiedFunctionDefinition) public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { // int main(int param) { ... }; element.Modifiers.TryAccept(this, arg); element.Type.TryAccept(this, arg); Writer.Write(" "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); element.Body.TryAccept(this, arg.Set(ForBlock)); return(element.Body == null); }
public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); Writer.Write("def "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); Writer.WriteLine(":"); element.Body.TryAccept(this, arg.IncrementDepth()); return false; }
private static UnifiedExpression CreateDefs(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "defs"); var owner = CreateExpresion(node.NthElement(0)); var target = UnifiedFunctionDefinition.Create( null, null, null, null, CreateSymbol(node.NthElement(1)), CreateArgs(node.NthElement(2)), null, CreateScope(node.NthElement(3))); return(UnifiedProperty.Create(".", owner, target)); }
public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); Writer.Write("def "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); Writer.WriteLine(":"); element.Body.TryAccept(this, arg.IncrementDepth()); return(false); }
private static Boolean IsFunctionCollision(UnifiedFunctionDefinition src, UnifiedFunctionDefinition dst) { // Judge whether src and dst have same signature var judges = new List<Boolean>(); judges.Add(src.Name.Name == dst.Name.Name); judges.Add(src.Parameters.All(e => dst.Parameters.Any(e.Equals))); if (judges.All(e => e)) { return true; } return false; }
public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); element.Type.TryAccept(this, arg); Writer.Write(" "); element.Name.TryAccept(this, arg); element.GenericParameters.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); element.Throws.TryAccept(this, arg); element.Body.TryAccept(this, arg.Set(ForBlock)); return element.Body == null; }
public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); element.GenericParameters.TryAccept(this, arg); element.Type.TryAccept(this, arg); Writer.Write(" "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); element.Throws.TryAccept(this, arg); element.Body.TryAccept(this, arg.Set(ForBlock)); return(element.Body == null); }
public static Namespace GetNamespace( UnifiedFunctionDefinition functionNode) { var type = NamespaceType.Function; var functionName = functionNode.Name.Name; var parents = DetectorHelper.GetParentTypes(type).Select( t => DetectorHelper.Namespace2UnifiedType(t)); var parentNode = DetectorHelper.GetFirstFoundNode( functionNode, parents); return new Namespace { Value = functionName, NamespaceType = type, Parent = Dispatcher(parentNode), }; }
public static UnifiedFunctionDefinition CreateFunctionDefinition( XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "function_definition"); /* function_definition * : declaration_specifiers? declarator * ( declaration+ compound_statement // K&R style * | compound_statement // ANSI style * ) */ UnifiedSet <UnifiedModifier> modifiers = null; UnifiedType type = null; UnifiedSet <UnifiedGenericParameter> genericParameters = null; UnifiedIdentifier name = null; UnifiedSet <UnifiedParameter> parameters = null; UnifiedBlock body = null; var first = node.FirstElement(); if (first.Name() == "declaration_specifiers") { var modifiersAndType = CreateDeclarationSpecifiers(first); modifiers = modifiersAndType.Item1; type = (UnifiedType)modifiersAndType.Item2; } var declarator = CreateDeclarator(node.Element("declarator")); name = declarator.Item1; parameters = declarator.Item2; if (node.Elements("declaration").Count() != 0) { // TODO declaration+ compound_statement に該当するケースが未検出 throw new NotImplementedException(); } body = CreateCompoundStatement(node.Element("compound_statement")); return(UnifiedFunctionDefinition.Create( null, modifiers, type, genericParameters, name, parameters, null, body)); }
public UnifiedElement VisitMethodDeclaration( MethodDeclaration dec, object data) { var attrs = dec.Attributes.AcceptVisitorAsAttrs(this, data); var mods = LookupModifiers(dec.Modifiers); var type = LookupType(dec.ReturnType); var name = UnifiedVariableIdentifier.Create(dec.Name); var generics = dec.TypeParameters.AcceptVisitorAsTypeParams( this, data); if (generics.IsEmptyOrNull()) { generics = null; } var parameters = dec.Parameters.AcceptVisitorAsParams(this, data); var body = dec.Body.TryAcceptForExpression(this).ToBlock(); // TODO constraint return(UnifiedFunctionDefinition.Create( attrs, mods, type, generics, name, parameters, /* no throws */ null, body)); }
//関数定義 : e.g. function hoge() { } public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { WriteIndent(arg.IndentDepth); Writer.Write("function "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); element.Body.TryAccept(this, arg.Set(ForBlock)); return element.Body == null; }