Skip to content

#line is not used #163

@keestux

Description

@keestux

CCSM is not taking #line into account. What do I mean by that? Suppose you have the following input file. The file is created by preprocessing some C sources.

# 0 "t1.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "t1.c"
# 1 "t2.h" 1
extern void baz(void);
# 2 "t1.c" 2

void foo(void)
{
    baz();
}
# 0 "t2.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "t2.c"
# 1 "t2.h" 1
extern void baz(void);
# 2 "t2.c" 2

void baz(void)
{
}

Then apply ccsm

Global
Comment density: 0
Size in lines: 27
File: t.c
        Comment density: 0
        Size in lines: 27
        Function: baz
                Function (body) size in lines: 2
        Function: foo
                Function (body) size in lines: 3

This is not correct. I would expect that #line is taken into account.

Here are a few files that I used for a test
t1.c

#include "t2.h"

void foo(void)
{
    baz();
}

t2.c

#include "t2.h"

void baz(void)
{
}

t2.h

extern void baz(void);

doit.sh

#!/bin/sh

/lib/cpp t1.c > t1.i
/lib/cpp t2.c > t2.i
cat t1.i t2.i > t.c

echo "============== preprocessed, combined ===================="
ccsm -output-metrics=HIS_COMF,FILE_LINE_CNT,FUNC_BODY_LINE_CNT t.c --

echo "============== t1.c     t2.c          ===================="
ccsm -output-metrics=HIS_COMF,FILE_LINE_CNT,FUNC_BODY_LINE_CNT t1.c t2.c --

Here is the output using the current ccsm

============== preprocessed, combined ====================
Global
Comment density: 0
Size in lines: 27
File: t.c
	Comment density: 0
	Size in lines: 27
	Function: baz
		Function (body) size in lines: 2
	Function: foo
		Function (body) size in lines: 3
============== t1.c     t2.c          ====================
Global
Comment density: 0
Size in lines: 12
File: t1.c
	Comment density: 0
	Size in lines: 6
	Function: foo
		Function (body) size in lines: 3
File: t2.c
	Comment density: N/A
	Size in lines: 5
	Function: baz
		Function (body) size in lines: 2
File: t2.h
	Comment density: N/A
	Size in lines: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions