Skip to content

Commit

Permalink
Read makefile as token
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Oct 12, 2009
1 parent d1940ce commit d9b502f
Show file tree
Hide file tree
Showing 12 changed files with 416 additions and 26 deletions.
19 changes: 19 additions & 0 deletions libanjuta/anjuta-token-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ anjuta_token_file_get_content (AnjutaTokenFile *file, GError **error)
return file->content;
}

AnjutaToken*
anjuta_token_file_load (AnjutaTokenFile *file, GError **error)
{
if (file->content == NULL)
{
gchar *content;
gsize length;

if (g_file_load_contents (file->file, NULL, &content, &length, NULL, error))
{
file->first = anjuta_token_new_static (ANJUTA_TOKEN_FILE, content);
file->content = content;
file->length = length;
}
}

return file->first;
}

gsize
anjuta_token_file_get_length (AnjutaTokenFile *file, GError **error)
{
Expand Down
1 change: 1 addition & 0 deletions libanjuta/anjuta-token-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ AnjutaTokenFile *anjuta_token_file_new (GFile *file);
void anjuta_token_file_free (AnjutaTokenFile *file);

const gchar* anjuta_token_file_get_content (AnjutaTokenFile *file, GError **error);
AnjutaToken* anjuta_token_file_load (AnjutaTokenFile *file, GError **error);
gsize anjuta_token_file_get_length (AnjutaTokenFile *file, GError **error);
void anjuta_token_file_move (AnjutaTokenFile *file, GFile *new_file);
gboolean anjuta_token_file_save (AnjutaTokenFile *file, GError **error);
Expand Down
6 changes: 3 additions & 3 deletions libanjuta/anjuta-token.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ anjuta_token_insert_child (AnjutaToken *parent, AnjutaToken *child)
AnjutaToken *
anjuta_token_insert_after (AnjutaToken *sibling, AnjutaToken *token)
{
return (AnjutaToken *)g_node_insert_after ((GNode *)sibling->parent, (GNode *)sibling, (GNode *)token);
return g_node_insert_after ((GNode *)sibling->parent, (GNode *)sibling, (GNode *)token);
}

AnjutaToken *
Expand Down Expand Up @@ -592,7 +592,7 @@ AnjutaToken *anjuta_token_get_next_arg (AnjutaToken *arg, gchar ** value)
/* Constructor & Destructor
*---------------------------------------------------------------------------*/

AnjutaToken *anjuta_token_new_string (AnjutaTokenType type, const char *value)
AnjutaToken *anjuta_token_new_string (AnjutaTokenType type, const gchar *value)
{
if (value == NULL)
{
Expand All @@ -611,7 +611,7 @@ AnjutaToken *anjuta_token_new_string (AnjutaTokenType type, const char *value)
return (AnjutaToken *)g_node_new (data);
}
}

AnjutaToken *
anjuta_token_new_fragment (gint type, const gchar *pos, gsize length)
{
Expand Down
6 changes: 4 additions & 2 deletions libanjuta/anjuta-token.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ typedef enum
ANJUTA_TOKEN_TYPE = 0xFFFF,

ANJUTA_TOKEN_FIRST = 16384,
ANJUTA_TOKEN_FILE = 16384,
ANJUTA_TOKEN_FILE,
ANJUTA_TOKEN_VARIABLE,
ANJUTA_TOKEN_EOV,
ANJUTA_TOKEN_PARSED,
ANJUTA_TOKEN_KEYWORD,
ANJUTA_TOKEN_OPERATOR,
ANJUTA_TOKEN_NAME,
ANJUTA_TOKEN_VALUE,
ANJUTA_TOKEN_MACRO,
ANJUTA_TOKEN_VARIABLE,
ANJUTA_TOKEN_DEFINITION,
ANJUTA_TOKEN_STATEMENT,
ANJUTA_TOKEN_NUMBER,
Expand Down
73 changes: 72 additions & 1 deletion libanjuta/interfaces/ianjuta-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,31 @@ ianjuta_project_configure_default (IAnjutaProject *obj, GError **err)
g_return_val_if_reached (NULL);
}

/**
* ianjuta_project_configure_node:
* @obj: Self
* @node: node to configure
* @err: Error propagation and reporting.
*
* Return a widget that can be use to set any options needed by this node
*
* Returns: A GtkWidget
*/
GtkWidget*
ianjuta_project_configure_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
{
g_return_val_if_fail (IANJUTA_IS_PROJECT(obj), NULL);
g_return_val_if_fail ((node == NULL) ||ANJUTA_IS_PROJECT_NODE(node), NULL);
return IANJUTA_PROJECT_GET_IFACE (obj)->configure_node (obj, node, err);
}

/* Default implementation */
static GtkWidget*
ianjuta_project_configure_node_default (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
{
g_return_val_if_reached (NULL);
}

/**
* ianjuta_project_get_capabilities:
* @obj: Self
Expand Down Expand Up @@ -317,6 +342,7 @@ ianjuta_project_base_init (IAnjutaProjectIface* klass)
klass->add_source = ianjuta_project_add_source_default;
klass->add_target = ianjuta_project_add_target_default;
klass->configure = ianjuta_project_configure_default;
klass->configure_node = ianjuta_project_configure_node_default;
klass->get_capabilities = ianjuta_project_get_capabilities_default;
klass->get_packages = ianjuta_project_get_packages_default;
klass->get_root = ianjuta_project_get_root_default;
Expand Down Expand Up @@ -376,7 +402,7 @@ ianjuta_project_capabilities_get_type (void)
{
static const GEnumValue values[] =
{
{ IANJUTA_PROJECT_HAS_NONE, "IANJUTA_PROJECT_HAS_NONE", "has-none" },
{ IANJUTA_PROJECT_CAN_ADD_NONE, "IANJUTA_PROJECT_CAN_ADD_NONE", "can-add-none" },
{ IANJUTA_PROJECT_CAN_ADD_GROUP, "IANJUTA_PROJECT_CAN_ADD_GROUP", "can-add-group" },
{ IANJUTA_PROJECT_CAN_ADD_TARGET, "IANJUTA_PROJECT_CAN_ADD_TARGET", "can-add-target" },
{ IANJUTA_PROJECT_CAN_ADD_SOURCE, "IANJUTA_PROJECT_CAN_ADD_SOURCE", "can-add-source" },
Expand All @@ -393,3 +419,48 @@ ianjuta_project_capabilities_get_type (void)

return type;
}

GType
ianjuta_project_error_get_type (void)
{
static const GEnumValue values[] =
{
{ IANJUTA_PROJECT_ERROR_SUCCESS, "IANJUTA_PROJECT_ERROR_SUCCESS", "error-success" },
{ IANJUTA_PROJECT_ERROR_DOESNT_EXIST, "IANJUTA_PROJECT_ERROR_DOESNT_EXIST", "error-doesnt-exist" },
{ IANJUTA_PROJECT_ERROR_ALREADY_EXISTS, "IANJUTA_PROJECT_ERROR_ALREADY_EXISTS", "error-already-exists" },
{ IANJUTA_PROJECT_ERROR_VALIDATION_FAILED, "IANJUTA_PROJECT_ERROR_VALIDATION_FAILED", "error-validation-failed" },
{ IANJUTA_PROJECT_ERROR_PROJECT_MALFORMED, "IANJUTA_PROJECT_ERROR_PROJECT_MALFORMED", "error-project-malformed" },
{ IANJUTA_PROJECT_ERROR_GENERAL_FAILURE, "IANJUTA_PROJECT_ERROR_GENERAL_FAILURE", "error-general-failure" },
{ 0, NULL, NULL }
};

static GType type = 0;

if (! type)
{
type = g_enum_register_static ("IAnjutaProjectError", values);
}

return type;
}

GType
ianjuta_project_probe_get_type (void)
{
static const GEnumValue values[] =
{
{ IANJUTA_PROJECT_PROBE_FILES, "IANJUTA_PROJECT_PROBE_FILES", "probe-files" },
{ IANJUTA_PROJECT_PROBE_MAKE_FILES, "IANJUTA_PROJECT_PROBE_MAKE_FILES", "probe-make-files" },
{ IANJUTA_PROJECT_PROBE_PROJECT_FILES, "IANJUTA_PROJECT_PROBE_PROJECT_FILES", "probe-project-files" },
{ 0, NULL, NULL }
};

static GType type = 0;

if (! type)
{
type = g_enum_register_static ("IAnjutaProjectProbe", values);
}

return type;
}
25 changes: 24 additions & 1 deletion libanjuta/interfaces/ianjuta-project.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,38 @@ G_BEGIN_DECLS
#define IANJUTA_PROJECT_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), IANJUTA_TYPE_PROJECT, IAnjutaProjectIface))

#define IANJUTA_TYPE_PROJECT_CAPABILITIES (ianjuta_project_capabilities_get_type())
#define IANJUTA_TYPE_PROJECT_ERROR (ianjuta_project_error_get_type())
#define IANJUTA_TYPE_PROJECT_PROBE (ianjuta_project_probe_get_type())

#define IANJUTA_PROJECT_ERROR ianjuta_project_error_quark()

typedef struct _IAnjutaProject IAnjutaProject;
typedef struct _IAnjutaProjectIface IAnjutaProjectIface;

typedef enum {
IANJUTA_PROJECT_HAS_NONE = 0,
IANJUTA_PROJECT_CAN_ADD_NONE = 0,
IANJUTA_PROJECT_CAN_ADD_GROUP = 1 << 0,
IANJUTA_PROJECT_CAN_ADD_TARGET = 1 << 1,
IANJUTA_PROJECT_CAN_ADD_SOURCE = 1 << 2,
IANJUTA_PROJECT_HAS_PACKAGES = 1 << 3
} IAnjutaProjectCapabilities;

/* Types */
typedef enum {
IANJUTA_PROJECT_ERROR_SUCCESS = 0,
IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
IANJUTA_PROJECT_ERROR_ALREADY_EXISTS,
IANJUTA_PROJECT_ERROR_VALIDATION_FAILED,
IANJUTA_PROJECT_ERROR_PROJECT_MALFORMED,
IANJUTA_PROJECT_ERROR_GENERAL_FAILURE
} IAnjutaProjectError;

typedef enum {
IANJUTA_PROJECT_PROBE_FILES = 10,
IANJUTA_PROJECT_PROBE_MAKE_FILES = 100,
IANJUTA_PROJECT_PROBE_PROJECT_FILES = 200
} IAnjutaProjectProbe;


struct _IAnjutaProjectIface {
GTypeInterface g_iface;
Expand All @@ -57,6 +75,7 @@ struct _IAnjutaProjectIface {
AnjutaProjectSource* (*add_source) (IAnjutaProject *obj, AnjutaProjectTarget *parent, GFile *file, GError **err);
AnjutaProjectTarget* (*add_target) (IAnjutaProject *obj, AnjutaProjectGroup *parent, const gchar *name, AnjutaProjectTargetType type, GError **err);
GtkWidget* (*configure) (IAnjutaProject *obj, GError **err);
GtkWidget* (*configure_node) (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err);
guint (*get_capabilities) (IAnjutaProject *obj, GError **err);
GList* (*get_packages) (IAnjutaProject *obj, GError **err);
AnjutaProjectGroup* (*get_root) (IAnjutaProject *obj, GError **err);
Expand All @@ -68,6 +87,8 @@ struct _IAnjutaProjectIface {
};

GType ianjuta_project_capabilities_get_type (void);
GType ianjuta_project_error_get_type (void);
GType ianjuta_project_probe_get_type (void);

GQuark ianjuta_project_error_quark (void);
GType ianjuta_project_get_type (void);
Expand All @@ -80,6 +101,8 @@ AnjutaProjectTarget* ianjuta_project_add_target (IAnjutaProject *obj, AnjutaProj

GtkWidget* ianjuta_project_configure (IAnjutaProject *obj, GError **err);

GtkWidget* ianjuta_project_configure_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err);

guint ianjuta_project_get_capabilities (IAnjutaProject *obj, GError **err);

GList* ianjuta_project_get_packages (IAnjutaProject *obj, GError **err);
Expand Down
2 changes: 2 additions & 0 deletions src/mk-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ head_token:
name_token:
VARIABLE {
anjuta_token_set_type ($$, MK_TOKEN_VARIABLE);
g_message ("variable is %s", anjuta_token_evaluate ($$));
//mkp_scanner_parse_variable (scanner, $$);
}
| NAME
| CHARACTER
Expand Down
3 changes: 3 additions & 0 deletions src/mk-project-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ struct _MkpRule {

gchar *mkp_project_token_evaluate (MkpProject *project, AnjutaToken *token);

AnjutaToken* mkp_project_get_variable_token (MkpProject *project, AnjutaToken *variable);


MkpTarget* mkp_target_new (const gchar *name, AnjutaProjectTargetType type);
void mkp_target_free (MkpTarget *node);
void mkp_target_add_token (MkpGroup *node, AnjutaToken *token);
Expand Down
28 changes: 27 additions & 1 deletion src/mk-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,9 @@ project_load_makefile (MkpProject *project, GFile *file, MkpGroup *parent, GErro
tfile = mkp_group_set_makefile (parent, file);
g_hash_table_insert (project->files, g_object_ref (file), g_object_ref (tfile));
// g_object_add_toggle_ref (G_OBJECT (project->make_file), remove_make_file, project);
arg = anjuta_token_file_load (tfile, NULL);
scanner = mkp_scanner_new (project);
ok = mkp_scanner_parse (scanner, tfile, &err);
ok = mkp_scanner_parse_token (scanner, arg, &err);
mkp_scanner_free (scanner);
if (!ok)
{
Expand Down Expand Up @@ -1195,6 +1196,7 @@ mkp_project_update_variable (MkpProject *project, AnjutaToken *variable)
break;
}
}
g_message ("new variable %s", name);
for (; arg != NULL; arg = anjuta_token_next_sibling (arg))
{
switch (anjuta_token_get_type (arg))
Expand Down Expand Up @@ -1242,6 +1244,30 @@ mkp_project_update_variable (MkpProject *project, AnjutaToken *variable)
if (name) g_free (name);
}

AnjutaToken*
mkp_project_get_variable_token (MkpProject *project, AnjutaToken *variable)
{
guint length;
const gchar *string;
gchar *name;
MkpVariable *var;

length = anjuta_token_get_length (variable);
string = anjuta_token_get_string (variable);
if (string[1] == '(')
{
name = g_strndup (string + 2, length - 3);
}
else
{
name = g_strndup (string + 1, 1);
}
var = g_hash_table_lookup (project->variables, name);
g_free (name);

return var != NULL ? var->value : NULL;
}

/* Public functions
*---------------------------------------------------------------------------*/

Expand Down
1 change: 1 addition & 0 deletions src/mk-scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void mkp_scanner_free (MkpScanner *scanner);
gboolean mkp_scanner_parse (MkpScanner *scanner, AnjutaTokenFile *file, GError **error);

void mkp_scanner_update_variable (MkpScanner *scanner, AnjutaToken *variable);
void mkp_scanner_parse_variable (MkpScanner *scanner, AnjutaToken *variable);
void mkp_scanner_add_rule (MkpScanner *scanner, AnjutaToken *rule);

const gchar* mkp_scanner_get_filename (MkpScanner *scanner);
Expand Down
Loading

0 comments on commit d9b502f

Please sign in to comment.