public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Code assistance with GCC
@ 2010-04-21 11:12 Tomohiro Matsuyama
  2010-04-21 11:53 ` Basile Starynkevitch
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Tomohiro Matsuyama @ 2010-04-21 11:12 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]

Hi, all

I have been working on implementing a tool-set of code assistance called 
GCCSense, which enables code-completion for C/C++ in editors or a terminal.

http://cx4a.org/software/gccsense/

GCCSense depends on its own GCC which has special options for code 
assistance such like -code-completion-at:

     $ cat
     #include <string>
     int main()
     {
         std::string s;
         s.
     }
     $ # Print completion candidates at line 5 and column 7 of a.cc
     $ g++-code-assist -fsyntax-only -code-completion-at=a.cc:5:7 a.c

Now, I have the following problems:

* Hard to build that GCC for users
* Hard to maintain that GCC for me

Plugin might be a solution for them. Finally, however, I found that 
there is no proper plugin entrances for code assistance. As you may 
understand if you read an attached patch, GCCSense needs to handle 
quickly a special token for code-completion after particular tokens such 
as "." and "->" in parser phase.

Is there any good solution for this ?
Or could you implement such plugin entrances for code assistance ?

Thanks.
Tomohiro Matsuyama


[-- Attachment #2: gcc-code-assist.patch --]
[-- Type: text/x-patch, Size: 17187 bytes --]

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 88c40b6..ef22823 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1029,7 +1029,7 @@ C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
   c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
   c-ppoutput.o c-cppbuiltin.o \
   c-objc-common.o c-dump.o c-pch.o c-parser.o $(C_TARGET_OBJS) \
-  c-gimplify.o tree-mudflap.o c-pretty-print.o c-omp.o
+  c-gimplify.o tree-mudflap.o c-pretty-print.o c-omp.o c-code-assist.o
 
 # Language-specific object files for C.
 C_OBJS = c-lang.o stub-objc.o $(C_AND_OBJC_OBJS)
@@ -1070,6 +1070,7 @@ OBJS-common = \
 	cfgloopanal.o \
 	cfgloopmanip.o \
 	cfgrtl.o \
+	code-assist-common.o \
 	combine.o \
 	combine-stack-adj.o \
 	convert.o \
@@ -1941,6 +1942,9 @@ c-omp.o : c-omp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
 	$(FUNCTION_H) $(C_COMMON_H) $(TOPLEV.H) $(GIMPLE_H) $(BITMAP_H) \
 	langhooks.h
 
+c-code-assist.o : c-code-assist.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
+		$(FUNCTION_H) $(C_COMMON_H) $(TOPLEV.H) $(GIMPLE_H) $(BITMAP_H)
+
 # Language-independent files.
 
 DRIVER_DEFINES = \
@@ -2807,6 +2811,7 @@ cfgloop.o : cfgloop.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) coretypes.h $(TM_H) \
 cfgloopanal.o : cfgloopanal.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) \
    $(BASIC_BLOCK_H) hard-reg-set.h $(CFGLOOP_H) $(EXPR_H) coretypes.h $(TM_H) \
    $(OBSTACK_H) output.h graphds.h $(PARAMS_H)
+code-assist-common.o : code-assist-common.c $(CONFIG_H) $(SYSTEM_H)
 graphds.o : graphds.c graphds.h $(CONFIG_H) $(SYSTEM_H) $(BITMAP_H) $(OBSTACK_H) \
    coretypes.h vec.h vecprim.h
 loop-iv.o : loop-iv.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(BASIC_BLOCK_H) \
diff --git a/gcc/c-code-assist.c b/gcc/c-code-assist.c
new file mode 100644
index 0000000..de76100
--- /dev/null
+++ b/gcc/c-code-assist.c
@@ -0,0 +1,27 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree.h"
+#include "flags.h"
+#include "toplev.h"
+#include "langhooks.h"
+#include "diagnostic.h"
+#include "debug.h"
+#include "opts.h"
+#include "options.h"
+#include "c-tree.h"
+#include "code-assist.h"
+
+void code_completion_decls (tree node, bool nonstatic)
+{
+  while (node)
+    {
+      print_completion (node);
+      node = TREE_CHAIN (node);
+    }
+}
+
+void code_completion_scope (tree scope)
+{
+}
diff --git a/gcc/c-opts.c b/gcc/c-opts.c
index 28bdc31..76b6388 100644
--- a/gcc/c-opts.c
+++ b/gcc/c-opts.c
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "mkdeps.h"
 #include "target.h"
 #include "tm_p.h"
+#include "code-assist.h"
 
 #ifndef DOLLARS_IN_IDENTIFIERS
 # define DOLLARS_IN_IDENTIFIERS true
@@ -550,6 +551,10 @@ c_common_handle_option (size_t scode, const char *arg, int value)
 	set_std_cxx98 (true);
       break;
 
+    case OPT_code_completion_at_:
+      code_assist_setup (cpp_opts, CPP_CODE_COMPLETION, arg, "-code-completion-at");
+      break;
+
     case OPT_d:
       handle_OPT_d (arg);
       break;
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 0f047de..0c149b0 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -57,6 +57,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "vec.h"
 #include "target.h"
 #include "cgraph.h"
+#include "code-assist.h"
 
 \f
 /* Initialization routine for this file.  */
@@ -5595,6 +5596,11 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
 	  /* Structure element reference.  */
 	  c_parser_consume_token (parser);
 	  expr = default_function_array_conversion (expr);
+          if (c_parser_next_token_is (parser, CPP_CODE_COMPLETION))
+	    {
+	      c_parser_consume_token (parser);
+	      code_completion_expr (expr.value);
+	    }
 	  if (c_parser_next_token_is (parser, CPP_NAME))
 	    ident = c_parser_peek_token (parser)->value;
 	  else
@@ -5612,6 +5618,13 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
 	  /* Structure element reference.  */
 	  c_parser_consume_token (parser);
 	  expr = default_function_array_conversion (expr);
+          if (c_parser_next_token_is (parser, CPP_CODE_COMPLETION))
+	    {
+	      c_parser_consume_token (parser);
+	      code_completion_expr (build_indirect_ref (loc,
+							expr.value,
+							"->"));
+	    }
 	  if (c_parser_next_token_is (parser, CPP_NAME))
 	    ident = c_parser_peek_token (parser)->value;
 	  else
diff --git a/gcc/c.opt b/gcc/c.opt
index 711710b..d7cc7bf 100644
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -500,6 +500,10 @@ ansi
 C ObjC C++ ObjC++
 A synonym for -std=c89 (for C) or -std=c++98 (for C++)
 
+code-completion-at=
+C ObjC C++ ObjC++ Joined
+-code-completion-at=<line>:<column>	Code completions at specified position by <line> and <column>
+
 d
 C ObjC C++ ObjC++ Joined
 ; Documented in common.opt.  FIXME - what about -dI, -dD, -dN and -dD?
diff --git a/gcc/code-assist-common.c b/gcc/code-assist-common.c
new file mode 100644
index 0000000..1c9d2de
--- /dev/null
+++ b/gcc/code-assist-common.c
@@ -0,0 +1,111 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree.h"
+#include "flags.h"
+#include "toplev.h"
+#include "langhooks.h"
+#include "diagnostic.h"
+#include "debug.h"
+#include "opts.h"
+#include "options.h"
+#include "c-tree.h"
+#include "code-assist.h"
+
+enum cpp_ttype code_assist_type;
+
+static const char *generic_node_name (tree node)
+{
+  enum tree_code code;
+  enum tree_code_class tclass;
+  const char *name = 0;
+  
+  if (!node)
+    return 0;
+
+  code = TREE_CODE (node);
+  tclass = TREE_CODE_CLASS (code);
+
+  if (tclass == tcc_declaration)
+    {
+      if (DECL_NAME (node))
+        name = IDENTIFIER_POINTER (DECL_NAME (node));
+    }
+  
+  return name;
+}
+
+static void code_completion_base_types (tree type, bool nonstatic)
+{
+  /* Base types.  */
+  int i;
+  tree base_binfo;
+  tree binfo;
+
+  for (binfo = TYPE_BINFO (type), i = 0;
+       binfo && BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
+    {
+      tree basetype = TREE_TYPE (base_binfo);
+      code_completion_type (basetype, nonstatic);
+    }
+}
+
+void code_assist_setup (cpp_options *cpp_opts, enum cpp_ttype type, const char *arg, const char *opt)
+{
+  const char *p = strchr (arg, ':');
+  const char *q = 0;
+
+  if (p)
+    {
+      q = strchr (p + 1, ':');
+    }
+  if (!p || !q)
+    {
+      error ("%s must take a form of line:column", opt);
+      return;
+    }
+
+  code_assist_type = type;
+  cpp_opts->phantom_token.type = type;
+  cpp_opts->phantom_token.file = xstrndup (arg, p - arg);
+  cpp_opts->phantom_token.line = atoi (p + 1);
+  cpp_opts->phantom_token.column = atoi (q + 1);
+}
+
+void print_completion (tree node)
+{
+  const char *name = generic_node_name (node);
+  if (name)
+    printf ("completion: %s \"%s\"\n", name, lang_hooks.decl_printable_name (node, 2));
+}
+
+void code_completion_type (tree type, bool nonstatic)
+{
+  enum tree_code code;
+  
+  if (!type)
+    return;
+  
+  code = TREE_CODE (type);
+
+  switch (code)
+    {
+    case RECORD_TYPE:
+    case UNION_TYPE:
+    case QUAL_UNION_TYPE:
+      code_completion_decls (TYPE_FIELDS (type), nonstatic);
+      code_completion_decls (TYPE_METHODS (type), nonstatic);
+      code_completion_base_types (type, nonstatic);
+      break;
+    default:
+      break;
+    }
+}
+
+void code_completion_expr (tree expr)
+{
+  if (!expr)
+    return;
+  code_completion_type (TREE_TYPE (expr), true);
+}
diff --git a/gcc/code-assist.h b/gcc/code-assist.h
new file mode 100644
index 0000000..20b8cb0
--- /dev/null
+++ b/gcc/code-assist.h
@@ -0,0 +1,16 @@
+#ifndef GCC_CODE_ASSIST_H
+#define GCC_CODE_ASSIST_H
+
+#include "cpplib.h"
+#include "input.h"
+
+extern enum cpp_ttype code_assist_type;
+
+extern void code_assist_setup (cpp_options *, enum cpp_ttype, const char *, const char *);
+extern void print_completion (tree);
+extern void code_completion_decls (tree, bool);
+extern void code_completion_type (tree, bool);
+extern void code_completion_expr (tree);
+extern void code_completion_scope (tree);
+
+#endif /* ! GCC_CODE_ASSIST_H */
diff --git a/gcc/common.opt b/gcc/common.opt
index 023d773..5391bb0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -246,6 +246,10 @@ Common Separate
 auxbase-strip
 Common Separate
 
+code-completion-at=
+C ObjC C++ ObjC++ Joined
+-code-completion-at=<line>:<column>	Code completions at specified position by <line> and <column>
+
 d
 Common Joined
 -d<letters>	Enable dumps from specific passes of the compiler
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 626a63e..18bb2c6 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -81,7 +81,7 @@ CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
  cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
  cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o cp/optimize.o \
  cp/mangle.o cp/cp-objcp-common.o cp/name-lookup.o cp/cxx-pretty-print.o \
- cp/cp-gimplify.o tree-mudflap.o $(CXX_C_OBJS)
+ cp/cp-gimplify.o cp/cp-code-assist.o tree-mudflap.o $(CXX_C_OBJS)
 
 # Language-specific object files for C++.
 CXX_OBJS = cp/cp-lang.o stub-objc.o $(CXX_AND_OBJCXX_OBJS)
@@ -302,3 +302,6 @@ cp/name-lookup.o: cp/name-lookup.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
 
 cp/cxx-pretty-print.o: cp/cxx-pretty-print.c $(CXX_PRETTY_PRINT_H) \
   $(CONFIG_H) $(SYSTEM_H) $(TM_H) coretypes.h $(CXX_TREE_H)
+
+cp/cp-code-assist.o: cp/cp-code-assist.c $(CXX_TREE_H) toplev.h $(C_COMMON_H) \
+	$(TM_H) coretypes.h pointer-set.h tree-iterator.h
diff --git a/gcc/cp/cp-code-assist.c b/gcc/cp/cp-code-assist.c
new file mode 100644
index 0000000..b9f00cf
--- /dev/null
+++ b/gcc/cp/cp-code-assist.c
@@ -0,0 +1,56 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "flags.h"
+#include "tree.h"
+#include "cp-tree.h"
+#include "toplev.h"
+#include "langhooks.h"
+#include "diagnostic.h"
+#include "debug.h"
+#include "code-assist.h"
+#include "name-lookup.h"
+
+void code_completion_decls (tree node, bool nonstatic)
+{
+  while (node)
+    {
+      enum tree_code code = TREE_CODE (node);
+
+      if (nonstatic
+	  ? (code == FIELD_DECL
+	     || (code == FUNCTION_DECL
+		 && !DECL_STATIC_FUNCTION_P (node)))
+	  : ((code == VAR_DECL
+	      || code == CONST_DECL
+	      || code == TYPE_DECL)
+	     || (code == FUNCTION_DECL
+		 && DECL_STATIC_FUNCTION_P (node))))
+	print_completion (node);
+      
+      node = TREE_CHAIN (node);
+    }
+}
+
+void code_completion_scope (tree scope)
+{
+  enum tree_code code;
+
+  if (!scope)
+    return;
+
+  code = TREE_CODE (scope);
+
+  if (code == NAMESPACE_DECL)
+    {
+      tree decls = cp_namespace_decls (scope);
+      while (decls)
+	{
+	  print_completion (decls);
+	  decls = TREE_CHAIN (decls);
+	}
+    }
+  else
+    code_completion_type (scope, false);
+}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index eba1707..5bb2cea 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "timevar.h"
 #include "tree-flow.h"
 #include "pointer-set.h"
+#include "code-assist.h"
 
 static tree grokparms (tree parmlist, tree *);
 static const char *redeclaration_error_message (tree, tree);
@@ -12359,7 +12360,8 @@ finish_function (int flags)
       && !TREE_NO_WARNING (fndecl)
       /* Structor return values (if any) are set by the compiler.  */
       && !DECL_CONSTRUCTOR_P (fndecl)
-      && !DECL_DESTRUCTOR_P (fndecl))
+      && !DECL_DESTRUCTOR_P (fndecl)
+      && !code_assist_type)
     {
       warning (OPT_Wreturn_type,
  	       "no return statement in function returning non-void");
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4f75606..a607f62 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "target.h"
 #include "cgraph.h"
 #include "c-common.h"
+#include "code-assist.h"
 
 \f
 /* The lexer.  */
@@ -4034,6 +4035,7 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
       tree old_scope;
       tree saved_qualifying_scope;
       bool template_keyword_p;
+      bool code_completion_p = false;
 
       /* Spot cases that cannot be the beginning of a
 	 nested-name-specifier.  */
@@ -4120,6 +4122,12 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
       /* Look for the `::' token.  */
       cp_parser_require (parser, CPP_SCOPE, "%<::%>");
 
+      if (cp_lexer_next_token_is (parser->lexer, CPP_CODE_COMPLETION))
+	{
+	  code_completion_p = true;
+	  cp_lexer_consume_token (parser->lexer);
+	}
+
       /* If we found what we wanted, we keep going; otherwise, we're
 	 done.  */
       if (!cp_parser_parse_definitely (parser))
@@ -4231,6 +4239,10 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
       /* Make sure we look in the right scope the next time through
 	 the loop.  */
       parser->scope = new_scope;
+
+      /* Code completion here.  */
+      if (code_completion_p)
+	code_completion_scope (parser->scope);
     }
 
   /* If parsing tentatively, replace the sequence of tokens that makes
@@ -4847,17 +4859,51 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 	     postfix-expression . pseudo-destructor-name
 	     postfix-expression -> template [opt] id-expression
 	     postfix-expression -> pseudo-destructor-name */
+	  {
+	    tree code_assist_expr = 0;
+	    
+	    /* Consume the `.' or `->' operator.  */
+	    cp_lexer_consume_token (parser->lexer);
+	    
+	    if (cp_lexer_next_token_is (parser->lexer, CPP_CODE_COMPLETION))
+	      {
+		code_assist_expr = postfix_expression;
+		cp_lexer_consume_token (parser->lexer);
+	      }
 
-	  /* Consume the `.' or `->' operator.  */
-	  cp_lexer_consume_token (parser->lexer);
+	    postfix_expression
+	      = cp_parser_postfix_dot_deref_expression (parser, token->type,
+							postfix_expression,
+							false, &idk,
+							token->location);
 
-	  postfix_expression
-	    = cp_parser_postfix_dot_deref_expression (parser, token->type,
-						      postfix_expression,
-						      false, &idk,
-						      token->location);
+	    is_member_access = true;
+
+	    if (code_assist_expr)
+	      {
+		tree type;
+		tree expr = code_assist_expr;
+		if (token->type == CPP_DEREF)
+		  {
+		    tree e = build_x_arrow (expr);
+		    if (!TREE_TYPE (e))
+		      expr = TREE_TYPE (expr);
+		    else
+		      expr = e;
+		  }
+                type = expr ? TREE_TYPE (expr) : NULL_TREE;
+		if (!type)
+		  break;
 
-          is_member_access = true;
+		/* Use approximate type if type is not completed.  */
+		if (CLASS_TYPE_P (type)
+		    && !COMPLETE_TYPE_P (type)
+		    && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
+		  type = TREE_TYPE (most_general_template (CLASSTYPE_TI_TEMPLATE (type)));
+
+		code_completion_type (type, true);
+	      }
+	  }
 	  break;
 
 	case CPP_PLUS_PLUS:
@@ -14589,6 +14635,61 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
 static void
 cp_parser_function_body (cp_parser *parser)
 {
+  if (code_assist_type)
+    {
+      unsigned nesting_depth = 1;
+
+      /* Skip the function body.  */
+
+      /* Save tokens so that we can rollback if necessary to
+	 parse the function body.  */
+      cp_lexer_save_tokens (parser->lexer);
+
+      cp_parser_require (parser, CPP_OPEN_BRACE, "%<{%>");
+
+      /* Skip to a next outermost close brace.  */
+      while (true)
+	{
+	  cp_token *token = cp_lexer_peek_token (parser->lexer);
+
+	  switch (token->type)
+	    {
+	    case CPP_EOF:
+	    case CPP_PRAGMA_EOL:
+	      goto skipped;
+	      
+	    case CPP_OPEN_BRACE:
+	      nesting_depth++;
+	      break;
+
+	    case CPP_CLOSE_BRACE:
+	      if (--nesting_depth == 0)
+		{
+		  cp_lexer_consume_token (parser->lexer);
+		  goto skipped;
+		}
+	      break;
+
+	    case CPP_CODE_COMPLETION:
+	      goto parse;
+
+	    default:
+	      break;
+	    }
+
+	  cp_lexer_consume_token (parser->lexer);
+	}
+
+    skipped:
+      /* No need to rollback.  */
+      cp_lexer_commit_tokens (parser->lexer);
+      return;
+
+    parse:
+      /* Rollback to parse the function body.  */
+      cp_lexer_rollback_tokens (parser->lexer);
+    }
+  
   cp_parser_compound_statement (parser, NULL, false);
 }
 
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 1f1d85f..29d4ac3 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -836,7 +836,8 @@ static const char *cc1_options =
  %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
  %{fsyntax-only:-o %j} %{-param*}\
  %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\
- %{coverage:-fprofile-arcs -ftest-coverage}";
+ %{coverage:-fprofile-arcs -ftest-coverage}\
+ %{code-completion-at=*:-code-completion-at=%*}";
 
 static const char *asm_options =
 "%{--target-help:%:print-asm-header()} "
@@ -1106,6 +1107,7 @@ static const struct option_map option_map[] =
    {"--classpath", "-fclasspath=", "aj"},
    {"--bootclasspath", "-fbootclasspath=", "aj"},
    {"--CLASSPATH", "-fclasspath=", "aj"},
+   {"--code-completion-at", "-code-completion-at=", "aj"},
    {"--combine", "-combine", 0},
    {"--comments", "-C", 0},
    {"--comments-in-macros", "-CC", 0},

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 11:12 Code assistance with GCC Tomohiro Matsuyama
@ 2010-04-21 11:53 ` Basile Starynkevitch
  2010-04-21 14:22   ` Daniel Jacobowitz
  2010-04-21 14:47 ` Manuel López-Ibáñez
  2010-04-21 17:37 ` Chris Lattner
  2 siblings, 1 reply; 13+ messages in thread
From: Basile Starynkevitch @ 2010-04-21 11:53 UTC (permalink / raw)
  To: Tomohiro Matsuyama; +Cc: gcc

Tomohiro Matsuyama wrote:
> Hi, all
> 
> I have been working on implementing a tool-set of code assistance called 
> GCCSense, which enables code-completion for C/C++ in editors or a terminal.
> 
> http://cx4a.org/software/gccsense/
> 
> GCCSense depends on its own GCC which has special options for code 
> assistance such like -code-completion-at:
> 
>     $ cat
>     #include <string>
>     int main()
>     {
>         std::string s;
>         s.
>     }
>     $ # Print completion candidates at line 5 and column 7 of a.cc
>     $ g++-code-assist -fsyntax-only -code-completion-at=a.cc:5:7 a.c
> 
> Now, I have the following problems:
> 
> * Hard to build that GCC for users
> * Hard to maintain that GCC for me
> 
> Plugin might be a solution for them. Finally, however, I found that 
> there is no proper plugin entrances for code assistance. As you may 
> understand if you read an attached patch, GCCSense needs to handle 
> quickly a special token for code-completion after particular tokens such 
> as "." and "->" in parser phase.
> 
> Is there any good solution for this ?
> Or could you implement such plugin entrances for code assistance ?
> 
> Thanks.
> Tomohiro Matsuyama
> 


I did suggest (in a previous private emaol) to Tomohiro to consider 
making his g++-code-assist  a proper GCC plugin. I even dared suggesting 
him to make it a GCC MELT module (see 
http://gcc.gnu.org/wiki/MiddleEndLispTranslator for more about GCC MELT).

However, I am not sure to understand why Tomohiro needs to hack the GCC 
parser itself. I was thinking that he might instead write a plugin which 
works at the Generic/TREE (or even perhaps  Gimple) level.

What do other people think?

Regards.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 11:53 ` Basile Starynkevitch
@ 2010-04-21 14:22   ` Daniel Jacobowitz
  2010-04-21 15:52     ` Basile Starynkevitch
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel Jacobowitz @ 2010-04-21 14:22 UTC (permalink / raw)
  To: Basile Starynkevitch; +Cc: Tomohiro Matsuyama, gcc

On Wed, Apr 21, 2010 at 01:12:37PM +0200, Basile Starynkevitch wrote:
> However, I am not sure to understand why Tomohiro needs to hack the
> GCC parser itself. I was thinking that he might instead write a
> plugin which works at the Generic/TREE (or even perhaps  Gimple)
> level.

That doesn't make sense.  If you're doing code completion, then by
definition, what you have now does not parse.  If it doesn't parse,
you can't build IL from it.  A parser is pretty much all you need for
code completion, not any of the rest of the compiler (e.g. Eclipse has
just a parser and a syntax tree).

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 11:12 Code assistance with GCC Tomohiro Matsuyama
  2010-04-21 11:53 ` Basile Starynkevitch
@ 2010-04-21 14:47 ` Manuel López-Ibáñez
  2010-04-21 17:37 ` Chris Lattner
  2 siblings, 0 replies; 13+ messages in thread
From: Manuel López-Ibáñez @ 2010-04-21 14:47 UTC (permalink / raw)
  To: Tomohiro Matsuyama; +Cc: gcc

On 21 April 2010 12:32, Tomohiro Matsuyama <tomo@cx4a.org> wrote:
> Hi, all
>
> I have been working on implementing a tool-set of code assistance called
> GCCSense, which enables code-completion for C/C++ in editors or a terminal.
>
> http://cx4a.org/software/gccsense/
>
> GCCSense depends on its own GCC which has special options for code
> assistance such like -code-completion-at:

That seems like a really cool project.

> Plugin might be a solution for them. Finally, however, I found that there is
> no proper plugin entrances for code assistance. As you may understand if you
> read an attached patch, GCCSense needs to handle quickly a special token for
> code-completion after particular tokens such as "." and "->" in parser
> phase.
>
> Is there any good solution for this ?

I think the approach of adding phantom tokens is going to be
unmaintainable. The C++ parser depends too much on tentative parsing,
so things need to fail for the parser to work. When you add tokens
like that, you alter the behaviour of when tentative parse fails and
succeeds.

The plugin approach would need a lot of hooks in the parser and too
many internal details exposed, I think.

This would be easier if the C++ parser was more like a library with an
external interface that can be extended. Then, probably you would be
able to reuse most of the C++ parser but extend/override the functions
that parse "." and "->" expression. That still may cause trouble with
tentative parse, but I think it will be less unpredictable and a
matter of catching all corner cases. Of course, this would require
substantial changes to the C++ parser, but perhaps if done in a proper
way, those changes would be welcome and beneficial.

> Or could you implement such plugin entrances for code assistance ?

I am curious about the answer to this. Because I am not sure of the
cost of each plugin hook we add, GCC is already too slow and the
demand is only going to increase.

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 14:22   ` Daniel Jacobowitz
@ 2010-04-21 15:52     ` Basile Starynkevitch
  0 siblings, 0 replies; 13+ messages in thread
From: Basile Starynkevitch @ 2010-04-21 15:52 UTC (permalink / raw)
  To: Basile Starynkevitch, Tomohiro Matsuyama, gcc

Daniel Jacobowitz wrote:
> On Wed, Apr 21, 2010 at 01:12:37PM +0200, Basile Starynkevitch wrote:
>> However, I am not sure to understand why Tomohiro needs to hack the
>> GCC parser itself. I was thinking that he might instead write a
>> plugin which works at the Generic/TREE (or even perhaps  Gimple)
>> level.
> 
> That doesn't make sense.  If you're doing code completion, then by
> definition, what you have now does not parse.  If it doesn't parse,
> you can't build IL from it.  A parser is pretty much all you need for
> code completion, not any of the rest of the compiler (e.g. Eclipse has
> just a parser and a syntax tree).


I agree, but I am not sure Tomohiro is doing code completion inside the 
source file (i.e. inside an incomplete source file which was not saved 
by the editor). I thought that his emacs mode was triggering his program 
(on a source file in a sane state, i.e. just after emacs having saved 
it) with the symbol to complete passed in argument.

In that case, his program has to consult the symbol tables & other 
information from a completely parsed & sane file, and this might be done 
as a plugin.

And if indeed he is doing completion an incomplete source, I am not sure 
that hacking GCC is the good approach...

Cheers.
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 11:12 Code assistance with GCC Tomohiro Matsuyama
  2010-04-21 11:53 ` Basile Starynkevitch
  2010-04-21 14:47 ` Manuel López-Ibáñez
@ 2010-04-21 17:37 ` Chris Lattner
  2010-04-21 17:51   ` Andrew Haley
  2 siblings, 1 reply; 13+ messages in thread
From: Chris Lattner @ 2010-04-21 17:37 UTC (permalink / raw)
  To: Tomohiro Matsuyama; +Cc: gcc


On Apr 21, 2010, at 3:32 AM, Tomohiro Matsuyama wrote:

> Hi, all
> 
> I have been working on implementing a tool-set of code assistance called GCCSense, which enables code-completion for C/C++ in editors or a terminal.
> 
> http://cx4a.org/software/gccsense/

This approach seems highly, uh, "inspired" from the exact same functionality in Clang.  Any reason not to contribute to that effort?

-Chris

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 17:37 ` Chris Lattner
@ 2010-04-21 17:51   ` Andrew Haley
  2010-04-21 20:52     ` Manuel López-Ibáñez
  2010-04-23  3:29     ` Michael Witten
  0 siblings, 2 replies; 13+ messages in thread
From: Andrew Haley @ 2010-04-21 17:51 UTC (permalink / raw)
  To: gcc

On 04/21/2010 06:35 PM, Chris Lattner wrote:
> 
> On Apr 21, 2010, at 3:32 AM, Tomohiro Matsuyama wrote:
> 
>> Hi, all
>>
>> I have been working on implementing a tool-set of code assistance
>> called GCCSense, which enables code-completion for C/C++ in editors
>> or a terminal.
>>
>> http://cx4a.org/software/gccsense/
> 
> This approach seems highly, uh, "inspired" from the exact same
> functionality in Clang.  Any reason not to contribute to that
> effort?

Surely trying to persuade people to contribute to some other project
rather than gcc is off-topic here.  Even if not, it's pretty hostile.

Andrew.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 17:51   ` Andrew Haley
@ 2010-04-21 20:52     ` Manuel López-Ibáñez
  2010-04-22  1:41       ` Chris Lattner
  2010-04-23  3:29     ` Michael Witten
  1 sibling, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2010-04-21 20:52 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc

On 21 April 2010 19:49, Andrew Haley <aph@redhat.com> wrote:
> On 04/21/2010 06:35 PM, Chris Lattner wrote:
>>
>> On Apr 21, 2010, at 3:32 AM, Tomohiro Matsuyama wrote:
>>
>>> Hi, all
>>>
>>> I have been working on implementing a tool-set of code assistance
>>> called GCCSense, which enables code-completion for C/C++ in editors
>>> or a terminal.
>>>
>>> http://cx4a.org/software/gccsense/
>>
>> This approach seems highly, uh, "inspired" from the exact same
>> functionality in Clang.  Any reason not to contribute to that
>> effort?
>
> Surely trying to persuade people to contribute to some other project
> rather than gcc is off-topic here.  Even if not, it's pretty hostile.

Would such a feature be accepted in GCC? Otherwise, this seems like a
misunderstanding. Chris was not suggesting to contribute to Clang
instead of GCC but instead to contribute to the Clang completion
library rather than create your own 1-person project. Or at least this
is how I understood it.

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 20:52     ` Manuel López-Ibáñez
@ 2010-04-22  1:41       ` Chris Lattner
  2010-04-22 12:16         ` Jakub Jelinek
  0 siblings, 1 reply; 13+ messages in thread
From: Chris Lattner @ 2010-04-22  1:41 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Andrew Haley, gcc

On Apr 21, 2010, at 1:51 PM, Manuel López-Ibáñez wrote:
>>>> http://cx4a.org/software/gccsense/
>>> 
>>> This approach seems highly, uh, "inspired" from the exact same
>>> functionality in Clang.  Any reason not to contribute to that
>>> effort?
>> 
>> Surely trying to persuade people to contribute to some other project
>> rather than gcc is off-topic here.  Even if not, it's pretty hostile.
> 
> Would such a feature be accepted in GCC? Otherwise, this seems like a
> misunderstanding. Chris was not suggesting to contribute to Clang
> instead of GCC but instead to contribute to the Clang completion
> library rather than create your own 1-person project. Or at least this
> is how I understood it.

I actually meant to respond to him personally, I apologize for cc'ing the list.

I did this because the other responses made it seem that it wasn't something that would be accepted back into GCC proper.  Maintaining an invasive patch on the side for a long period of time didn't seem like a great idea.

-Chris

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-22  1:41       ` Chris Lattner
@ 2010-04-22 12:16         ` Jakub Jelinek
  2010-04-22 16:50           ` Chris Lattner
  0 siblings, 1 reply; 13+ messages in thread
From: Jakub Jelinek @ 2010-04-22 12:16 UTC (permalink / raw)
  To: Chris Lattner; +Cc: Manuel L?pez-Ib??ez, Andrew Haley, gcc

On Wed, Apr 21, 2010 at 06:23:44PM -0700, Chris Lattner wrote:
> On Apr 21, 2010, at 1:51 PM, Manuel López-Ibáñez wrote:
> >>>> http://cx4a.org/software/gccsense/
> >>> 
> >>> This approach seems highly, uh, "inspired" from the exact same
> >>> functionality in Clang.  Any reason not to contribute to that
> >>> effort?
> >> 
> >> Surely trying to persuade people to contribute to some other project
> >> rather than gcc is off-topic here.  Even if not, it's pretty hostile.
> > 
> > Would such a feature be accepted in GCC? Otherwise, this seems like a
> > misunderstanding. Chris was not suggesting to contribute to Clang
> > instead of GCC but instead to contribute to the Clang completion
> > library rather than create your own 1-person project. Or at least this
> > is how I understood it.
> 
> I actually meant to respond to him personally, I apologize for cc'ing the list.
> 
> I did this because the other responses made it seem that it wasn't
> something that would be accepted back into GCC proper.  Maintaining an

Can you point at any response that said it would not be accepted back into
GCC proper?  There were no such comments AFAIK.  All that has been said
is that it is not possible to implement it AS A PLUGIN, at least not currently
and would probably require way too many hook points unless it wants to do
only code completion after . and -> (and not e.g. after :: and many other
tokens).  For C++ tentative parsing is probably the biggest problem that
needs solving.

	Jakub

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-22 12:16         ` Jakub Jelinek
@ 2010-04-22 16:50           ` Chris Lattner
  2010-04-23  4:47             ` Miles Bader
  0 siblings, 1 reply; 13+ messages in thread
From: Chris Lattner @ 2010-04-22 16:50 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Manuel L?pez-Ib??ez, Andrew Haley, gcc


On Apr 22, 2010, at 4:29 AM, Jakub Jelinek wrote:

>> 
>> I did this because the other responses made it seem that it wasn't
>> something that would be accepted back into GCC proper.  Maintaining an
> 
> Can you point at any response that said it would not be accepted back into
> GCC proper?  There were no such comments AFAIK.  All that has been said
> is that it is not possible to implement it AS A PLUGIN,

Nope, you are correct.  Again, the cc was a mistake and I apologize for it.

> at least not currently
> and would probably require way too many hook points unless it wants to do
> only code completion after . and -> (and not e.g. after :: and many other
> tokens).  For C++ tentative parsing is probably the biggest problem that
> needs solving.

I predict it won't be accepted into GCC mainline either, but we'll see. :)

-Chris

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-21 17:51   ` Andrew Haley
  2010-04-21 20:52     ` Manuel López-Ibáñez
@ 2010-04-23  3:29     ` Michael Witten
  1 sibling, 0 replies; 13+ messages in thread
From: Michael Witten @ 2010-04-23  3:29 UTC (permalink / raw)
  To: gcc

On Wed, Apr 21, 2010 at 12:49, Andrew Haley <aph@redhat.com> wrote:
> On 04/21/2010 06:35 PM, Chris Lattner wrote:
>> This approach seems highly, uh, "inspired" from the exact same
>> functionality in Clang.  Any reason not to contribute to that
>> effort?
>
> Surely trying to persuade people to contribute to some other project
> rather than gcc is off-topic here.  Even if not, it's pretty hostile.

Chris Lattner of Apple
    Chief architect of the LLVM project and Clang.

Andrew Haley of Red Hat
    Maintainer of the GCC's Java frontend.

Michael Witten
    Preparer of Popcorn.

:-D

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Code assistance with GCC
  2010-04-22 16:50           ` Chris Lattner
@ 2010-04-23  4:47             ` Miles Bader
  0 siblings, 0 replies; 13+ messages in thread
From: Miles Bader @ 2010-04-23  4:47 UTC (permalink / raw)
  To: gcc

Chris Lattner <clattner@apple.com> writes:
>>> I did this because the other responses made it seem that it wasn't
>>> something that would be accepted back into GCC proper.  Maintaining an
>> 
>> Can you point at any response that said it would not be accepted back into
>> GCC proper?  There were no such comments AFAIK.  All that has been said
>> is that it is not possible to implement it AS A PLUGIN,
>
> Nope, you are correct.  Again, the cc was a mistake and I apologize for it.

But people aren't objecting to the CC, they're objecting to the message
you were (apparently) trying to send to the original poster.  If
anything, the CC was _good_, because it allowed some measure of debate.

-Miles

-- 
Fast, small, soon; pick any 2.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-04-23  4:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21 11:12 Code assistance with GCC Tomohiro Matsuyama
2010-04-21 11:53 ` Basile Starynkevitch
2010-04-21 14:22   ` Daniel Jacobowitz
2010-04-21 15:52     ` Basile Starynkevitch
2010-04-21 14:47 ` Manuel López-Ibáñez
2010-04-21 17:37 ` Chris Lattner
2010-04-21 17:51   ` Andrew Haley
2010-04-21 20:52     ` Manuel López-Ibáñez
2010-04-22  1:41       ` Chris Lattner
2010-04-22 12:16         ` Jakub Jelinek
2010-04-22 16:50           ` Chris Lattner
2010-04-23  4:47             ` Miles Bader
2010-04-23  3:29     ` Michael Witten

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).